perlfunc >
5.18.1
との差分
perlfunc 5.18.1 と 5.38.0 の差分
| 1 | 1 | |
| 2 | =encoding | |
| 2 | =encoding utf8 | |
| 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 | 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 | than one place. | |
| 248 | than one place. Any warnings, including those produced by | |
| 249 | keywords, are described in L<perldiag> and L<warnings>. | |
| 242 | 250 | |
| 243 | 251 | =end original |
| 244 | 252 | |
| 245 | 253 | 以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、 |
| 246 | 254 | 関数のように見えるものも含みます)を示します。 |
| 247 | 255 | 複数の場所に現れる関数もあります。 |
| 256 | キーワードによって生成されるものを含む全ての警告は | |
| 257 | L<perldiag> と L<warnings> に記述されています。 | |
| 248 | 258 | |
| 249 | 259 | =over 4 |
| 250 | 260 | |
| 251 | 261 | =item Functions for SCALARs or strings |
| 252 | 262 | X<scalar> X<string> X<character> |
| 253 | 263 | |
| 254 | 264 | (スカラや文字列のための関数) |
| 255 | 265 | |
| 256 | 266 | =for Pod::Functions =String |
| 257 | 267 | |
| 258 | C<chomp> | |
| 268 | L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>, | |
| 259 | C< | |
| 269 | L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>, | |
| 260 | ||
| 270 | L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>, | |
| 271 | L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>, | |
| 272 | L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>, | |
| 273 | L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>, | |
| 274 | L<C<pack>|/pack TEMPLATE,LIST>, | |
| 275 | L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>, | |
| 276 | L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>, | |
| 277 | L<C<rindex>|/rindex STR,SUBSTR,POSITION>, | |
| 278 | L<C<sprintf>|/sprintf FORMAT, LIST>, | |
| 279 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>, | |
| 280 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>, | |
| 281 | L<C<ucfirst>|/ucfirst EXPR>, | |
| 282 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> | |
| 261 | 283 | |
| 262 | 284 | =begin original |
| 263 | 285 | |
| 264 | C<fc> is available only if the | |
| 286 | L<C<fc>|/fc EXPR> is available only if the | |
| 265 | ||
| 287 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is | |
| 288 | prefixed with C<CORE::>. The | |
| 289 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically | |
| 266 | 290 | with a C<use v5.16> (or higher) declaration in the current scope. |
| 267 | 291 | |
| 268 | 292 | =end original |
| 269 | 293 | |
| 270 | C<fc> は C<"fc"> 機能 | |
| 294 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か | |
| 271 | C< | |
| 295 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 272 | ||
| 296 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
| 297 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 273 | 298 | |
| 274 | 299 | =item Regular expressions and pattern matching |
| 275 | 300 | X<regular expression> X<regex> X<regexp> |
| 276 | 301 | |
| 277 | 302 | (正規表現とパターンマッチング) |
| 278 | 303 | |
| 279 | 304 | =for Pod::Functions =Regexp |
| 280 | 305 | |
| 281 | C<m | |
| 306 | L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>, | |
| 307 | L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>, | |
| 308 | L<C<quotemeta>|/quotemeta EXPR>, | |
| 309 | L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>, | |
| 310 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
| 311 | L<C<study>|/study SCALAR> | |
| 282 | 312 | |
| 283 | 313 | =item Numeric functions |
| 284 | 314 | X<numeric> X<number> X<trigonometric> X<trigonometry> |
| 285 | 315 | |
| 286 | 316 | (数値関数) |
| 287 | 317 | |
| 288 | 318 | =for Pod::Functions =Math |
| 289 | 319 | |
| 290 | C<abs>, C<atan2> | |
| 320 | L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>, | |
| 291 | C< | |
| 321 | L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>, | |
| 322 | L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>, | |
| 323 | L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR> | |
| 292 | 324 | |
| 293 | 325 | =item Functions for real @ARRAYs |
| 294 | 326 | X<array> |
| 295 | 327 | |
| 296 | 328 | (実配列のための関数) |
| 297 | 329 | |
| 298 | 330 | =for Pod::Functions =ARRAY |
| 299 | 331 | |
| 300 | C<each>, C<keys>, C<pop> | |
| 332 | L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>, | |
| 333 | L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>, | |
| 334 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>, | |
| 335 | L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH> | |
| 301 | 336 | |
| 302 | 337 | =item Functions for list data |
| 303 | 338 | X<list> |
| 304 | 339 | |
| 305 | 340 | (リストデータのための関数) |
| 306 | 341 | |
| 307 | 342 | =for Pod::Functions =LIST |
| 308 | 343 | |
| 309 | C<grep>, C<join> | |
| 344 | L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>, | |
| 345 | L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>, | |
| 346 | L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>, | |
| 347 | L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 310 | 348 | |
| 311 | 349 | =item Functions for real %HASHes |
| 312 | 350 | X<hash> |
| 313 | 351 | |
| 314 | 352 | (実ハッシュのための関数) |
| 315 | 353 | |
| 316 | 354 | =for Pod::Functions =HASH |
| 317 | 355 | |
| 318 | C<delete>, C<each> | |
| 356 | L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>, | |
| 357 | L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>, | |
| 358 | L<C<values>|/values HASH> | |
| 319 | 359 | |
| 320 | 360 | =item Input and output functions |
| 321 | 361 | X<I/O> X<input> X<output> X<dbm> |
| 322 | 362 | |
| 323 | 363 | (入出力関数) |
| 324 | 364 | |
| 325 | 365 | =for Pod::Functions =I/O |
| 326 | 366 | |
| 327 | C<binmode> | |
| 367 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>, | |
| 328 | C< | |
| 368 | L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>, | |
| 329 | ||
| 369 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>, | |
| 330 | ||
| 370 | L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>, | |
| 331 | C< | |
| 371 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>, | |
| 372 | L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>, | |
| 373 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 374 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 375 | L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>, | |
| 376 | L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>, | |
| 377 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 378 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, | |
| 379 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, | |
| 380 | L<C<syscall>|/syscall NUMBER, LIST>, | |
| 381 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 382 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, | |
| 383 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 384 | L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, | |
| 385 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>, | |
| 386 | L<C<write>|/write FILEHANDLE> | |
| 332 | 387 | |
| 333 | 388 | =begin original |
| 334 | 389 | |
| 335 | C<say> is available only if the | |
| 390 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
| 336 | ||
| 391 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is | |
| 392 | prefixed with C<CORE::>. The | |
| 393 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically | |
| 337 | 394 | with a C<use v5.10> (or higher) declaration in the current scope. |
| 338 | 395 | |
| 339 | 396 | =end original |
| 340 | 397 | |
| 341 | C<say> | |
| 398 | L<C<say>|/say FILEHANDLE LIST> は | |
| 342 | C<"say"> 機能 | |
| 399 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
| 343 | ||
| 400 | 前置されたときにのみ利用可能です。 | |
| 401 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
| 402 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 344 | 403 | |
| 345 | 404 | =item Functions for fixed-length data or records |
| 346 | 405 | |
| 347 | 406 | (固定長データやレコードのための関数) |
| 348 | 407 | |
| 349 | 408 | =for Pod::Functions =Binary |
| 350 | 409 | |
| 351 | C<pack> | |
| 410 | L<C<pack>|/pack TEMPLATE,LIST>, | |
| 352 | C< | |
| 411 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 412 | L<C<syscall>|/syscall NUMBER, LIST>, | |
| 413 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 414 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>, | |
| 415 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 416 | L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS> | |
| 353 | 417 | |
| 354 | 418 | =item Functions for filehandles, files, or directories |
| 355 | 419 | X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink> |
| 356 | 420 | |
| 357 | 421 | (ファイルハンドル、ファイル、ディレクトリのための関数) |
| 358 | 422 | |
| 359 | 423 | =for Pod::Functions =File |
| 360 | 424 | |
| 361 | C<-I<X>>, C<chdir> | |
| 425 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>, | |
| 362 | C< | |
| 426 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, | |
| 363 | ||
| 427 | L<C<chroot>|/chroot FILENAME>, | |
| 364 | ||
| 428 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>, | |
| 429 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, | |
| 430 | L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>, | |
| 431 | L<C<mkdir>|/mkdir FILENAME,MODE>, L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
| 432 | L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>, | |
| 433 | L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>, | |
| 434 | L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>, | |
| 435 | L<C<symlink>|/symlink OLDFILE,NEWFILE>, | |
| 436 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
| 437 | L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>, | |
| 438 | L<C<utime>|/utime LIST> | |
| 365 | 439 | |
| 366 | 440 | =item Keywords related to the control flow of your Perl program |
| 367 | 441 | X<control flow> |
| 368 | 442 | |
| 369 | 443 | (プログラムの流れを制御することに関連するキーワード) |
| 370 | 444 | |
| 371 | 445 | =for Pod::Functions =Flow |
| 372 | 446 | |
| 373 | C<break>, C<caller> | |
| 447 | L<C<break>|/break>, L<C<caller>|/caller EXPR>, | |
| 374 | C< | |
| 448 | L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>, | |
| 375 | ||
| 449 | L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>, | |
| 376 | ||
| 450 | L<C<evalbytes>|/evalbytes EXPR>, L<C<exit>|/exit EXPR>, | |
| 451 | L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>, | |
| 452 | L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>, | |
| 453 | L<C<method>|/method NAME BLOCK>, | |
| 454 | L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>, | |
| 455 | L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>, | |
| 456 | L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>, | |
| 457 | L<C<wantarray>|/wantarray> | |
| 377 | 458 | |
| 378 | 459 | =begin original |
| 379 | 460 | |
| 380 | C<break> is available only if you enable the experimental | |
| 461 | L<C<break>|/break> is available only if you enable the experimental | |
| 381 | feature | |
| 462 | L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::> | |
| 382 | ||
| 463 | prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also | |
| 383 | ||
| 464 | enables the C<default>, C<given> and C<when> statements, which are | |
| 465 | documented in L<perlsyn/"Switch Statements">. | |
| 466 | The L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
| 384 | 467 | automatically with a C<use v5.10> (or higher) declaration in the current |
| 385 | scope. In Perl v5.14 and earlier, C<continue> | |
| 468 | scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK> | |
| 386 | feature | |
| 469 | required the L<C<"switch"> feature|feature/The 'switch' feature>, like | |
| 470 | the other keywords. | |
| 387 | 471 | |
| 388 | 472 | =end original |
| 389 | 473 | |
| 390 | C<break> | |
| 474 | L<C<break>|/break> は、実験的な | |
| 391 | ||
| 475 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を | |
| 392 | ||
| 476 | 使ったときにのみ利用可能です。 | |
| 477 | L<C<"switch"> 機能|feature/The 'switch' feature> は、 | |
| 478 | L<perlsyn/"Switch Statements"> で文書化されている | |
| 393 | 479 | C<default>, C<given>, C<when> 文も有効にします。 |
| 394 | C<"switch"> 機能は現在のスコープで | |
| 480 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
| 395 | 宣言 | |
| 481 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
| 396 | Perl v5.14 以前では、C<continue> は他のキーワードと同様に | |
| 482 | Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に | |
| 397 | 必要です。 | |
| 483 | L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。 | |
| 398 | 484 | |
| 399 | 485 | =begin original |
| 400 | 486 | |
| 401 | C<evalbytes> is only available with th | |
| 487 | L<C<evalbytes>|/evalbytes EXPR> is only available with the | |
| 402 | L< | |
| 488 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 403 | ||
| 489 | (see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__> | |
| 404 | ||
| 490 | is only available with the | |
| 405 | ||
| 491 | L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if | |
| 492 | prefixed with C<CORE::>. Both the | |
| 493 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 494 | and L<C<"current_sub">|feature/The 'current_sub' feature> features are | |
| 495 | enabled automatically with a C<use v5.16> (or higher) declaration in the | |
| 496 | current scope. | |
| 406 | 497 | |
| 407 | 498 | =end original |
| 408 | 499 | |
| 409 | C<evalbytes> | |
| 500 | L<C<evalbytes>|/evalbytes EXPR> は | |
| 410 | ||
| 501 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 411 | ||
| 502 | (L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。 | |
| 412 | ||
| 503 | L<C<__SUB__>|/__SUB__> は | |
| 413 | C<"e | |
| 504 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か | |
| 505 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 506 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と | |
| 507 | L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は | |
| 508 | 現在のスコープで | |
| 414 | 509 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 |
| 415 | 510 | |
| 416 | 511 | =item Keywords related to scoping |
| 417 | 512 | |
| 418 | 513 | (スコープに関するキーワード) |
| 419 | 514 | |
| 420 | 515 | =for Pod::Functions =Namespace |
| 421 | 516 | |
| 422 | C<caller> | |
| 517 | L<C<caller>|/caller EXPR>, | |
| 518 | L<C<class>|/class NAMESPACE>, | |
| 519 | L<C<field>|/field VARNAME>, | |
| 520 | L<C<import>|/import LIST>, | |
| 521 | L<C<local>|/local EXPR>, | |
| 522 | L<C<my>|/my VARLIST>, | |
| 523 | L<C<our>|/our VARLIST>, | |
| 524 | L<C<package>|/package NAMESPACE>, | |
| 525 | L<C<state>|/state VARLIST>, | |
| 526 | L<C<use>|/use Module VERSION LIST> | |
| 423 | 527 | |
| 424 | 528 | =begin original |
| 425 | 529 | |
| 426 | C<state> is available only if the | |
| 530 | L<C<state>|/state VARLIST> is available only if the | |
| 427 | ||
| 531 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
| 428 | with | |
| 532 | prefixed with C<CORE::>. The | |
| 533 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
| 534 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 535 | scope. | |
| 429 | 536 | |
| 430 | 537 | =end original |
| 431 | 538 | |
| 432 | C<state> | |
| 539 | L<C<state>|/state VARLIST> は | |
| 433 | ||
| 540 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
| 434 | ||
| 541 | 前置した場合にのみ利用可能です。 | |
| 435 | ||
| 542 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
| 543 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
| 436 | 544 | |
| 437 | 545 | =item Miscellaneous functions |
| 438 | 546 | |
| 439 | 547 | (さまざまな関数) |
| 440 | 548 | |
| 441 | 549 | =for Pod::Functions =Misc |
| 442 | 550 | |
| 443 | C<defined>, C<formline> | |
| 551 | L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>, | |
| 552 | L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>, | |
| 553 | L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>, | |
| 554 | L<C<undef>|/undef EXPR> | |
| 444 | 555 | |
| 445 | 556 | =item Functions for processes and process groups |
| 446 | 557 | X<process> X<pid> X<process id> |
| 447 | 558 | |
| 448 | 559 | (プロセスとプロセスグループのための関数) |
| 449 | 560 | |
| 450 | 561 | =for Pod::Functions =Process |
| 451 | 562 | |
| 452 | C<alarm>, C<exec>, C<fork> | |
| 563 | L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>, | |
| 453 | C<p | |
| 564 | L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>, | |
| 454 | C< | |
| 565 | L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>, | |
| 455 | C< | |
| 566 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, | |
| 567 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, | |
| 568 | L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
| 569 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
| 570 | L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>, | |
| 571 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS> | |
| 456 | 572 | |
| 457 | 573 | =item Keywords related to Perl modules |
| 458 | 574 | X<module> |
| 459 | 575 | |
| 460 | 576 | (Perl モジュールに関するキーワード) |
| 461 | 577 | |
| 462 | 578 | =for Pod::Functions =Modules |
| 463 | 579 | |
| 464 | C<do>, C<import> | |
| 580 | L<C<do>|/do EXPR>, L<C<import>|/import LIST>, | |
| 581 | L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>, | |
| 582 | L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST> | |
| 465 | 583 | |
| 466 | 584 | =item Keywords related to classes and object-orientation |
| 467 | 585 | X<object> X<class> X<package> |
| 468 | 586 | |
| 469 | 587 | (クラスとオブジェクト指向に関するキーワード) |
| 470 | 588 | |
| 471 | 589 | =for Pod::Functions =Objects |
| 472 | 590 | |
| 473 | C<bless> | |
| 591 | L<C<bless>|/bless REF,CLASSNAME>, | |
| 474 | C< | |
| 592 | L<C<class>|/class NAMESPACE>, | |
| 593 | L<C<dbmclose>|/dbmclose HASH>, | |
| 594 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, | |
| 595 | L<C<field>|/field VARNAME>, | |
| 596 | L<C<method>|/method NAME BLOCK>, | |
| 597 | L<C<package>|/package NAMESPACE>, | |
| 598 | L<C<ref>|/ref EXPR>, | |
| 599 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, | |
| 600 | L<C<tied>|/tied VARIABLE>, | |
| 601 | L<C<untie>|/untie VARIABLE>, | |
| 602 | L<C<use>|/use Module VERSION LIST> | |
| 475 | 603 | |
| 476 | 604 | =item Low-level socket functions |
| 477 | 605 | X<socket> X<sock> |
| 478 | 606 | |
| 479 | 607 | (低レベルソケット関数) |
| 480 | 608 | |
| 481 | 609 | =for Pod::Functions =Socket |
| 482 | 610 | |
| 483 | C<accept> | |
| 611 | L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>, | |
| 484 | ||
| 612 | L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>, | |
| 485 | C< | |
| 613 | L<C<getpeername>|/getpeername SOCKET>, | |
| 614 | L<C<getsockname>|/getsockname SOCKET>, | |
| 615 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
| 616 | L<C<listen>|/listen SOCKET,QUEUESIZE>, | |
| 617 | L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>, | |
| 618 | L<C<send>|/send SOCKET,MSG,FLAGS,TO>, | |
| 619 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
| 620 | L<C<shutdown>|/shutdown SOCKET,HOW>, | |
| 621 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
| 622 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> | |
| 486 | 623 | |
| 487 | 624 | =item System V interprocess communication functions |
| 488 | 625 | X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message> |
| 489 | 626 | |
| 490 | 627 | (System V プロセス間通信関数) |
| 491 | 628 | |
| 492 | 629 | =for Pod::Functions =SysV |
| 493 | 630 | |
| 494 | C<msgctl> | |
| 631 | L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>, | |
| 495 | ||
| 632 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
| 633 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, | |
| 634 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
| 635 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
| 636 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
| 637 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
| 638 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE> | |
| 496 | 639 | |
| 497 | 640 | =item Fetching user and group info |
| 498 | 641 | X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd> |
| 499 | 642 | |
| 500 | 643 | (ユーザーとグループの情報取得) |
| 501 | 644 | |
| 502 | 645 | =for Pod::Functions =User |
| 503 | 646 | |
| 504 | C<endgrent> | |
| 647 | L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>, | |
| 505 | C< | |
| 648 | L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>, | |
| 506 | C<get | |
| 649 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, | |
| 650 | L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>, | |
| 651 | L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>, | |
| 652 | L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>, | |
| 653 | L<C<setpwent>|/setpwent> | |
| 507 | 654 | |
| 508 | 655 | =item Fetching network info |
| 509 | 656 | X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service> |
| 510 | 657 | |
| 511 | 658 | (ネットワーク情報取得) |
| 512 | 659 | |
| 513 | 660 | =for Pod::Functions =Network |
| 514 | 661 | |
| 515 | C<endprotoent>, C<endservent> | |
| 662 | L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>, | |
| 516 | C<gethost | |
| 663 | L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>, | |
| 517 | C<get | |
| 664 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, | |
| 518 | C<get | |
| 665 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, | |
| 519 | C< | |
| 666 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, | |
| 667 | L<C<getprotobyname>|/getprotobyname NAME>, | |
| 668 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
| 669 | L<C<getprotoent>|/getprotoent>, | |
| 670 | L<C<getservbyname>|/getservbyname NAME,PROTO>, | |
| 671 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
| 672 | L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
| 673 | L<C<setnetent>|/setnetent STAYOPEN>, | |
| 674 | L<C<setprotoent>|/setprotoent STAYOPEN>, | |
| 675 | L<C<setservent>|/setservent STAYOPEN> | |
| 520 | 676 | |
| 521 | 677 | =item Time-related functions |
| 522 | 678 | X<time> X<date> |
| 523 | 679 | |
| 524 | 680 | (時刻に関する関数) |
| 525 | 681 | |
| 526 | 682 | =for Pod::Functions =Time |
| 527 | 683 | |
| 528 | C<gmtime>, C<localtime> | |
| 684 | L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>, | |
| 685 | L<C<time>|/time>, L<C<times>|/times> | |
| 529 | 686 | |
| 530 | 687 | =item Non-function keywords |
| 531 | 688 | |
| 532 | 689 | =for Pod::Functions =!Non-functions |
| 533 | 690 | |
| 534 | C< | |
| 691 | C<ADJUST>, | |
| 535 | C< | |
| 692 | C<and>, | |
| 536 | C< | |
| 693 | C<AUTOLOAD>, | |
| 537 | C< | |
| 694 | C<BEGIN>, | |
| 538 | C< | |
| 695 | C<catch>, | |
| 696 | C<CHECK>, | |
| 697 | C<cmp>, | |
| 698 | C<CORE>, | |
| 699 | C<__DATA__>, | |
| 700 | C<default>, | |
| 701 | C<defer>, | |
| 702 | C<DESTROY>, | |
| 703 | C<else>, | |
| 704 | C<elseif>, | |
| 705 | C<elsif>, | |
| 706 | C<END>, | |
| 707 | C<__END__>, | |
| 708 | C<eq>, | |
| 709 | C<finally>, | |
| 710 | C<for>, | |
| 711 | C<foreach>, | |
| 712 | C<ge>, | |
| 713 | C<given>, | |
| 714 | C<gt>, | |
| 715 | C<if>, | |
| 716 | C<INIT>, | |
| 717 | C<isa>, | |
| 718 | C<le>, | |
| 719 | C<lt>, | |
| 720 | C<ne>, | |
| 721 | C<not>, | |
| 722 | C<or>, | |
| 723 | C<try>, | |
| 724 | C<UNITCHECK>, | |
| 725 | C<unless>, | |
| 726 | C<until>, | |
| 727 | C<when>, | |
| 728 | C<while>, | |
| 729 | C<x>, | |
| 730 | C<xor> | |
| 539 | 731 | |
| 540 | 732 | =back |
| 541 | 733 | |
| 542 | 734 | =head2 Portability |
| 543 | 735 | X<portability> X<Unix> X<portable> |
| 544 | 736 | |
| 545 | 737 | (移植性) |
| 546 | 738 | |
| 547 | 739 | =begin original |
| 548 | 740 | |
| 549 | 741 | Perl was born in Unix and can therefore access all common Unix |
| 550 | 742 | system calls. In non-Unix environments, the functionality of some |
| 551 | 743 | Unix system calls may not be available or details of the available |
| 552 | 744 | functionality may differ slightly. The Perl functions affected |
| 553 | 745 | by this are: |
| 554 | 746 | |
| 555 | 747 | =end original |
| 556 | 748 | |
| 557 | 749 | Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに |
| 558 | 750 | アクセスします。 |
| 559 | 751 | 非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、 |
| 560 | 752 | 使える機能の詳細が多少異なったりします。 |
| 561 | 753 | これによる影響を受ける Perl 関数は以下のものです: |
| 562 | 754 | |
| 563 | C<-X>, C<binmode> | |
| 755 | L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 564 | C< | |
| 756 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, | |
| 565 | ||
| 757 | L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>, | |
| 566 | C< | |
| 758 | L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, | |
| 567 | C< | |
| 759 | L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>, | |
| 568 | C< | |
| 760 | L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>, | |
| 569 | C< | |
| 761 | L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>, | |
| 570 | C< | |
| 762 | L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>, | |
| 571 | ||
| 763 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, | |
| 572 | ||
| 764 | L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>, | |
| 573 | C< | |
| 765 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, | |
| 574 | C< | |
| 766 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, | |
| 575 | ||
| 767 | L<C<getlogin>|/getlogin>, | |
| 576 | C< | |
| 768 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, | |
| 577 | C< | |
| 769 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, | |
| 578 | C<ti | |
| 770 | L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>, | |
| 579 | C< | |
| 771 | L<C<getpriority>|/getpriority WHICH,WHO>, | |
| 772 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
| 773 | L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>, | |
| 774 | L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>, | |
| 775 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
| 776 | L<C<getservent>|/getservent>, | |
| 777 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
| 778 | L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, | |
| 779 | L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>, | |
| 780 | L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>, | |
| 781 | L<C<msgget>|/msgget KEY,FLAGS>, | |
| 782 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
| 783 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
| 784 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>, | |
| 785 | L<C<rename>|/rename OLDNAME,NEWNAME>, | |
| 786 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, | |
| 787 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
| 788 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
| 789 | L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
| 790 | L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
| 791 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
| 792 | L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>, | |
| 793 | L<C<setservent>|/setservent STAYOPEN>, | |
| 794 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
| 795 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
| 796 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
| 797 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>, | |
| 798 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
| 799 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, | |
| 800 | L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>, | |
| 801 | L<C<syscall>|/syscall NUMBER, LIST>, | |
| 802 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
| 803 | L<C<system>|/system LIST>, L<C<times>|/times>, | |
| 804 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>, | |
| 805 | L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>, | |
| 806 | L<C<waitpid>|/waitpid PID,FLAGS> | |
| 580 | 807 | |
| 581 | 808 | =begin original |
| 582 | 809 | |
| 583 | 810 | For more information about the portability of these functions, see |
| 584 | 811 | L<perlport> and other available platform-specific documentation. |
| 585 | 812 | |
| 586 | 813 | =end original |
| 587 | 814 | |
| 588 | 815 | これらの関数の移植性に関するさらなる情報については、 |
| 589 | 816 | L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。 |
| 590 | 817 | |
| 591 | 818 | =head2 Alphabetical Listing of Perl Functions |
| 592 | 819 | |
| 593 | =over | |
| 820 | =over | |
| 594 | 821 | |
| 595 | 822 | =item -X FILEHANDLE |
| 596 | 823 | X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p> |
| 597 | 824 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> |
| 598 | 825 | |
| 599 | 826 | =item -X EXPR |
| 600 | 827 | |
| 601 | 828 | =item -X DIRHANDLE |
| 602 | 829 | |
| 603 | 830 | =item -X |
| 604 | 831 | |
| 605 | 832 | =for Pod::Functions a file test (-r, -x, etc) |
| 606 | 833 | |
| 607 | 834 | =begin original |
| 608 | 835 | |
| 609 | 836 | A file test, where X is one of the letters listed below. This unary |
| 610 | operator takes one argument, either a filename, a filehandle, or a dirhandle, | |
| 837 | operator takes one argument, either a filename, a filehandle, or a dirhandle, | |
| 611 | 838 | and tests the associated file to see if something is true about it. If the |
| 612 | argument is omitted, tests C<$_>, except for C<-t>, which | |
| 839 | argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which | |
| 613 | Unless otherwise documented, it returns C<1> for true and | |
| 840 | tests STDIN. Unless otherwise documented, it returns C<1> for true and | |
| 614 | ||
| 841 | C<''> for false. If the file doesn't exist or can't be examined, it | |
| 615 | ||
| 842 | returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno). | |
| 616 | ||
| 843 | With the exception of the C<-l> test they all follow symbolic links | |
| 844 | because they use C<stat()> and not C<lstat()> (so dangling symlinks can't | |
| 845 | be examined and will therefore report failure). | |
| 617 | 846 | |
| 618 | 847 | =end original |
| 619 | 848 | |
| 620 | 849 | X は以下にあげる文字で、ファイルテストを行ないます。 |
| 621 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
| 850 | この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、 | |
| 622 | ||
| 851 | 「あること」について真であるか否かを判定した結果を返します。 | |
| 623 | ||
| 852 | 引数が省略されると、C<-t> では STDIN を調べますが、その他は | |
| 624 | ||
| 853 | L<C<$_>|perlvar/$_> を調べます。 | |
| 625 | 特に記述されていなければ、真として C<1> を返し、偽として | |
| 854 | 特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。 | |
| 626 | ||
| 855 | ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し、 | |
| 856 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 857 | C<-l> テストを例外として、これら全てはシンボリックリンクに従います; | |
| 858 | C<lstat()> ではなく C<stat()> を使っているからです | |
| 859 | (従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。 | |
| 860 | ||
| 861 | =begin original | |
| 862 | ||
| 863 | Despite the funny names, precedence is the same as any other named unary | |
| 864 | operator. The operator may be any of: | |
| 865 | ||
| 866 | =end original | |
| 867 | ||
| 627 | 868 | みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、 |
| 628 | 869 | 他の単項演算子と同じく、引数を括弧で括ることもできます。 |
| 629 | 870 | 演算子には以下のものがあります: |
| 630 | 871 | |
| 631 | 872 | =begin original |
| 632 | 873 | |
| 633 | 874 | -r File is readable by effective uid/gid. |
| 634 | 875 | -w File is writable by effective uid/gid. |
| 635 | 876 | -x File is executable by effective uid/gid. |
| 636 | 877 | -o File is owned by effective uid. |
| 637 | 878 | |
| 638 | 879 | =end original |
| 639 | 880 | |
| 640 | 881 | -r ファイルが実効 uid/gid で読み出し可。 |
| 641 | 882 | -w ファイルが実効 uid/gid で書き込み可。 |
| 642 | 883 | -x ファイルが実効 uid/gid で実行可。 |
| 643 | 884 | -o ファイルが実効 uid の所有物。 |
| 644 | 885 | |
| 645 | 886 | =begin original |
| 646 | 887 | |
| 647 | 888 | -R File is readable by real uid/gid. |
| 648 | 889 | -W File is writable by real uid/gid. |
| 649 | 890 | -X File is executable by real uid/gid. |
| 650 | 891 | -O File is owned by real uid. |
| 651 | 892 | |
| 652 | 893 | =end original |
| 653 | 894 | |
| 654 | 895 | -R ファイルが実 uid/gid で読み出し可。 |
| 655 | 896 | -W ファイルが実 uid/gid で書き込み可。 |
| 656 | 897 | -X ファイルが実 uid/gid で実行可。 |
| 657 | 898 | -O ファイルが実 uid の所有物。 |
| 658 | 899 | |
| 659 | 900 | =begin original |
| 660 | 901 | |
| 661 | 902 | -e File exists. |
| 662 | 903 | -z File has zero size (is empty). |
| 663 | 904 | -s File has nonzero size (returns size in bytes). |
| 664 | 905 | |
| 665 | 906 | =end original |
| 666 | 907 | |
| 667 | 908 | -e ファイルが存在する。 |
| 668 | 909 | -z ファイルの大きさがゼロ(空)。 |
| 669 | 910 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。 |
| 670 | 911 | |
| 671 | 912 | =begin original |
| 672 | 913 | |
| 673 | 914 | -f File is a plain file. |
| 674 | 915 | -d File is a directory. |
| 675 | -l File is a symbolic link | |
| 916 | -l File is a symbolic link (false if symlinks aren't | |
| 917 | supported by the file system). | |
| 676 | 918 | -p File is a named pipe (FIFO), or Filehandle is a pipe. |
| 677 | 919 | -S File is a socket. |
| 678 | 920 | -b File is a block special file. |
| 679 | 921 | -c File is a character special file. |
| 680 | 922 | -t Filehandle is opened to a tty. |
| 681 | 923 | |
| 682 | 924 | =end original |
| 683 | 925 | |
| 684 | 926 | -f ファイルは通常ファイル。 |
| 685 | 927 | -d ファイルはディレクトリ。 |
| 686 | -l ファイルはシンボリックリンク。 | |
| 928 | -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。 | |
| 687 | 929 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。 |
| 688 | 930 | -S ファイルはソケット。 |
| 689 | 931 | -b ファイルはブロック特殊ファイル。 |
| 690 | 932 | -c ファイルはキャラクタ特殊ファイル。 |
| 691 | 933 | -t ファイルハンドルは tty にオープンされている。 |
| 692 | 934 | |
| 693 | 935 | =begin original |
| 694 | 936 | |
| 695 | 937 | -u File has setuid bit set. |
| 696 | 938 | -g File has setgid bit set. |
| 697 | 939 | -k File has sticky bit set. |
| 698 | 940 | |
| 699 | 941 | =end original |
| 700 | 942 | |
| 701 | 943 | -u ファイルの setuid ビットがセットされている。 |
| 702 | 944 | -g ファイルの setgid ビットがセットされている。 |
| 703 | 945 | -k ファイルの sticky ビットがセットされている。 |
| 704 | 946 | |
| 705 | 947 | =begin original |
| 706 | 948 | |
| 707 | -T File is an ASCII text file (heuristic guess). | |
| 949 | -T File is an ASCII or UTF-8 text file (heuristic guess). | |
| 708 | 950 | -B File is a "binary" file (opposite of -T). |
| 709 | 951 | |
| 710 | 952 | =end original |
| 711 | 953 | |
| 712 | -T ファイルは ASCII テキストファイル (発見的に推測します)。 | |
| 954 | -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。 | |
| 713 | 955 | -B ファイルは「バイナリ」ファイル (-T の反対)。 |
| 714 | 956 | |
| 715 | 957 | =begin original |
| 716 | 958 | |
| 717 | 959 | -M Script start time minus file modification time, in days. |
| 718 | 960 | -A Same for access time. |
| 719 | 961 | -C Same for inode change time (Unix, may differ for other |
| 720 | 962 | platforms) |
| 721 | 963 | |
| 722 | 964 | =end original |
| 723 | 965 | |
| 724 | 966 | -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。 |
| 725 | 967 | -A 同様にアクセスがあってからの日数。 |
| 726 | 968 | -C 同様に(Unix では) inode が変更されてからの日数(それ以外の |
| 727 | 969 | プラットフォームでは違うかもしれません)。 |
| 728 | 970 | |
| 729 | 971 | =begin original |
| 730 | 972 | |
| 731 | 973 | Example: |
| 732 | 974 | |
| 733 | 975 | =end original |
| 734 | 976 | |
| 735 | 977 | 例: |
| 736 | 978 | |
| 737 | 979 | while (<>) { |
| 738 | 980 | chomp; |
| 739 | 981 | next unless -f $_; # ignore specials |
| 740 | 982 | #... |
| 741 | 983 | } |
| 742 | 984 | |
| 743 | 985 | =begin original |
| 744 | 986 | |
| 745 | 987 | Note that C<-s/a/b/> does not do a negated substitution. Saying |
| 746 | 988 | C<-exp($foo)> still works as expected, however: only single letters |
| 747 | 989 | following a minus are interpreted as file tests. |
| 748 | 990 | |
| 749 | 991 | =end original |
| 750 | 992 | |
| 751 | 993 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 |
| 752 | 994 | しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に |
| 753 | 995 | 英字が 1 字続くときにのみ、ファイルテストと解釈されます。 |
| 754 | 996 | |
| 755 | 997 | =begin original |
| 756 | 998 | |
| 757 | 999 | These operators are exempt from the "looks like a function rule" described |
| 758 | 1000 | above. That is, an opening parenthesis after the operator does not affect |
| 759 | 1001 | how much of the following code constitutes the argument. Put the opening |
| 760 | 1002 | parentheses before the operator to separate it from code that follows (this |
| 761 | 1003 | applies only to operators with higher precedence than unary operators, of |
| 762 | 1004 | course): |
| 763 | 1005 | |
| 764 | 1006 | =end original |
| 765 | 1007 | |
| 766 | 1008 | これらの演算子は上述の「関数のように見えるルール」から免除されます。 |
| 767 | 1009 | つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を |
| 768 | 1010 | 構成するかに影響を与えません。 |
| 769 | 1011 | 演算子を引き続くコードから分離するには、演算子の前に開きかっこを |
| 770 | 1012 | 置いてください (これはもちろん、単項演算子より高い優先順位を持つ |
| 771 | 1013 | 演算子にのみ適用されます): |
| 772 | 1014 | |
| 773 | 1015 | -s($file) + 1024 # probably wrong; same as -s($file + 1024) |
| 774 | 1016 | (-s $file) + 1024 # correct |
| 775 | 1017 | |
| 776 | 1018 | =begin original |
| 777 | 1019 | |
| 778 | 1020 | The interpretation of the file permission operators C<-r>, C<-R>, |
| 779 | 1021 | C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode |
| 780 | 1022 | of the file and the uids and gids of the user. There may be other |
| 781 | 1023 | reasons you can't actually read, write, or execute the file: for |
| 782 | 1024 | example network filesystem access controls, ACLs (access control lists), |
| 783 | 1025 | read-only filesystems, and unrecognized executable formats. Note |
| 784 | 1026 | that the use of these six specific operators to verify if some operation |
| 785 | 1027 | is possible is usually a mistake, because it may be open to race |
| 786 | 1028 | conditions. |
| 787 | 1029 | |
| 788 | 1030 | =end original |
| 789 | 1031 | |
| 790 | 1032 | ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, |
| 791 | 1033 | C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と |
| 792 | 1034 | 実効/実 gid のみから判断されます。 |
| 793 | 1035 | 実際にファイルが読めたり、書けたり、実行できたりするためには、 |
| 794 | 1036 | 別の条件が必要かもしれません: |
| 795 | 1037 | 例えば、ネットワークファイルシステムアクセスコントロール、 |
| 796 | 1038 | ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、 |
| 797 | 1039 | 認識できない実行ファイルフォーマット、などです。 |
| 798 | 1040 | これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは |
| 799 | 1041 | 通常は誤りであることに注意してください; なぜなら、これらは競合条件を |
| 800 | 1042 | 招きやすいからです。 |
| 801 | 1043 | |
| 802 | 1044 | =begin original |
| 803 | 1045 | |
| 804 | 1046 | Also note that, for the superuser on the local filesystems, the C<-r>, |
| 805 | 1047 | C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1 |
| 806 | 1048 | if any execute bit is set in the mode. Scripts run by the superuser |
| 807 | may thus need to do a stat | |
| 1049 | may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the | |
| 808 | or temporarily set their effective uid to | |
| 1050 | actual mode of the file, or temporarily set their effective uid to | |
| 1051 | something else. | |
| 809 | 1052 | |
| 810 | 1053 | =end original |
| 811 | 1054 | |
| 812 | 1055 | ローカルファイルシステムのスーパーユーザには、 |
| 813 | 1056 | C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の |
| 814 | 1057 | いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が |
| 815 | 1058 | 返ることにも注意してください。 |
| 816 | 1059 | スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、 |
| 817 | stat | |
| 1060 | L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする | |
| 818 | 1061 | 必要があるでしょう。 |
| 819 | 1062 | |
| 820 | 1063 | =begin original |
| 821 | 1064 | |
| 822 | If you are using ACLs, there is a pragma called C<filetest> | |
| 1065 | If you are using ACLs, there is a pragma called L<C<filetest>|filetest> | |
| 823 | produce more accurate results than the bare | |
| 1066 | that may produce more accurate results than the bare | |
| 824 | ||
| 1067 | L<C<stat>|/stat FILEHANDLE> mode bits. | |
| 825 | ||
| 1068 | When under C<use filetest 'access'>, the above-mentioned filetests | |
| 826 | ||
| 1069 | test whether the permission can(not) be granted using the L<access(2)> | |
| 1070 | family of system calls. Also note that the C<-x> and C<-X> tests may | |
| 827 | 1071 | under this pragma return true even if there are no execute permission |
| 828 | 1072 | bits set (nor any extra execute permission ACLs). This strangeness is |
| 829 | 1073 | due to the underlying system calls' definitions. Note also that, due to |
| 830 | 1074 | the implementation of C<use filetest 'access'>, the C<_> special |
| 831 | 1075 | filehandle won't cache the results of the file tests when this pragma is |
| 832 | in effect. Read the documentation for the C<filetest> | |
| 1076 | in effect. Read the documentation for the L<C<filetest>|filetest> | |
| 833 | information. | |
| 1077 | pragma for more information. | |
| 834 | 1078 | |
| 835 | 1079 | =end original |
| 836 | 1080 | |
| 837 | ACL を使っている場合は、生の stat | |
| 1081 | ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより | |
| 838 | 精度の高い結果を作成する C<filetest> プラグマがあります。 | |
| 1082 | 精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。 | |
| 839 | 1083 | C<use filetest 'access'> とした場合、上述したファイルテストは |
| 840 | システムコールの access(2) ファミリーを使って権限が与えられているか | |
| 1084 | システムコールの L<access(2)> ファミリーを使って権限が与えられているか | |
| 841 | 1085 | どうかをテストします。 |
| 842 | また、このプラグマが指定されている場合、C<-x> と C<-X> は | |
| 1086 | また、このプラグマが指定されている場合、C<-x> と C<-X> テストは | |
| 843 | 1087 | たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない |
| 844 | 1088 | 場合でも真を返すことに注意してください。 |
| 845 | 1089 | この挙動は使用するシステムコールの定義によるものです。 |
| 846 | 1090 | C<use filetest 'access'> の実装により、このプラグマが有効の場合は |
| 847 | 1091 | C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに |
| 848 | 1092 | 注意してください。 |
| 849 | さらなる情報については C<filetest> プラグマのドキュメントを | |
| 1093 | さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを | |
| 850 | 1094 | 参照してください。 |
| 851 | 1095 | |
| 852 | 1096 | =begin original |
| 853 | 1097 | |
| 854 | The C<-T> and C<-B> | |
| 1098 | The C<-T> and C<-B> tests work as follows. The first block or so of | |
| 855 | file is examined | |
| 1099 | the file is examined to see if it is valid UTF-8 that includes non-ASCII | |
| 856 | characters | |
| 1100 | characters. If so, it's a C<-T> file. Otherwise, that same portion of | |
| 857 | ||
| 1101 | the file is examined for odd characters such as strange control codes or | |
| 858 | c | |
| 1102 | characters with the high bit set. If more than a third of the | |
| 859 | ||
| 1103 | characters are strange, it's a C<-B> file; otherwise it's a C<-T> file. | |
| 1104 | Also, any file containing a zero byte in the examined portion is | |
| 1105 | considered a binary file. (If executed within the scope of a L<S<use | |
| 1106 | locale>|perllocale> which includes C<LC_CTYPE>, odd characters are | |
| 1107 | anything that isn't a printable nor space in the current locale.) If | |
| 1108 | C<-T> or C<-B> is used on a filehandle, the current IO buffer is | |
| 1109 | examined | |
| 860 | 1110 | rather than the first block. Both C<-T> and C<-B> return true on an empty |
| 861 | 1111 | file, or a file at EOF when testing a filehandle. Because you have to |
| 862 | 1112 | read a file to do the C<-T> test, on most occasions you want to use a C<-f> |
| 863 | 1113 | against the file first, as in C<next unless -f $file && -T $file>. |
| 864 | 1114 | |
| 865 | 1115 | =end original |
| 866 | 1116 | |
| 867 | 1117 | ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。 |
| 868 | ファイルの最初の数ブロックを調べて、 | |
| 1118 | ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを | |
| 1119 | 調べます。 | |
| 1120 | もしそうなら、それは C<-T> ファイルです。 | |
| 1121 | さもなければ、ファイルの同じ位置から、変わった制御コードや | |
| 869 | 1122 | 上位ビットがセットされているような、通常のテキストには現れない文字を探します。 |
| 870 | ||
| 1123 | 三分の一以上がおかしな文字なら、それは C<-B> ファイルでです; | |
| 871 | ||
| 1124 | さもなければ C<-T> ファイルです。 | |
| 872 | ||
| 1125 | また、調べた位置にヌル文字が含まれるファイルも、バイナリファイルと | |
| 873 | ||
| 1126 | みなされます。 | |
| 874 | ||
| 1127 | (C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、 | |
| 1128 | おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。) | |
| 875 | 1129 | C<-T> や C<-B> をファイルハンドルに対して用いると、 |
| 876 | 1130 | 最初のブロックを調べる代わりに、IO バッファを調べます。 |
| 877 | 1131 | 調べたファイルの中身が何もないときや、 |
| 878 | 1132 | ファイルハンドルを調べたときに EOF に達して |
| 879 | 1133 | いたときには、C<-T> も C<-B> も「真」を返します。 |
| 880 | 1134 | C<-T> テストをするためにはファイルを読み込まないといけないので、 |
| 881 | 1135 | たいていは C<next unless -f $file && -T $file> というような形で |
| 882 | 1136 | まず調べたいファイルに対して C<-f> を使いたいはずです。 |
| 883 | 1137 | |
| 884 | 1138 | =begin original |
| 885 | 1139 | |
| 886 | If any of the file tests (or either the C<stat> | |
| 1140 | If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or | |
| 887 | ||
| 1141 | L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle | |
| 888 | st | |
| 1142 | consisting of a solitary underline, then the stat structure of the | |
| 889 | ||
| 1143 | previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used, | |
| 890 | ||
| 1144 | saving a system call. (This doesn't work with C<-t>, and you need to | |
| 891 | ||
| 1145 | remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in | |
| 892 | ||
| 1146 | the stat structure for the symbolic link, not the real file.) (Also, if | |
| 1147 | the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call, | |
| 1148 | C<-T> and C<-B> will reset it with the results of C<stat _>). | |
| 893 | 1149 | Example: |
| 894 | 1150 | |
| 895 | 1151 | =end original |
| 896 | 1152 | |
| 897 | どのファイルテスト (あるいは、C<stat> | |
| 1153 | どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE> や | |
| 1154 | L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、 | |
| 898 | 1155 | 下線だけから成る特別なファイルハンドルを与えると、 |
| 899 | 前回のファイルテスト (や stat | |
| 1156 | 前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の | |
| 900 | システムコールを省きます。 | |
| 1157 | stat 構造体が使われ、システムコールを省きます。 | |
| 901 | (C<-t> には使えませんし、lstat | |
| 1158 | (C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は | |
| 902 | シンボリックリンクの情報を stat 構造体に残すことを | |
| 1159 | 実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを | |
| 903 | 1160 | 覚えておく必要があります。) |
| 904 | (また、stat バッファが C<lstat> 呼び出しで埋まった場合、 | |
| 1161 | (また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、 | |
| 905 | 1162 | C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。 |
| 906 | 1163 | 例: |
| 907 | 1164 | |
| 908 | 1165 | print "Can do.\n" if -r $a || -w _ || -x _; |
| 909 | 1166 | |
| 910 | 1167 | stat($filename); |
| 911 | 1168 | print "Readable\n" if -r _; |
| 912 | 1169 | print "Writable\n" if -w _; |
| 913 | 1170 | print "Executable\n" if -x _; |
| 914 | 1171 | print "Setuid\n" if -u _; |
| 915 | 1172 | print "Setgid\n" if -g _; |
| 916 | 1173 | print "Sticky\n" if -k _; |
| 917 | 1174 | print "Text\n" if -T _; |
| 918 | 1175 | print "Binary\n" if -B _; |
| 919 | 1176 | |
| 920 | 1177 | =begin original |
| 921 | 1178 | |
| 922 | 1179 | As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file |
| 923 | 1180 | test operators, in a way that C<-f -w -x $file> is equivalent to |
| 924 | C<-x $file && -w _ && -f _>. (This is only fancy | |
| 1181 | C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use | |
| 925 | 1182 | the return value of C<-f $file> as an argument to another filetest |
| 926 | 1183 | operator, no special magic will happen.) |
| 927 | 1184 | |
| 928 | 1185 | =end original |
| 929 | 1186 | |
| 930 | 1187 | Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を |
| 931 | 1188 | スタックさせることができるので、C<-f -w -x $file> は |
| 932 | 1189 | C<-x $file && -w _ && -f _> と等価です。 |
| 933 | 1190 | (これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト |
| 934 | 1191 | 演算子の引数として使う場合は、何の特別なことも起きません。) |
| 935 | 1192 | |
| 936 | 1193 | =begin original |
| 937 | 1194 | |
| 938 | 1195 | Portability issues: L<perlport/-X>. |
| 939 | 1196 | |
| 940 | 1197 | =end original |
| 941 | 1198 | |
| 942 | 1199 | 移植性の問題: L<perlport/-X>。 |
| 943 | 1200 | |
| 944 | 1201 | =begin original |
| 945 | 1202 | |
| 946 | 1203 | To avoid confusing would-be users of your code with mysterious |
| 947 | 1204 | syntax errors, put something like this at the top of your script: |
| 948 | 1205 | |
| 949 | 1206 | =end original |
| 950 | 1207 | |
| 951 | 1208 | あなたのコードのユーザーが不思議な文法エラーで混乱することを |
| 952 | 1209 | 避けるために、スクリプトの先頭に以下のようなことを書いてください: |
| 953 | 1210 | |
| 954 | use 5. | |
| 1211 | use v5.10; # so filetest ops can stack | |
| 955 | 1212 | |
| 956 | 1213 | =item abs VALUE |
| 957 | 1214 | X<abs> X<absolute> |
| 958 | 1215 | |
| 959 | 1216 | =item abs |
| 960 | 1217 | |
| 961 | 1218 | =for Pod::Functions absolute value function |
| 962 | 1219 | |
| 963 | 1220 | =begin original |
| 964 | 1221 | |
| 965 | 1222 | Returns the absolute value of its argument. |
| 966 | If VALUE is omitted, uses C<$_>. | |
| 1223 | If VALUE is omitted, uses L<C<$_>|perlvar/$_>. | |
| 967 | 1224 | |
| 968 | 1225 | =end original |
| 969 | 1226 | |
| 970 | 1227 | 引数の絶対値を返します。 |
| 971 | VALUE が省略された場合は、C<$_> を使います。 | |
| 1228 | VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。 | |
| 972 | 1229 | |
| 973 | 1230 | =item accept NEWSOCKET,GENERICSOCKET |
| 974 | 1231 | X<accept> |
| 975 | 1232 | |
| 976 | 1233 | =for Pod::Functions accept an incoming socket connect |
| 977 | 1234 | |
| 978 | 1235 | =begin original |
| 979 | 1236 | |
| 980 | Accepts an incoming socket connect, just as accept(2) | |
| 1237 | Accepts an incoming socket connect, just as L<accept(2)> | |
| 981 | 1238 | does. Returns the packed address if it succeeded, false otherwise. |
| 982 | 1239 | See the example in L<perlipc/"Sockets: Client/Server Communication">. |
| 983 | 1240 | |
| 984 | 1241 | =end original |
| 985 | 1242 | |
| 986 | accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。 | |
| 1243 | L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。 | |
| 987 | 1244 | 成功時にはパックされたアドレスを返し、失敗すれば偽を返します。 |
| 988 | 1245 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 989 | 1246 | |
| 990 | 1247 | =begin original |
| 991 | 1248 | |
| 992 | 1249 | On systems that support a close-on-exec flag on files, the flag will |
| 993 | 1250 | be set for the newly opened file descriptor, as determined by the |
| 994 | value of $^F. See L<perlvar/$^F>. | |
| 1251 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
| 995 | 1252 | |
| 996 | 1253 | =end original |
| 997 | 1254 | |
| 998 | 1255 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 999 | フラグは $^F の値で決定される、新しくオープンされた | |
| 1256 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
| 1000 | セットされます。 | |
| 1257 | ファイル記述子に対してセットされます。 | |
| 1001 | 1258 | L<perlvar/$^F> を参照してください。 |
| 1002 | 1259 | |
| 1003 | 1260 | =item alarm SECONDS |
| 1004 | 1261 | X<alarm> |
| 1005 | 1262 | X<SIGALRM> |
| 1006 | 1263 | X<timer> |
| 1007 | 1264 | |
| 1008 | 1265 | =item alarm |
| 1009 | 1266 | |
| 1010 | 1267 | =for Pod::Functions schedule a SIGALRM |
| 1011 | 1268 | |
| 1012 | 1269 | =begin original |
| 1013 | 1270 | |
| 1014 | 1271 | Arranges to have a SIGALRM delivered to this process after the |
| 1015 | 1272 | specified number of wallclock seconds has elapsed. If SECONDS is not |
| 1016 | specified, the value stored in C<$_> is used. (On some | |
| 1273 | specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some | |
| 1017 | unfortunately, the elapsed time may be up to one second less | |
| 1274 | machines, unfortunately, the elapsed time may be up to one second less | |
| 1018 | than you specified because of how seconds are counted, and | |
| 1275 | or more than you specified because of how seconds are counted, and | |
| 1019 | scheduling may delay the delivery of the signal even further.) | |
| 1276 | process scheduling may delay the delivery of the signal even further.) | |
| 1020 | 1277 | |
| 1021 | 1278 | =end original |
| 1022 | 1279 | |
| 1023 | 1280 | 指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が |
| 1024 | 1281 | 送られてくるようにします。 |
| 1025 | SECONDS が指定されていない場合は、C<$_> に格納されている値を | |
| 1282 | SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を | |
| 1283 | 使います。 | |
| 1026 | 1284 | (マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で |
| 1027 | 1285 | 1 秒ずれます。) |
| 1028 | 1286 | |
| 1029 | 1287 | =begin original |
| 1030 | 1288 | |
| 1031 | 1289 | Only one timer may be counting at once. Each call disables the |
| 1032 | 1290 | previous timer, and an argument of C<0> may be supplied to cancel the |
| 1033 | 1291 | previous timer without starting a new one. The returned value is the |
| 1034 | 1292 | amount of time remaining on the previous timer. |
| 1035 | 1293 | |
| 1036 | 1294 | =end original |
| 1037 | 1295 | |
| 1038 | 1296 | 一度には一つのタイマだけが設定可能です。 |
| 1039 | 1297 | 呼び出しを行なう度に、以前のタイマを無効にしますし、 |
| 1040 | 1298 | 新しくタイマを起動しないで以前のタイマをキャンセルするために |
| 1041 | 1299 | 引数に C<0> を指定して呼び出すことができます。 |
| 1042 | 1300 | 以前のタイマの残り時間が、返り値となります。 |
| 1043 | 1301 | |
| 1044 | 1302 | =begin original |
| 1045 | 1303 | |
| 1046 | For delays of finer granularity than one second, the Time::HiRes module | |
| 1304 | For delays of finer granularity than one second, the L<Time::HiRes> module | |
| 1047 | 1305 | (from CPAN, and starting from Perl 5.8 part of the standard |
| 1048 | distribution) provides | |
| 1306 | distribution) provides | |
| 1049 | ||
| 1307 | L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>. | |
| 1050 | m | |
| 1308 | You may also use Perl's four-argument version of | |
| 1051 | ||
| 1309 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three | |
| 1310 | arguments undefined, or you might be able to use the | |
| 1311 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
| 1312 | if your system supports it. See L<perlfaq8> for details. | |
| 1052 | 1313 | |
| 1053 | 1314 | =end original |
| 1054 | 1315 | |
| 1055 | 1 秒より精度の高いスリープを行なうには、 | |
| 1316 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 | |
| 1056 | ||
| 1317 | また Perl 5.8 からは標準配布されています) が | |
| 1057 | ||
| 1318 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 | |
| 1058 | Perl の 4 引数版 select | |
| 1319 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の | |
| 1059 | setitimer(2) をサポートしているシステムでは、 | |
| 1320 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 | |
| 1060 | C<syscall> インタフェースを使って | |
| 1321 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
| 1322 | アクセスすることもできます。 | |
| 1061 | 1323 | 詳しくは L<perlfaq8> を参照してください。 |
| 1062 | 1324 | |
| 1063 | 1325 | =begin original |
| 1064 | 1326 | |
| 1065 | It is usually a mistake to intermix C<alarm> | |
| 1327 | It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and | |
| 1066 | C<sleep> | |
| 1328 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be | |
| 1329 | internally implemented on your system with L<C<alarm>|/alarm SECONDS>. | |
| 1067 | 1330 | |
| 1068 | 1331 | =end original |
| 1069 | 1332 | |
| 1070 | C<alarm> と C<sleep> を混ぜて使うのは | |
| 1333 | L<C<alarm>|/alarm SECONDS> と L<C<sleep>|/sleep EXPR> を混ぜて使うのは | |
| 1071 | C<sleep> | |
| 1334 | 普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> は内部的に | |
| 1335 | L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも | |
| 1072 | 1336 | しれないからです。 |
| 1073 | 1337 | |
| 1074 | 1338 | =begin original |
| 1075 | 1339 | |
| 1076 | If you want to use C<alarm> to time out a system call | |
| 1340 | If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call | |
| 1077 | C<eval>/C<die> pair. You | |
| 1341 | you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You | |
| 1078 | ||
| 1342 | can't rely on the alarm causing the system call to fail with | |
| 1079 | ||
| 1343 | L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers | |
| 1080 | ||
| 1344 | to restart system calls on some systems. Using | |
| 1345 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the | |
| 1346 | caveats given in L<perlipc/"Signals">. | |
| 1081 | 1347 | |
| 1082 | 1348 | =end original |
| 1083 | 1349 | |
| 1084 | C<alarm> をシステムコールの時間切れのために使いたいなら、 | |
| 1350 | L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、 | |
| 1085 | C<eval>/C<die> のペアで使う必要があります。 | |
| 1351 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。 | |
| 1086 | システムコールが失敗したときに C<$!> に C<EINTR> が | |
| 1352 | システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が | |
| 1087 | 頼ってはいけません; なぜならシステムによっては Perl は | |
| 1353 | セットされることに頼ってはいけません; なぜならシステムによっては Perl は | |
| 1088 | 1354 | システムコールを再開するためにシグナルハンドラを設定するからです。 |
| 1089 | C<eval>/C<die> は常にうまく動きます; | |
| 1355 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます; | |
| 1090 | L<perlipc/"Signals"> を参照してください。 | |
| 1356 | 注意点については L<perlipc/"Signals"> を参照してください。 | |
| 1091 | 1357 | |
| 1092 | 1358 | eval { |
| 1093 | 1359 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required |
| 1094 | 1360 | alarm $timeout; |
| 1095 | $nread = sysread | |
| 1361 | my $nread = sysread $socket, $buffer, $size; | |
| 1096 | 1362 | alarm 0; |
| 1097 | 1363 | }; |
| 1098 | 1364 | if ($@) { |
| 1099 | 1365 | die unless $@ eq "alarm\n"; # propagate unexpected errors |
| 1100 | 1366 | # timed out |
| 1101 | 1367 | } |
| 1102 | 1368 | else { |
| 1103 | 1369 | # didn't |
| 1104 | 1370 | } |
| 1105 | 1371 | |
| 1106 | 1372 | =begin original |
| 1107 | 1373 | |
| 1108 | 1374 | For more information see L<perlipc>. |
| 1109 | 1375 | |
| 1110 | 1376 | =end original |
| 1111 | 1377 | |
| 1112 | 1378 | さらなる情報については L<perlipc> を参照してください。 |
| 1113 | 1379 | |
| 1114 | 1380 | =begin original |
| 1115 | 1381 | |
| 1116 | 1382 | Portability issues: L<perlport/alarm>. |
| 1117 | 1383 | |
| 1118 | 1384 | =end original |
| 1119 | 1385 | |
| 1120 | 1386 | 移植性の問題: L<perlport/alarm>。 |
| 1121 | 1387 | |
| 1122 | 1388 | =item atan2 Y,X |
| 1123 | 1389 | X<atan2> X<arctangent> X<tan> X<tangent> |
| 1124 | 1390 | |
| 1125 | 1391 | =for Pod::Functions arctangent of Y/X in the range -PI to PI |
| 1126 | 1392 | |
| 1127 | 1393 | =begin original |
| 1128 | 1394 | |
| 1129 | 1395 | Returns the arctangent of Y/X in the range -PI to PI. |
| 1130 | 1396 | |
| 1131 | 1397 | =end original |
| 1132 | 1398 | |
| 1133 | 1399 | -πからπの範囲で Y/X の逆正接を返します。 |
| 1134 | 1400 | |
| 1135 | 1401 | =begin original |
| 1136 | 1402 | |
| 1137 | For the tangent operation, you may use the | |
| 1403 | For the tangent operation, you may use the | |
| 1138 | function, or use the familiar | |
| 1404 | L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar | |
| 1405 | relation: | |
| 1139 | 1406 | |
| 1140 | 1407 | =end original |
| 1141 | 1408 | |
| 1142 | 正接を求めたいときは、C<Math::Trig::tan> を使うか、 | |
| 1409 | 正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、 | |
| 1143 | 1410 | 以下のよく知られた関係を使ってください。 |
| 1144 | 1411 | |
| 1145 | 1412 | sub tan { sin($_[0]) / cos($_[0]) } |
| 1146 | 1413 | |
| 1147 | 1414 | =begin original |
| 1148 | 1415 | |
| 1149 | 1416 | The return value for C<atan2(0,0)> is implementation-defined; consult |
| 1150 | your atan2(3) manpage for more information. | |
| 1417 | your L<atan2(3)> manpage for more information. | |
| 1151 | 1418 | |
| 1152 | 1419 | =end original |
| 1153 | 1420 | |
| 1154 | 1421 | C<atan2(0,0)> の返り値は実装依存です; さらなる情報については |
| 1155 | atan2(3) man ページを参照してください。 | |
| 1422 | L<atan2(3)> man ページを参照してください。 | |
| 1156 | 1423 | |
| 1157 | 1424 | =begin original |
| 1158 | 1425 | |
| 1159 | 1426 | Portability issues: L<perlport/atan2>. |
| 1160 | 1427 | |
| 1161 | 1428 | =end original |
| 1162 | 1429 | |
| 1163 | 1430 | 移植性の問題: L<perlport/atan2>。 |
| 1164 | 1431 | |
| 1165 | 1432 | =item bind SOCKET,NAME |
| 1166 | 1433 | X<bind> |
| 1167 | 1434 | |
| 1168 | 1435 | =for Pod::Functions binds an address to a socket |
| 1169 | 1436 | |
| 1170 | 1437 | =begin original |
| 1171 | 1438 | |
| 1172 | Binds a network address to a socket, just as bind(2) | |
| 1439 | Binds a network address to a socket, just as L<bind(2)> | |
| 1173 | 1440 | does. Returns true if it succeeded, false otherwise. NAME should be a |
| 1174 | 1441 | packed address of the appropriate type for the socket. See the examples in |
| 1175 | 1442 | L<perlipc/"Sockets: Client/Server Communication">. |
| 1176 | 1443 | |
| 1177 | 1444 | =end original |
| 1178 | 1445 | |
| 1179 | bind(2) システムコールと同様に、ネットワークアドレスをソケットに | |
| 1446 | L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに | |
| 1447 | 結び付けます。 | |
| 1180 | 1448 | 成功時には真を、さもなければ偽を返します。 |
| 1181 | 1449 | NAME は、ソケットに対する、適切な型のパックされた |
| 1182 | 1450 | アドレスでなければなりません。 |
| 1183 | 1451 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 1184 | 1452 | |
| 1185 | 1453 | =item binmode FILEHANDLE, LAYER |
| 1186 | 1454 | X<binmode> X<binary> X<text> X<DOS> X<Windows> |
| 1187 | 1455 | |
| 1188 | 1456 | =item binmode FILEHANDLE |
| 1189 | 1457 | |
| 1190 | 1458 | =for Pod::Functions prepare binary files for I/O |
| 1191 | 1459 | |
| 1192 | 1460 | =begin original |
| 1193 | 1461 | |
| 1194 | 1462 | Arranges for FILEHANDLE to be read or written in "binary" or "text" |
| 1195 | 1463 | mode on systems where the run-time libraries distinguish between |
| 1196 | 1464 | binary and text files. If FILEHANDLE is an expression, the value is |
| 1197 | 1465 | taken as the name of the filehandle. Returns true on success, |
| 1198 | otherwise it returns C<undef> and sets | |
| 1466 | otherwise it returns L<C<undef>|/undef EXPR> and sets | |
| 1467 | L<C<$!>|perlvar/$!> (errno). | |
| 1199 | 1468 | |
| 1200 | 1469 | =end original |
| 1201 | 1470 | |
| 1202 | 1471 | バイナリファイルとテキストファイルを区別する OS において、 |
| 1203 | 1472 | FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように |
| 1204 | 1473 | 指定します。 |
| 1205 | 1474 | FILEHANDLE が式である場合には、その式の値がファイルハンドルの |
| 1206 | 1475 | 名前として使われます。 |
| 1207 | 成功時には真を返し、失敗時には C<undef> | |
| 1476 | 成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を返して | |
| 1477 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 1208 | 1478 | |
| 1209 | 1479 | =begin original |
| 1210 | 1480 | |
| 1211 | On some systems (in general, DOS- and Windows-based systems) | |
| 1481 | On some systems (in general, DOS- and Windows-based systems) | |
| 1212 | is necessary when you're not | |
| 1482 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not | |
| 1213 | of portability it is a good idea | |
| 1483 | working with a text file. For the sake of portability it is a good idea | |
| 1214 | a | |
| 1484 | always to use it when appropriate, and never to use it when it isn't | |
| 1215 | set their I/O to be by default | |
| 1485 | appropriate. Also, people can set their I/O to be by default | |
| 1486 | UTF8-encoded Unicode, not bytes. | |
| 1216 | 1487 | |
| 1217 | 1488 | =end original |
| 1218 | 1489 | |
| 1219 | テキストファイルでないものを扱う場合に | |
| 1490 | テキストファイルでないものを扱う場合に | |
| 1491 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な | |
| 1220 | 1492 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 |
| 1221 | 1493 | 移植性のために、適切なときには常にこれを使い、適切でないときには |
| 1222 | 1494 | 決して使わないというのは良い考えです。 |
| 1223 | 1495 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた |
| 1224 | 1496 | Unicode にセットすることも出来ます。 |
| 1225 | 1497 | |
| 1226 | 1498 | =begin original |
| 1227 | 1499 | |
| 1228 | In other words: regardless of platform, use | |
| 1500 | In other words: regardless of platform, use | |
| 1229 | ||
| 1501 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images, | |
| 1502 | for example. | |
| 1230 | 1503 | |
| 1231 | 1504 | =end original |
| 1232 | 1505 | |
| 1233 | 1506 | 言い換えると: プラットフォームに関わらず、 |
| 1234 | 例えばイメージのようなバイナリファイルに対しては | |
| 1507 | 例えばイメージのようなバイナリファイルに対しては | |
| 1235 | 使ってください。 | |
| 1508 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。 | |
| 1236 | 1509 | |
| 1237 | 1510 | =begin original |
| 1238 | 1511 | |
| 1239 | 1512 | If LAYER is present it is a single string, but may contain multiple |
| 1240 | 1513 | directives. The directives alter the behaviour of the filehandle. |
| 1241 | 1514 | When LAYER is present, using binmode on a text file makes sense. |
| 1242 | 1515 | |
| 1243 | 1516 | =end original |
| 1244 | 1517 | |
| 1245 | 1518 | LAYER が存在すると、それは単一の文字列ですが、複数の指示子を |
| 1246 | 1519 | 含むことができます。 |
| 1247 | 1520 | 指示子はファイルハンドルの振る舞いを変更します。 |
| 1248 | 1521 | LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。 |
| 1249 | 1522 | |
| 1250 | 1523 | =begin original |
| 1251 | 1524 | |
| 1252 | 1525 | If LAYER is omitted or specified as C<:raw> the filehandle is made |
| 1253 | 1526 | suitable for passing binary data. This includes turning off possible CRLF |
| 1254 | 1527 | translation and marking it as bytes (as opposed to Unicode characters). |
| 1255 | 1528 | Note that, despite what may be implied in I<"Programming Perl"> (the |
| 1256 | 1529 | Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>. |
| 1257 | 1530 | Other layers that would affect the binary nature of the stream are |
| 1258 | I<also> disabled. See L<PerlIO>, | |
| 1531 | I<also> disabled. See L<PerlIO>, and the discussion about the PERLIO | |
| 1259 | ||
| 1532 | environment variable in L<perlrun|perlrun/PERLIO>. | |
| 1260 | 1533 | |
| 1261 | 1534 | =end original |
| 1262 | 1535 | |
| 1263 | 1536 | LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ |
| 1264 | 1537 | データの通過に適するように設定されます。 |
| 1265 | 1538 | これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく) |
| 1266 | 1539 | バイトであるとマークしたりすることを含みます。 |
| 1267 | 1540 | I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、 |
| 1268 | 1541 | C<:raw> は単なる C<:crlf> の I<逆ではありません>。 |
| 1269 | 1542 | ストリームのバイナリとしての性質に影響を与える |
| 1270 | 1543 | I<その他の層も無効にされます>。 |
| 1271 | L<PerlIO>, L<perlrun> | |
| 1544 | L<PerlIO>, および L<perlrun|perlrun/PERLIO> の PERLIO 環境変数に関する議論を | |
| 1545 | 参照してください。 | |
| 1272 | 1546 | |
| 1273 | 1547 | =begin original |
| 1274 | 1548 | |
| 1275 | 1549 | The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the |
| 1276 | form C<:...>, are called I/O I<layers>. The | |
| 1550 | form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to | |
| 1277 | establish default I/O layers. | |
| 1551 | establish default I/O layers. | |
| 1278 | 1552 | |
| 1279 | 1553 | =end original |
| 1280 | 1554 | |
| 1281 | 1555 | C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は |
| 1282 | 1556 | I/O I<層> が呼び出されます。 |
| 1283 | ||
| 1557 | L<open> プラグマはデフォルト I/O 層を指定するために使われます。 | |
| 1284 | L<open> を参照してください。 | |
| 1285 | 1558 | |
| 1286 | 1559 | =begin original |
| 1287 | 1560 | |
| 1288 | I<The LAYER parameter of the binmode | |
| 1561 | I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
| 1289 | in "Programming Perl, 3rd | |
| 1562 | function is described as "DISCIPLINE" in "Programming Perl, 3rd | |
| 1290 | ||
| 1563 | Edition". However, since the publishing of this book, by many known as | |
| 1291 | ||
| 1564 | "Camel III", the consensus of the naming of this functionality has moved | |
| 1292 | ||
| 1565 | from "discipline" to "layer". All documentation of this version of Perl | |
| 1293 | "disciplines". Now back to | |
| 1566 | therefore refers to "layers" rather than to "disciplines". Now back to | |
| 1567 | the regularly scheduled documentation...> | |
| 1294 | 1568 | |
| 1295 | 1569 | =end original |
| 1296 | 1570 | |
| 1297 | I<binmode | |
| 1571 | I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは | |
| 1572 | 「プログラミングPerl 第 3 版」では | |
| 1298 | 1573 | 「ディシプリン(DISCIPLINE)」と表現されていました。 |
| 1299 | しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は | |
| 1574 | しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は | |
| 1300 | 1575 | 「ディシプリン」から「層」に変更することで合意されました。 |
| 1301 | 1576 | 従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく |
| 1302 | 1577 | 「層」と記述されています。では通常の解説に戻ります…> |
| 1303 | 1578 | |
| 1304 | 1579 | =begin original |
| 1305 | 1580 | |
| 1306 | 1581 | To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>. |
| 1307 | 1582 | C<:utf8> just marks the data as UTF-8 without further checking, |
| 1308 | 1583 | while C<:encoding(UTF-8)> checks the data for actually being valid |
| 1309 | 1584 | UTF-8. More details can be found in L<PerlIO::encoding>. |
| 1310 | 1585 | |
| 1311 | 1586 | =end original |
| 1312 | 1587 | |
| 1313 | 1588 | FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か |
| 1314 | 1589 | C<:encoding(UTF-8)> を使ってください。 |
| 1315 | 1590 | C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、 |
| 1316 | 1591 | C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。 |
| 1317 | 1592 | さらなる詳細は L<PerlIO::encoding> にあります。 |
| 1318 | 1593 | |
| 1319 | 1594 | =begin original |
| 1320 | 1595 | |
| 1321 | In general, binmode | |
| 1596 | In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called | |
| 1322 | ||
| 1597 | after L<C<open>|/open FILEHANDLE,MODE,EXPR> but before any I/O is done on the | |
| 1323 | ||
| 1598 | filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally | |
| 1324 | han | |
| 1599 | flushes any pending buffered output data (and perhaps pending input | |
| 1325 | ||
| 1600 | data) on the handle. An exception to this is the C<:encoding> layer | |
| 1601 | that changes the default character encoding of the handle. | |
| 1326 | 1602 | The C<:encoding> layer sometimes needs to be called in |
| 1327 | mid-stream, and it doesn't flush the stream. | |
| 1603 | mid-stream, and it doesn't flush the stream. C<:encoding> | |
| 1328 | 1604 | also implicitly pushes on top of itself the C<:utf8> layer because |
| 1329 | 1605 | internally Perl operates on UTF8-encoded Unicode characters. |
| 1330 | 1606 | |
| 1331 | 1607 | =end original |
| 1332 | 1608 | |
| 1333 | 一般的に binmode | |
| 1609 | 一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は | |
| 1334 | ||
| 1610 | L<C<open>|/open FILEHANDLE,MODE,EXPR> を呼び出した後、このファイルハンドルに | |
| 1335 | ||
| 1611 | 対するI/O 操作をする前に呼び出すべきです。 | |
| 1336 | ||
| 1612 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの | |
| 1613 | ファイルハンドルに対してバッファリングされている全ての出力データ | |
| 1337 | 1614 | (およびおそらくは入力データ)をフラッシュします。 |
| 1338 | 1615 | 例外は、このハンドルに対するデフォルト文字エンコーディングを変更する |
| 1339 | C<:encoding> 層です | |
| 1616 | C<:encoding> 層です。 | |
| 1340 | 1617 | C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、 |
| 1341 | 1618 | それによってストリームはフラッシュされません。 |
| 1342 | 1619 | Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、 |
| 1343 | 1620 | C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。 |
| 1344 | 1621 | |
| 1345 | 1622 | =begin original |
| 1346 | 1623 | |
| 1347 | 1624 | The operating system, device drivers, C libraries, and Perl run-time |
| 1348 | 1625 | system all conspire to let the programmer treat a single |
| 1349 | 1626 | character (C<\n>) as the line terminator, irrespective of external |
| 1350 | 1627 | representation. On many operating systems, the native text file |
| 1351 | 1628 | representation matches the internal representation, but on some |
| 1352 | 1629 | platforms the external representation of C<\n> is made up of more than |
| 1353 | 1630 | one character. |
| 1354 | 1631 | |
| 1355 | 1632 | =end original |
| 1356 | 1633 | |
| 1357 | 1634 | オペレーティングシステム、デバイスドライバ、C ライブラリ、 |
| 1358 | 1635 | Perl ランタイムシステムは全て、プログラマが外部表現に関わらず |
| 1359 | 1636 | 1 文字 (C<\n>) を行終端として扱えるように協調作業します。 |
| 1360 | 1637 | 多くのオペレーティングシステムでは、ネイティブテキストファイル表現は |
| 1361 | 1638 | 内部表現と同じですが、C<\n> の外部表現が複数文字になる |
| 1362 | 1639 | プラットフォームもあります。 |
| 1363 | 1640 | |
| 1364 | 1641 | =begin original |
| 1365 | 1642 | |
| 1366 | 1643 | All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use |
| 1367 | 1644 | a single character to end each line in the external representation of text |
| 1368 | 1645 | (even though that single character is CARRIAGE RETURN on old, pre-Darwin |
| 1369 | 1646 | flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other |
| 1370 | 1647 | systems like OS/2, DOS, and the various flavors of MS-Windows, your program |
| 1371 | 1648 | sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the |
| 1372 | two characters C<\cM\cJ>. That means that if you don't use | |
| 1649 | two characters C<\cM\cJ>. That means that if you don't use | |
| 1373 | these systems, C<\cM\cJ> | |
| 1650 | L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ> | |
| 1374 | ||
| 1651 | sequences on disk will be converted to C<\n> on input, and any C<\n> in | |
| 1375 | ou | |
| 1652 | your program will be converted back to C<\cM\cJ> on output. This is | |
| 1376 | binary files. | |
| 1653 | what you want for text files, but it can be disastrous for binary files. | |
| 1377 | 1654 | |
| 1378 | 1655 | =end original |
| 1379 | 1656 | |
| 1380 | 1657 | 全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは |
| 1381 | 1658 | テキストの外部表現として各行の末尾に一つの文字を |
| 1382 | 1659 | 使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、 |
| 1383 | 1660 | Unix とほとんどのVMS のファイルでは改行です)。 |
| 1384 | 1661 | VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、 |
| 1385 | 1662 | プログラムからは C<\n> は単純に C<\cJ> に見えますが、 |
| 1386 | 1663 | テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。 |
| 1387 | つまり、もしこれらのシステムで binmode | |
| 1664 | つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER> を | |
| 1388 | ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 | |
| 1665 | 使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 | |
| 1389 | 1666 | プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。 |
| 1390 | 1667 | これはテキストファイルの場合は思い通りの結果でしょうが、 |
| 1391 | 1668 | バイナリファイルの場合は悲惨です。 |
| 1392 | 1669 | |
| 1393 | 1670 | =begin original |
| 1394 | 1671 | |
| 1395 | Another consequence of using binmode | |
| 1672 | Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
| 1396 | special end-of-file markers will be seen as | |
| 1673 | (on some systems) is that special end-of-file markers will be seen as | |
| 1397 | For systems from the Microsoft family this | |
| 1674 | part of the data stream. For systems from the Microsoft family this | |
| 1398 | data contain C<\cZ>, the I/O subsystem will | |
| 1675 | means that, if your binary data contain C<\cZ>, the I/O subsystem will | |
| 1399 | the file, unless you use | |
| 1676 | regard it as the end of the file, unless you use | |
| 1677 | L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 1400 | 1678 | |
| 1401 | 1679 | =end original |
| 1402 | 1680 | |
| 1403 | binmode | |
| 1681 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで) | |
| 1404 | 特別なファイル終端マーカーが | |
| 1682 | 使うことによるその他の作用としては、特別なファイル終端マーカーが | |
| 1405 | 見られることです。 | |
| 1683 | データストリームの一部として見られることです。 | |
| 1406 | Microsoft ファミリーのシステムでは、 | |
| 1684 | Microsoft ファミリーのシステムでは、 | |
| 1407 | ||
| 1685 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、 | |
| 1408 | ||
| 1686 | もしバイナリデータに C<\cZ> が含まれていたときに、 | |
| 1687 | I/O サブシステムがこれをファイル終端とみなすことを意味します。 | |
| 1409 | 1688 | |
| 1410 | 1689 | =begin original |
| 1411 | 1690 | |
| 1412 | binmode | |
| 1691 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for | |
| 1413 | ||
| 1692 | L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST> | |
| 1414 | ||
| 1693 | operations, but also when using | |
| 1415 | ||
| 1694 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1695 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 1696 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1697 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and | |
| 1698 | L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the | |
| 1699 | L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in | |
| 1700 | L<perlvar> for how to manually set your input and output | |
| 1416 | 1701 | line-termination sequences. |
| 1417 | 1702 | |
| 1418 | 1703 | =end original |
| 1419 | 1704 | |
| 1420 | binmode | |
| 1705 | L<C<binmode>|/binmode FILEHANDLE, LAYER> は L<C<readline>|/readline EXPR> と | |
| 1421 | r | |
| 1706 | L<C<print>|/print FILEHANDLE LIST> 操作にだけではなく、 | |
| 1707 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1708 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 1709 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1710 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1711 | L<C<tell>|/tell FILEHANDLE> を使うときにも重要です | |
| 1422 | 1712 | (詳細は L<perlport> を参照してください)。 |
| 1423 | 1713 | 入出力の行端末シーケンスを手動でセットする方法については |
| 1424 | L<perlvar> の C<$ | |
| 1714 | L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と | |
| 1715 | L<C<$\>|perlvar/$\> 変数を参照してください。 | |
| 1425 | 1716 | |
| 1426 | 1717 | =begin original |
| 1427 | 1718 | |
| 1428 | 1719 | Portability issues: L<perlport/binmode>. |
| 1429 | 1720 | |
| 1430 | 1721 | =end original |
| 1431 | 1722 | |
| 1432 | 1723 | 移植性の問題: L<perlport/binmode>。 |
| 1433 | 1724 | |
| 1434 | 1725 | =item bless REF,CLASSNAME |
| 1435 | 1726 | X<bless> |
| 1436 | 1727 | |
| 1437 | 1728 | =item bless REF |
| 1438 | 1729 | |
| 1439 | 1730 | =for Pod::Functions create an object |
| 1440 | 1731 | |
| 1441 | 1732 | =begin original |
| 1442 | 1733 | |
| 1443 | ||
| 1734 | C<bless> tells Perl to mark the item referred to by C<REF> as an | |
| 1444 | in | |
| 1735 | object in a package. The two-argument version of C<bless> is | |
| 1445 | ||
| 1736 | always preferable unless there is a specific reason to I<not> | |
| 1446 | ||
| 1737 | use it. | |
| 1447 | version if a derived class might inherit the function doing the blessing. | |
| 1448 | See L<perlobj> for more about the blessing (and blessings) of objects. | |
| 1449 | 1738 | |
| 1450 | 1739 | =end original |
| 1451 | 1740 | |
| 1452 | ||
| 1741 | C<bless> tells Perl to mark the item referred to by C<REF> as an | |
| 1453 | C | |
| 1742 | object in a package. The two-argument version of C<bless> is | |
| 1454 | ||
| 1743 | always preferable unless there is a specific reason to I<not> | |
| 1455 | ||
| 1744 | use it. | |
| 1456 | ||
| 1745 | (TBT) | |
| 1457 | 派生クラスが bless される関数を継承する場合は、 | |
| 1458 | 常に 2 引数版を使ってください。 | |
| 1459 | オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を | |
| 1460 | 参照してください。 | |
| 1461 | 1746 | |
| 1747 | =over | |
| 1748 | ||
| 1749 | =item * Bless the referred-to item into a specific package | |
| 1750 | (recommended form): | |
| 1751 | ||
| 1752 | bless $ref, $package; | |
| 1753 | ||
| 1462 | 1754 | =begin original |
| 1463 | 1755 | |
| 1464 | ||
| 1756 | The two-argument form adds the object to the package specified | |
| 1465 | ||
| 1757 | as the second argument. | |
| 1466 | Perl pragmata. Builtin types have all uppercase names. To prevent | |
| 1467 | confusion, you may wish to avoid such package names as well. Make sure | |
| 1468 | that CLASSNAME is a true value. | |
| 1469 | 1758 | |
| 1470 | 1759 | =end original |
| 1471 | 1760 | |
| 1472 | ||
| 1761 | The two-argument form adds the object to the package specified | |
| 1473 | ||
| 1762 | as the second argument. | |
| 1474 | ||
| 1763 | (TBT) | |
| 1475 | 組み込みの型は全て大文字の名前を持ちます。 | |
| 1476 | 混乱を避けるために、 | |
| 1477 | パッケージ名としてこのような名前は避けるべきです。 | |
| 1478 | CLASSNAME は真の値を持つようにしてください。 | |
| 1479 | 1764 | |
| 1765 | =item * Bless the referred-to item into package C<main>: | |
| 1766 | ||
| 1767 | bless $ref, ""; | |
| 1768 | ||
| 1480 | 1769 | =begin original |
| 1481 | 1770 | |
| 1482 | ||
| 1771 | If the second argument is an empty string, C<bless> adds the | |
| 1772 | object to package C<main>. | |
| 1483 | 1773 | |
| 1484 | 1774 | =end original |
| 1485 | 1775 | |
| 1486 | ||
| 1776 | If the second argument is an empty string, C<bless> adds the | |
| 1777 | object to package C<main>. | |
| 1778 | (TBT) | |
| 1487 | 1779 | |
| 1780 | =item * Bless the referred-to item into the current package (not | |
| 1781 | inheritable): | |
| 1782 | ||
| 1783 | bless $ref; | |
| 1784 | ||
| 1785 | =begin original | |
| 1786 | ||
| 1787 | If C<bless> is used without its second argument, the object is | |
| 1788 | created in the current package. The second argument should | |
| 1789 | always be supplied if a derived class might inherit a method | |
| 1790 | executing C<bless>. Because it is a potential source of bugs, | |
| 1791 | one-argument C<bless> is discouraged. | |
| 1792 | ||
| 1793 | =end original | |
| 1794 | ||
| 1795 | If C<bless> is used without its second argument, the object is | |
| 1796 | created in the current package. The second argument should | |
| 1797 | always be supplied if a derived class might inherit a method | |
| 1798 | executing C<bless>. Because it is a potential source of bugs, | |
| 1799 | one-argument C<bless> is discouraged. | |
| 1800 | (TBT) | |
| 1801 | ||
| 1802 | =back | |
| 1803 | ||
| 1804 | =begin original | |
| 1805 | ||
| 1806 | See L<perlobj> for more about the blessing (and blessings) of | |
| 1807 | objects. | |
| 1808 | ||
| 1809 | =end original | |
| 1810 | ||
| 1811 | See L<perlobj> for more about the blessing (and blessings) of | |
| 1812 | objects. | |
| 1813 | (TBT) | |
| 1814 | ||
| 1815 | =begin original | |
| 1816 | ||
| 1817 | L<C<bless>|/bless REF,CLASSNAME> returns its first argument, the | |
| 1818 | supplied reference, as the value of the function; since C<bless> | |
| 1819 | is commonly the last thing executed in constructors, this means | |
| 1820 | that the reference to the object is returned as the | |
| 1821 | constructor's value and allows the caller to immediately use | |
| 1822 | this returned object in method calls. | |
| 1823 | ||
| 1824 | =end original | |
| 1825 | ||
| 1826 | L<C<bless>|/bless REF,CLASSNAME> returns its first argument, the | |
| 1827 | supplied reference, as the value of the function; since C<bless> | |
| 1828 | is commonly the last thing executed in constructors, this means | |
| 1829 | that the reference to the object is returned as the | |
| 1830 | constructor's value and allows the caller to immediately use | |
| 1831 | this returned object in method calls. | |
| 1832 | (TBT) | |
| 1833 | ||
| 1834 | =begin original | |
| 1835 | ||
| 1836 | C<CLASSNAME> should always be a mixed-case name, as | |
| 1837 | all-uppercase and all-lowercase names are meant to be used only | |
| 1838 | for Perl builtin types and pragmas, respectively. Avoid creating | |
| 1839 | all-uppercase or all-lowercase package names to prevent | |
| 1840 | confusion. | |
| 1841 | ||
| 1842 | =end original | |
| 1843 | ||
| 1844 | C<CLASSNAME> should always be a mixed-case name, as | |
| 1845 | all-uppercase and all-lowercase names are meant to be used only | |
| 1846 | for Perl builtin types and pragmas, respectively. Avoid creating | |
| 1847 | all-uppercase or all-lowercase package names to prevent | |
| 1848 | confusion. | |
| 1849 | (TBT) | |
| 1850 | ||
| 1851 | =begin original | |
| 1852 | ||
| 1853 | Also avoid <Cbless>ing things into the class name C<0>; this | |
| 1854 | will cause code which (erroneously) checks the result of | |
| 1855 | L<C<ref>|/ref EXPR> to see if a reference is C<bless>ed to fail, | |
| 1856 | as "0", a falsy value, is returned. | |
| 1857 | ||
| 1858 | =end original | |
| 1859 | ||
| 1860 | Also avoid <Cbless>ing things into the class name C<0>; this | |
| 1861 | will cause code which (erroneously) checks the result of | |
| 1862 | L<C<ref>|/ref EXPR> to see if a reference is C<bless>ed to fail, | |
| 1863 | as "0", a falsy value, is returned. | |
| 1864 | (TBT) | |
| 1865 | ||
| 1866 | =begin original | |
| 1867 | ||
| 1868 | See L<perlmod/"Perl Modules"> for more details. | |
| 1869 | ||
| 1870 | =end original | |
| 1871 | ||
| 1872 | さらなる詳細については L<perlmod/"Perl Modules"> を参照してください。 | |
| 1873 | ||
| 1488 | 1874 | =item break |
| 1489 | 1875 | |
| 1490 | 1876 | =for Pod::Functions +switch break out of a C<given> block |
| 1491 | 1877 | |
| 1492 | 1878 | =begin original |
| 1493 | 1879 | |
| 1494 | Break out of a C<given | |
| 1880 | Break out of a C<given> block. | |
| 1495 | 1881 | |
| 1496 | 1882 | =end original |
| 1497 | 1883 | |
| 1498 | C<given | |
| 1884 | C<given> ブロックから脱出します。 | |
| 1499 | 1885 | |
| 1500 | 1886 | =begin original |
| 1501 | 1887 | |
| 1502 | ||
| 1888 | L<C<break>|/break> is available only if the | |
| 1503 | ||
| 1889 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it | |
| 1504 | with C<CORE::>. | |
| 1890 | is prefixed with C<CORE::>. The | |
| 1505 | cur | |
| 1891 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
| 1892 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 1893 | scope. | |
| 1506 | 1894 | |
| 1507 | 1895 | =end original |
| 1508 | 1896 | |
| 1509 | ||
| 1897 | L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が | |
| 1510 | ||
| 1898 | 有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。 | |
| 1511 | ||
| 1899 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
| 1512 | ||
| 1900 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
| 1513 | 1901 | |
| 1514 | 1902 | =item caller EXPR |
| 1515 | 1903 | X<caller> X<call stack> X<stack> X<stack trace> |
| 1516 | 1904 | |
| 1517 | 1905 | =item caller |
| 1518 | 1906 | |
| 1519 | 1907 | =for Pod::Functions get context of the current subroutine call |
| 1520 | 1908 | |
| 1521 | 1909 | =begin original |
| 1522 | 1910 | |
| 1523 | Returns the context of the current subroutine call. In scalar | |
| 1911 | Returns the context of the current pure perl subroutine call. In scalar | |
| 1524 | returns the caller's package name if there I<is> a caller (that is, if | |
| 1912 | context, returns the caller's package name if there I<is> a caller (that is, if | |
| 1525 | we're in a subroutine or C<eval> | |
| 1913 | we're in a subroutine or L<C<eval>|/eval EXPR> or | |
| 1526 | ||
| 1914 | L<C<require>|/require VERSION>) and the undefined value otherwise. | |
| 1915 | caller never returns XS subs and they are skipped. The next pure perl | |
| 1916 | sub will appear instead of the XS sub in caller's return values. In | |
| 1917 | list context, caller returns | |
| 1527 | 1918 | |
| 1528 | 1919 | =end original |
| 1529 | 1920 | |
| 1530 | その時点のサブルーチン呼び出しのコンテキストを返します。 | |
| 1921 | その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。 | |
| 1531 | 1922 | スカラコンテキストでは、呼び元が I<ある> 場合 |
| 1532 | (サブルーチン、C<eval>、C<require> の中に | |
| 1923 | (サブルーチン、L<C<eval>|/eval EXPR>、L<C<require>|/require VERSION> の中に | |
| 1533 | 呼び出し元のパッケージ名を返し、 | |
| 1924 | いるとき) には呼び出し元のパッケージ名を返し、 | |
| 1534 | ||
| 1925 | その他のときには未定義値を返します。 | |
| 1926 | caller は XS サブルーチンを返すことはなく、それらは飛ばされます。 | |
| 1927 | XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に | |
| 1928 | なります。 | |
| 1929 | リストコンテキストでは、caller は以下を返します: | |
| 1535 | 1930 | |
| 1536 | # 0 1 2 | |
| 1931 | # 0 1 2 | |
| 1537 | ($package, $filename, $line) = caller; | |
| 1932 | my ($package, $filename, $line) = caller; | |
| 1538 | 1933 | |
| 1539 | 1934 | =begin original |
| 1540 | 1935 | |
| 1936 | Like L<C<__FILE__>|/__FILE__> and L<C<__LINE__>|/__LINE__>, the filename and | |
| 1937 | line number returned here may be altered by the mechanism described at | |
| 1938 | L<perlsyn/"Plain Old Comments (Not!)">. | |
| 1939 | ||
| 1940 | =end original | |
| 1941 | ||
| 1942 | L<C<__FILE__>|/__FILE__> と L<C<__LINE__>|/__LINE__> 同様、 | |
| 1943 | ここで返されるファイル名と行番号は | |
| 1944 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構によって | |
| 1945 | 置き換えられます。 | |
| 1946 | ||
| 1947 | =begin original | |
| 1948 | ||
| 1541 | 1949 | With EXPR, it returns some extra information that the debugger uses to |
| 1542 | 1950 | print a stack trace. The value of EXPR indicates how many call frames |
| 1543 | 1951 | to go back before the current one. |
| 1544 | 1952 | |
| 1545 | 1953 | =end original |
| 1546 | 1954 | |
| 1547 | 1955 | EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。 |
| 1548 | 1956 | EXPR の値は、現状から数えて、 |
| 1549 | 1957 | いくつ前のコールフレームまで戻るかを示します。 |
| 1550 | 1958 | |
| 1551 | 1959 | # 0 1 2 3 4 |
| 1552 | | |
| 1960 | my ($package, $filename, $line, $subroutine, $hasargs, | |
| 1553 | 1961 | |
| 1554 | 1962 | # 5 6 7 8 9 10 |
| 1555 | 1963 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) |
| 1556 | | |
| 1964 | = caller($i); | |
| 1557 | 1965 | |
| 1558 | 1966 | =begin original |
| 1559 | 1967 | |
| 1560 | Here $subroutine | |
| 1968 | Here, $subroutine is the function that the caller called (rather than the | |
| 1561 | ||
| 1969 | function containing the caller). Note that $subroutine may be C<(eval)> if | |
| 1562 | ||
| 1970 | the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In | |
| 1563 | ||
| 1971 | such a case additional elements $evaltext and C<$is_require> are set: | |
| 1564 | C<e | |
| 1972 | C<$is_require> is true if the frame is created by a | |
| 1565 | ||
| 1973 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST> | |
| 1566 | ||
| 1974 | statement, $evaltext contains the text of the C<eval EXPR> statement. | |
| 1567 | fra | |
| 1975 | In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>, | |
| 1568 | ||
| 1976 | but $evaltext is undefined. (Note also that each | |
| 1569 | C< | |
| 1977 | L<C<use>|/use Module VERSION LIST> statement creates a | |
| 1978 | L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.) | |
| 1979 | $subroutine may also be C<(unknown)> if this particular subroutine | |
| 1980 | happens to have been deleted from the symbol table. C<$hasargs> is true | |
| 1981 | if a new instance of L<C<@_>|perlvar/@_> was set up for the frame. | |
| 1570 | 1982 | C<$hints> and C<$bitmask> contain pragmatic hints that the caller was |
| 1571 | compiled with. C<$hints> corresponds to C<$^H>, and | |
| 1983 | compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and | |
| 1572 | corresponds to | |
| 1984 | C<$bitmask> corresponds to | |
| 1573 | C<$ | |
| 1985 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and | |
| 1574 | to change between versions of Perl, and | |
| 1986 | C<$bitmask> values are subject to change between versions of Perl, and | |
| 1987 | are not meant for external use. | |
| 1575 | 1988 | |
| 1576 | 1989 | =end original |
| 1577 | 1990 | |
| 1578 | ||
| 1991 | ここで、$subroutine は、(caller を含む関数ではなく) caller が呼び出した | |
| 1579 | ||
| 1992 | 関数です。 | |
| 1993 | フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この | |
| 1994 | $subroutine は C<(eval)> になることに注意してください。 | |
| 1580 | 1995 | この場合、追加の要素である $evaltext と C<$is_require> がセットされます: |
| 1581 | C<$is_require> はフレームが C<require> | |
| 1996 | C<$is_require> はフレームが L<C<require>|/require VERSION> または | |
| 1582 | ||
| 1997 | L<C<use>|/use Module VERSION LIST> で作られた場合に真になり、 | |
| 1998 | $evaltext は C<eval EXPR> のテキストが入ります。 | |
| 1583 | 1999 | 特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、 |
| 1584 | 2000 | $evaltext は未定義値になります。 |
| 1585 | (それぞれの C<use> は C<eval EXPR> の中で | |
| 2001 | (それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で | |
| 1586 | 注意してください。) | |
| 2002 | L<C<require>|/require VERSION> フレームを作ることに注意してください。) | |
| 1587 | 2003 | $subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は |
| 1588 | 2004 | C<(unknown)> になります。 |
| 1589 | C<$hasargs> はこのフレーム用に C<@_> の新しい実体が | |
| 2005 | C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が | |
| 1590 | 真となります。 | |
| 2006 | 設定された場合に真となります。 | |
| 1591 | 2007 | C<$hints> と C<$bitmask> は caller がコンパイルされたときの |
| 1592 | 2008 | 実際的なヒントを含みます。 |
| 1593 | C<$hints> は C<$^H> に対応し、C<$bitmask> は | |
| 2009 | C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は | |
| 2010 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に | |
| 1594 | 2011 | 対応します。 |
| 1595 | 2012 | C<$hints> は C<$bitmask> は Perl のバージョンによって変更される |
| 1596 | 2013 | 可能性があるので、外部での使用を想定していません。 |
| 1597 | 2014 | |
| 1598 | 2015 | =begin original |
| 1599 | 2016 | |
| 1600 | C<$hinthash> is a reference to a hash containing the value of | |
| 2017 | C<$hinthash> is a reference to a hash containing the value of | |
| 1601 | caller was compiled, or | |
| 2018 | L<C<%^H>|perlvar/%^H> when the caller was compiled, or | |
| 1602 | ||
| 2019 | L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not | |
| 2020 | modify the values of this hash, as they are the actual values stored in | |
| 2021 | the optree. | |
| 1603 | 2022 | |
| 1604 | 2023 | =end original |
| 1605 | 2024 | |
| 1606 | C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を | |
| 2025 | C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を | |
| 1607 | ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は | |
| 2026 | 含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は | |
| 2027 | L<C<undef>|/undef EXPR> です。 | |
| 1608 | 2028 | このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。 |
| 1609 | 2029 | |
| 1610 | 2030 | =begin original |
| 1611 | 2031 | |
| 2032 | Note that the only types of call frames that are visible are subroutine | |
| 2033 | calls and C<eval>. Other forms of context, such as C<while> or C<foreach> | |
| 2034 | loops or C<try> blocks are not considered interesting to C<caller>, as they | |
| 2035 | do not alter the behaviour of the C<return> expression. | |
| 2036 | ||
| 2037 | =end original | |
| 2038 | ||
| 2039 | 見ることができる呼び出しフレームの種類はサブルーチン呼び出しと | |
| 2040 | C<eval> だけであることに注意してください。 | |
| 2041 | C<while> や C<foreach> のループや C<try> ブロックのようなその他の構造は、 | |
| 2042 | C<caller> の関心外です; これらは C<return> 式の振る舞いを変えないからです。 | |
| 2043 | ||
| 2044 | =begin original | |
| 2045 | ||
| 1612 | 2046 | Furthermore, when called from within the DB package in |
| 1613 | 2047 | list context, and with an argument, caller returns more |
| 1614 | 2048 | detailed information: it sets the list variable C<@DB::args> to be the |
| 1615 | 2049 | arguments with which the subroutine was invoked. |
| 1616 | 2050 | |
| 1617 | 2051 | =end original |
| 1618 | 2052 | |
| 1619 | 2053 | さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、 |
| 1620 | 2054 | caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を |
| 1621 | 2055 | 変数 C<@DB::args> に設定します。 |
| 1622 | 2056 | |
| 1623 | 2057 | =begin original |
| 1624 | 2058 | |
| 1625 | 2059 | Be aware that the optimizer might have optimized call frames away before |
| 1626 | C<caller> had a chance to get the information. That | |
| 2060 | L<C<caller>|/caller EXPR> had a chance to get the information. That | |
| 1627 | might not return information about the call | |
| 2061 | means that C<caller(N)> might not return information about the call | |
| 1628 | C<< N > 1 >>. In particular, C<@DB::args> | |
| 2062 | frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args> | |
| 1629 | previous time C<caller> | |
| 2063 | might have information from the previous time L<C<caller>|/caller EXPR> | |
| 2064 | was called. | |
| 1630 | 2065 | |
| 1631 | 2066 | =end original |
| 1632 | 2067 | |
| 1633 | C<caller> が情報を得る前にオプティマイザが呼び出しフレームを | |
| 2068 | L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを | |
| 1634 | しまうかもしれないことに注意してください。 | |
| 2069 | 最適化してしまうかもしれないことに注意してください。 | |
| 1635 | 2070 | これは、C<caller(N)> が C<< N > 1 >> のとき、 |
| 1636 | 2071 | あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。 |
| 1637 | 特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を | |
| 2072 | 特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を | |
| 1638 | 2073 | 持っているかもしれません。 |
| 1639 | 2074 | |
| 1640 | 2075 | =begin original |
| 1641 | 2076 | |
| 1642 | 2077 | Be aware that setting C<@DB::args> is I<best effort>, intended for |
| 1643 | 2078 | debugging or generating backtraces, and should not be relied upon. In |
| 1644 | particular, as C<@_> contains aliases to the caller' | |
| 2079 | particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's | |
| 1645 | not take a copy of C<@_> | |
| 2080 | arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so | |
| 1646 | ||
| 2081 | C<@DB::args> will contain modifications the subroutine makes to | |
| 1647 | ||
| 2082 | L<C<@_>|perlvar/@_> or its contents, not the original values at call | |
| 1648 | ||
| 2083 | time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit | |
| 1649 | re | |
| 2084 | references to its elements, so under certain cases its elements may have | |
| 1650 | o | |
| 2085 | become freed and reallocated for other variables or temporary values. | |
| 1651 | ||
| 2086 | Finally, a side effect of the current implementation is that the effects | |
| 1652 | ||
| 2087 | of C<shift @_> can I<normally> be undone (but not C<pop @_> or other | |
| 1653 | ||
| 2088 | splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been | |
| 1654 | ||
| 2089 | taken, I<and> subject to the caveat about reallocated elements), so | |
| 2090 | C<@DB::args> is actually a hybrid of the current state and initial state | |
| 2091 | of L<C<@_>|perlvar/@_>. Buyer beware. | |
| 1655 | 2092 | |
| 1656 | 2093 | =end original |
| 1657 | 2094 | |
| 1658 | 2095 | C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの |
| 1659 | 2096 | 生成を目的としていて、これに依存するべきではないということにも |
| 1660 | 2097 | 注意してください。 |
| 1661 | 特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、 | |
| 2098 | 特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、 | |
| 1662 | C<@_> のコピーを取らず、従って C<@DB::args> は | |
| 2099 | Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は | |
| 1663 | C<@_> やその内容に行った変更を含んでいて、 | |
| 2100 | サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、 | |
| 1664 | ||
| 2101 | 呼び出し時の元の値ではありません。 | |
| 1665 | ||
| 2102 | C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な | |
| 1666 | ||
| 2103 | リファレンスを保持しないので、ある種の状況では、解放されて他の変数や | |
| 2104 | 一時的な値のために再割り当てされているかもしれません。 | |
| 1667 | 2105 | 最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない |
| 1668 | 2106 | (しかし C<pop @_> やその他の splice は違い、I<そして> もし |
| 1669 | C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた | |
| 2107 | L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた | |
| 1670 | 問題になりやすいです)ことなので、C<@DB::args> は実際には現在の | |
| 2108 | 要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の | |
| 1671 | C<@_> の初期状態との合成物となります。 | |
| 2109 | 状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。 | |
| 1672 | 2110 | ご用心を。 |
| 1673 | 2111 | |
| 1674 | 2112 | =item chdir EXPR |
| 1675 | 2113 | X<chdir> |
| 1676 | 2114 | X<cd> |
| 1677 | 2115 | X<directory, change> |
| 1678 | 2116 | |
| 1679 | 2117 | =item chdir FILEHANDLE |
| 1680 | 2118 | |
| 1681 | 2119 | =item chdir DIRHANDLE |
| 1682 | 2120 | |
| 1683 | 2121 | =item chdir |
| 1684 | 2122 | |
| 1685 | 2123 | =for Pod::Functions change your current working directory |
| 1686 | 2124 | |
| 1687 | 2125 | =begin original |
| 1688 | 2126 | |
| 1689 | 2127 | Changes the working directory to EXPR, if possible. If EXPR is omitted, |
| 1690 | 2128 | changes to the directory specified by C<$ENV{HOME}>, if set; if not, |
| 1691 | 2129 | changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the |
| 1692 | variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If | |
| 2130 | variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If | |
| 1693 | neither is set, C<chdir> does nothing | |
| 2131 | neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It | |
| 1694 | false otherwise. See the example under | |
| 2132 | returns true on success, false otherwise. See the example under | |
| 2133 | L<C<die>|/die LIST>. | |
| 1695 | 2134 | |
| 1696 | 2135 | =end original |
| 1697 | 2136 | |
| 1698 | 2137 | (可能であれば、) カレントディレクトリを EXPR に移します。 |
| 1699 | 2138 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに |
| 1700 | 2139 | 移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに |
| 1701 | 2140 | 移ります。 |
| 1702 | (VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば | |
| 2141 | (VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば | |
| 1703 | 2142 | 使われます。) |
| 1704 | どちらも設定されていなければ、C<chdir> は何もしま | |
| 2143 | どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。 | |
| 1705 | 2144 | 成功時には真を返し、そうでなければ偽を返します。 |
| 1706 | C<die> の項の例を参照してください。 | |
| 2145 | L<C<die>|/die LIST> の項の例を参照してください。 | |
| 1707 | 2146 | |
| 1708 | 2147 | =begin original |
| 1709 | 2148 | |
| 1710 | On systems that support fchdir(2), you may pass a filehandle or | |
| 2149 | On systems that support L<fchdir(2)>, you may pass a filehandle or | |
| 1711 | directory handle as the argument. On systems that don't support fchdir(2), | |
| 2150 | directory handle as the argument. On systems that don't support L<fchdir(2)>, | |
| 1712 | 2151 | passing handles raises an exception. |
| 1713 | 2152 | |
| 1714 | 2153 | =end original |
| 1715 | 2154 | |
| 1716 | fchdir(2) に対応しているシステムでは、ファイルハンドルや | |
| 2155 | L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや | |
| 1717 | 2156 | ディレクトリハンドルを引数として渡せます。 |
| 1718 | fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。 | |
| 2157 | L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。 | |
| 1719 | 2158 | |
| 1720 | 2159 | =item chmod LIST |
| 1721 | 2160 | X<chmod> X<permission> X<mode> |
| 1722 | 2161 | |
| 1723 | 2162 | =for Pod::Functions changes the permissions on a list of files |
| 1724 | 2163 | |
| 1725 | 2164 | =begin original |
| 1726 | 2165 | |
| 1727 | 2166 | Changes the permissions of a list of files. The first element of the |
| 1728 | 2167 | list must be the numeric mode, which should probably be an octal |
| 1729 | 2168 | number, and which definitely should I<not> be a string of octal digits: |
| 1730 | 2169 | C<0644> is okay, but C<"0644"> is not. Returns the number of files |
| 1731 | successfully changed. See also L</oct> if all you have is a | |
| 2170 | successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a | |
| 2171 | string. | |
| 1732 | 2172 | |
| 1733 | 2173 | =end original |
| 1734 | 2174 | |
| 1735 | 2175 | LIST に含まれるファイルの、パーミッションを変更します。 |
| 1736 | 2176 | LIST の最初の要素は、数値表現のモードでなければなりません; |
| 1737 | 2177 | 恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の |
| 1738 | ||
| 2178 | 文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は | |
| 1739 | 2179 | だめ、ということです。 |
| 1740 | 2180 | 変更に成功したファイルの数を返します。 |
| 1741 | 文字列を使いたい場合は、L</oct> を参照してください。 | |
| 2181 | 文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。 | |
| 1742 | 2182 | |
| 1743 | $cnt = chmod 0755, "foo", "bar"; | |
| 2183 | my $cnt = chmod 0755, "foo", "bar"; | |
| 1744 | 2184 | chmod 0755, @executables; |
| 1745 | $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to | |
| 2185 | my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to | |
| 1746 | # --w----r-T | |
| 2186 | # --w----r-T | |
| 1747 | $mode = "0644"; chmod oct($mode), "foo"; # this is better | |
| 2187 | my $mode = "0644"; chmod oct($mode), "foo"; # this is better | |
| 1748 | $mode = 0644; chmod $mode, "foo"; # this is best | |
| 2188 | my $mode = 0644; chmod $mode, "foo"; # this is best | |
| 1749 | 2189 | |
| 1750 | 2190 | =begin original |
| 1751 | 2191 | |
| 1752 | On systems that support fchmod(2), you may pass filehandles among the | |
| 2192 | On systems that support L<fchmod(2)>, you may pass filehandles among the | |
| 1753 | files. On systems that don't support fchmod(2), passing filehandles raises | |
| 2193 | files. On systems that don't support L<fchmod(2)>, passing filehandles raises | |
| 1754 | 2194 | an exception. Filehandles must be passed as globs or glob references to be |
| 1755 | 2195 | recognized; barewords are considered filenames. |
| 1756 | 2196 | |
| 1757 | 2197 | =end original |
| 1758 | 2198 | |
| 1759 | fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として | |
| 2199 | L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として | |
| 1760 | ||
| 2200 | 渡せます。 | |
| 2201 | L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 1761 | 2202 | 例外が発生します。 |
| 1762 | 2203 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
| 1763 | 2204 | 渡されなければなりません; |
| 1764 | 2205 | 裸の単語はファイル名として扱われます。 |
| 1765 | 2206 | |
| 1766 | 2207 | open(my $fh, "<", "foo"); |
| 1767 | 2208 | my $perm = (stat $fh)[2] & 07777; |
| 1768 | 2209 | chmod($perm | 0600, $fh); |
| 1769 | 2210 | |
| 1770 | 2211 | =begin original |
| 1771 | 2212 | |
| 1772 | You can also import the symbolic C<S_I*> constants from the | |
| 2213 | You can also import the symbolic C<S_I*> constants from the | |
| 1773 | module: | |
| 2214 | L<C<Fcntl>|Fcntl> module: | |
| 1774 | 2215 | |
| 1775 | 2216 | =end original |
| 1776 | 2217 | |
| 1777 | C<Fcntl> モジュールから C<S_I*> シンボル定数を | |
| 2218 | L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を | |
| 2219 | インポートすることもできます: | |
| 1778 | 2220 | |
| 1779 | 2221 | use Fcntl qw( :mode ); |
| 1780 | 2222 | chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; |
| 1781 | 2223 | # Identical to the chmod 0755 of the example above. |
| 1782 | 2224 | |
| 1783 | 2225 | =begin original |
| 1784 | 2226 | |
| 1785 | 2227 | Portability issues: L<perlport/chmod>. |
| 1786 | 2228 | |
| 1787 | 2229 | =end original |
| 1788 | 2230 | |
| 1789 | 2231 | 移植性の問題: L<perlport/chmod>。 |
| 1790 | 2232 | |
| 1791 | 2233 | =item chomp VARIABLE |
| 1792 | 2234 | X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol> |
| 1793 | 2235 | |
| 1794 | 2236 | =item chomp( LIST ) |
| 1795 | 2237 | |
| 1796 | 2238 | =item chomp |
| 1797 | 2239 | |
| 1798 | 2240 | =for Pod::Functions remove a trailing record separator from a string |
| 1799 | 2241 | |
| 1800 | 2242 | =begin original |
| 1801 | 2243 | |
| 1802 | This safer version of L</chop> removes any trail | |
| 2244 | This safer version of L<C<chop>|/chop VARIABLE> removes any trailing | |
| 1803 | that corresponds to the current value of | |
| 2245 | string that corresponds to the current value of | |
| 1804 | $INPUT_RECORD_SEPARATOR | |
| 2246 | L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR> | |
| 2247 | in the L<C<English>|English> module). It returns the total | |
| 1805 | 2248 | number of characters removed from all its arguments. It's often used to |
| 1806 | 2249 | remove the newline from the end of an input record when you're worried |
| 1807 | 2250 | that the final record may be missing its newline. When in paragraph |
| 1808 | mode (C<$/ = | |
| 2251 | mode (C<$/ = ''>), it removes all trailing newlines from the string. | |
| 1809 | When in slurp mode (C<$/ = undef>) or fixed-length record mode | |
| 2252 | When in slurp mode (C<$/ = undef>) or fixed-length record mode | |
| 1810 | a reference to an integer or the like; | |
| 2253 | (L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like; | |
| 1811 | remove anything. | |
| 2254 | see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything. | |
| 1812 | If VARIABLE is omitted, it chomps C<$_>. Example: | |
| 2255 | If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example: | |
| 1813 | 2256 | |
| 1814 | 2257 | =end original |
| 1815 | 2258 | |
| 1816 | より安全な C<chop> (以下を参照してください) です; | |
| 2259 | より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です; | |
| 1817 | (C<English> モジュールでは、 | |
| 2260 | L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、 | |
| 2261 | C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の | |
| 1818 | 2262 | 値に対応する行末文字を削除します。 |
| 1819 | 2263 | 全ての引数から削除した文字数の合計を返します。 |
| 1820 | 2264 | 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が |
| 1821 | 2265 | 入っているのかわからないような場合に、使用できます。 |
| 1822 | 段落モード (C<$/ = | |
| 2266 | 段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。 | |
| 1823 | 2267 | 吸い込みモード (C<$/ = undef>) や 固定長レコードモード |
| 1824 | (C<$/> が整数へのリファレンスや類似のものの場合; | |
| 2268 | (L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合; | |
| 1825 | では、chomp | |
| 2269 | L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE> は | |
| 1826 | ||
| 2270 | 何も取り除きません。 | |
| 2271 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。 | |
| 1827 | 2272 | 例: |
| 1828 | 2273 | |
| 1829 | 2274 | while (<>) { |
| 1830 | 2275 | chomp; # avoid \n on last field |
| 1831 | @array = split(/:/); | |
| 2276 | my @array = split(/:/); | |
| 1832 | 2277 | # ... |
| 1833 | 2278 | } |
| 1834 | 2279 | |
| 1835 | 2280 | =begin original |
| 1836 | 2281 | |
| 1837 | If VARIABLE is a hash, it chomps the hash's values, but not its keys | |
| 2282 | If VARIABLE is a hash, it chomps the hash's values, but not its keys, | |
| 2283 | resetting the L<C<each>|/each HASH> iterator in the process. | |
| 1838 | 2284 | |
| 1839 | 2285 | =end original |
| 1840 | 2286 | |
| 1841 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し | |
| 2287 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、 | |
| 2288 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 | |
| 1842 | 2289 | |
| 1843 | 2290 | =begin original |
| 1844 | 2291 | |
| 1845 | 2292 | You can actually chomp anything that's an lvalue, including an assignment: |
| 1846 | 2293 | |
| 1847 | 2294 | =end original |
| 1848 | 2295 | |
| 1849 | 2296 | 左辺値であれば、代入を含めて、任意のものを chomp できます: |
| 1850 | 2297 | |
| 1851 | chomp($cwd = `pwd`); | |
| 2298 | chomp(my $cwd = `pwd`); | |
| 1852 | chomp($answer = <STDIN>); | |
| 2299 | chomp(my $answer = <STDIN>); | |
| 1853 | 2300 | |
| 1854 | 2301 | =begin original |
| 1855 | 2302 | |
| 1856 | 2303 | If you chomp a list, each element is chomped, and the total number of |
| 1857 | 2304 | characters removed is returned. |
| 1858 | 2305 | |
| 1859 | 2306 | =end original |
| 1860 | 2307 | |
| 1861 | 2308 | リストを chomp すると、個々の要素が chomp され、 |
| 1862 | 2309 | 削除された文字数の合計が返されます。 |
| 1863 | 2310 | |
| 1864 | 2311 | =begin original |
| 1865 | 2312 | |
| 1866 | 2313 | Note that parentheses are necessary when you're chomping anything |
| 1867 | 2314 | that is not a simple variable. This is because C<chomp $cwd = `pwd`;> |
| 1868 | 2315 | is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as |
| 1869 | 2316 | C<chomp( $cwd = `pwd` )> which you might expect. Similarly, |
| 1870 | 2317 | C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than |
| 1871 | 2318 | as C<chomp($a, $b)>. |
| 1872 | 2319 | |
| 1873 | 2320 | =end original |
| 1874 | 2321 | |
| 1875 | 2322 | 単純な変数以外のものを chomp する場合はかっこが必要であることに |
| 1876 | 2323 | 注意してください。 |
| 1877 | 2324 | これは、C<chomp $cwd = `pwd`;> は、予測している |
| 1878 | 2325 | C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と |
| 1879 | 2326 | 解釈されるからです。 |
| 1880 | 2327 | 同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b> |
| 1881 | 2328 | と解釈されます。 |
| 1882 | 2329 | |
| 1883 | 2330 | =item chop VARIABLE |
| 1884 | 2331 | X<chop> |
| 1885 | 2332 | |
| 1886 | 2333 | =item chop( LIST ) |
| 1887 | 2334 | |
| 1888 | 2335 | =item chop |
| 1889 | 2336 | |
| 1890 | 2337 | =for Pod::Functions remove the last character from a string |
| 1891 | 2338 | |
| 1892 | 2339 | =begin original |
| 1893 | 2340 | |
| 1894 | 2341 | Chops off the last character of a string and returns the character |
| 1895 | 2342 | chopped. It is much more efficient than C<s/.$//s> because it neither |
| 1896 | scans nor copies the string. If VARIABLE is omitted, chops | |
| 2343 | scans nor copies the string. If VARIABLE is omitted, chops | |
| 1897 | ||
| 2344 | L<C<$_>|perlvar/$_>. | |
| 2345 | If VARIABLE is a hash, it chops the hash's values, but not its keys, | |
| 2346 | resetting the L<C<each>|/each HASH> iterator in the process. | |
| 1898 | 2347 | |
| 1899 | 2348 | =end original |
| 1900 | 2349 | |
| 1901 | 2350 | 文字列の最後の文字を切り捨てて、その切り取った文字を返します。 |
| 1902 | 2351 | 文字列の検索もコピーも行ないませんので |
| 1903 | 2352 | C<s/.$//s> よりも、ずっと効率的です。 |
| 1904 | VARIABLE が省略されると、C<$_> を対象として chop します。 | |
| 2353 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。 | |
| 1905 | VARIABLE がハッシュの場合、ハッシュの | |
| 2354 | VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、 | |
| 1906 | ||
| 2355 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 | |
| 1907 | 2356 | |
| 1908 | 2357 | =begin original |
| 1909 | 2358 | |
| 1910 | 2359 | You can actually chop anything that's an lvalue, including an assignment. |
| 1911 | 2360 | |
| 1912 | 2361 | =end original |
| 1913 | 2362 | |
| 1914 | 2363 | 実際のところ、代入を含む左辺値となりうるなんでも chop できます。 |
| 1915 | 2364 | |
| 1916 | 2365 | =begin original |
| 1917 | 2366 | |
| 1918 | 2367 | If you chop a list, each element is chopped. Only the value of the |
| 1919 | last C<chop> is returned. | |
| 2368 | last L<C<chop>|/chop VARIABLE> is returned. | |
| 1920 | 2369 | |
| 1921 | 2370 | =end original |
| 1922 | 2371 | |
| 1923 | 2372 | リストを chop すると、個々の要素が chop されます。 |
| 1924 | 最後の C<chop> の値だけが返されます。 | |
| 2373 | 最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。 | |
| 1925 | 2374 | |
| 1926 | 2375 | =begin original |
| 1927 | 2376 | |
| 1928 | Note that C<chop> returns the last character. To | |
| 2377 | Note that L<C<chop>|/chop VARIABLE> returns the last character. To | |
| 1929 | character, use C<substr($string, 0, -1)>. | |
| 2378 | return all but the last character, use C<substr($string, 0, -1)>. | |
| 1930 | 2379 | |
| 1931 | 2380 | =end original |
| 1932 | 2381 | |
| 1933 | C<chop> は最後の文字を返すことに注意してください。 | |
| 2382 | L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。 | |
| 1934 | 2383 | 最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を |
| 1935 | 2384 | 使ってください。 |
| 1936 | 2385 | |
| 1937 | 2386 | =begin original |
| 1938 | 2387 | |
| 1939 | See also L</chomp>. | |
| 2388 | See also L<C<chomp>|/chomp VARIABLE>. | |
| 1940 | 2389 | |
| 1941 | 2390 | =end original |
| 1942 | 2391 | |
| 1943 | L</chomp> も参照してください。 | |
| 2392 | L<C<chomp>|/chomp VARIABLE> も参照してください。 | |
| 1944 | 2393 | |
| 1945 | 2394 | =item chown LIST |
| 1946 | 2395 | X<chown> X<owner> X<user> X<group> |
| 1947 | 2396 | |
| 1948 | 2397 | =for Pod::Functions change the ownership on a list of files |
| 1949 | 2398 | |
| 1950 | 2399 | =begin original |
| 1951 | 2400 | |
| 1952 | 2401 | Changes the owner (and group) of a list of files. The first two |
| 1953 | 2402 | elements of the list must be the I<numeric> uid and gid, in that |
| 1954 | 2403 | order. A value of -1 in either position is interpreted by most |
| 1955 | 2404 | systems to leave that value unchanged. Returns the number of files |
| 1956 | 2405 | successfully changed. |
| 1957 | 2406 | |
| 1958 | 2407 | =end original |
| 1959 | 2408 | |
| 1960 | 2409 | LIST に含まれるファイルの所有者 (とグループ) を変更します。 |
| 1961 | 2410 | LIST の最初の二つの要素には、I<数値表現> の uid と gid を |
| 1962 | 2411 | この順序で与えなければなりません。 |
| 1963 | 2412 | どちらかの値を -1 にすると、ほとんどのシステムではその値は |
| 1964 | 2413 | 変更しないと解釈します。 |
| 1965 | 2414 | 変更に成功したファイルの数を返します。 |
| 1966 | 2415 | |
| 1967 | $cnt = chown $uid, $gid, 'foo', 'bar'; | |
| 2416 | my $cnt = chown $uid, $gid, 'foo', 'bar'; | |
| 1968 | 2417 | chown $uid, $gid, @filenames; |
| 1969 | 2418 | |
| 1970 | 2419 | =begin original |
| 1971 | 2420 | |
| 1972 | On systems that support fchown(2), you may pass filehandles among the | |
| 2421 | On systems that support L<fchown(2)>, you may pass filehandles among the | |
| 1973 | files. On systems that don't support fchown(2), passing filehandles raises | |
| 2422 | files. On systems that don't support L<fchown(2)>, passing filehandles raises | |
| 1974 | 2423 | an exception. Filehandles must be passed as globs or glob references to be |
| 1975 | 2424 | recognized; barewords are considered filenames. |
| 1976 | 2425 | |
| 1977 | 2426 | =end original |
| 1978 | 2427 | |
| 1979 | fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。 | |
| 2428 | L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。 | |
| 1980 | fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと | |
| 2429 | L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 1981 | 2430 | 例外が発生します。 |
| 1982 | 2431 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
| 1983 | 2432 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
| 1984 | 2433 | |
| 1985 | 2434 | =begin original |
| 1986 | 2435 | |
| 1987 | 2436 | Here's an example that looks up nonnumeric uids in the passwd file: |
| 1988 | 2437 | |
| 1989 | 2438 | =end original |
| 1990 | 2439 | |
| 1991 | 2440 | passwd ファイルから数値表現でない uid を検索する例を |
| 1992 | 2441 | 示します: |
| 1993 | 2442 | |
| 1994 | 2443 | print "User: "; |
| 1995 | chomp($user = <STDIN>); | |
| 2444 | chomp(my $user = <STDIN>); | |
| 1996 | 2445 | print "Files: "; |
| 1997 | chomp($pattern = <STDIN>); | |
| 2446 | chomp(my $pattern = <STDIN>); | |
| 1998 | 2447 | |
| 1999 | ($login,$pass,$uid,$gid) = getpwnam($user) | |
| 2448 | my ($login,$pass,$uid,$gid) = getpwnam($user) | |
| 2000 | 2449 | or die "$user not in passwd file"; |
| 2001 | 2450 | |
| 2002 | @ary = glob($pattern); # expand filenames | |
| 2451 | my @ary = glob($pattern); # expand filenames | |
| 2003 | 2452 | chown $uid, $gid, @ary; |
| 2004 | 2453 | |
| 2005 | 2454 | =begin original |
| 2006 | 2455 | |
| 2007 | 2456 | On most systems, you are not allowed to change the ownership of the |
| 2008 | 2457 | file unless you're the superuser, although you should be able to change |
| 2009 | 2458 | the group to any of your secondary groups. On insecure systems, these |
| 2010 | 2459 | restrictions may be relaxed, but this is not a portable assumption. |
| 2011 | 2460 | On POSIX systems, you can detect this condition this way: |
| 2012 | 2461 | |
| 2013 | 2462 | =end original |
| 2014 | 2463 | |
| 2015 | 2464 | ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を |
| 2016 | 2465 | 変更できますが、グループは実行者の副グループに変更できるべきです。 |
| 2017 | 2466 | 安全でないシステムでは、この制限はゆるめられています; しかしこれは |
| 2018 | 2467 | 移植性のある仮定ではありません。 |
| 2019 | 2468 | POSIX システムでは、以下のようにしてこの条件を検出できます: |
| 2020 | 2469 | |
| 2021 | 2470 | use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); |
| 2022 | $can_chown_giveaway = | |
| 2471 | my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED); | |
| 2023 | 2472 | |
| 2024 | 2473 | =begin original |
| 2025 | 2474 | |
| 2026 | Portability issues: L<perlport/ch | |
| 2475 | Portability issues: L<perlport/chown>. | |
| 2027 | 2476 | |
| 2028 | 2477 | =end original |
| 2029 | 2478 | |
| 2030 | 移植性の問題: L<perlport/ch | |
| 2479 | 移植性の問題: L<perlport/chown>。 | |
| 2031 | 2480 | |
| 2032 | 2481 | =item chr NUMBER |
| 2033 | 2482 | X<chr> X<character> X<ASCII> X<Unicode> |
| 2034 | 2483 | |
| 2035 | 2484 | =item chr |
| 2036 | 2485 | |
| 2037 | 2486 | =for Pod::Functions get character this number represents |
| 2038 | 2487 | |
| 2039 | 2488 | =begin original |
| 2040 | 2489 | |
| 2041 | 2490 | Returns the character represented by that NUMBER in the character set. |
| 2042 | 2491 | For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and |
| 2043 | chr(0x263a) is a Unicode smiley face. | |
| 2492 | chr(0x263a) is a Unicode smiley face. | |
| 2044 | 2493 | |
| 2045 | 2494 | =end original |
| 2046 | 2495 | |
| 2047 | 2496 | 特定の文字セットでの NUMBER で表わされる文字を返します。 |
| 2048 | 2497 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります; |
| 2049 | chr(0x263a) は Unicode のスマイリーフェイスです。 | |
| 2498 | chr(0x263a) は Unicode のスマイリーフェイスです。 | |
| 2050 | 2499 | |
| 2051 | 2500 | =begin original |
| 2052 | 2501 | |
| 2053 | 2502 | Negative values give the Unicode replacement character (chr(0xfffd)), |
| 2054 | 2503 | except under the L<bytes> pragma, where the low eight bits of the value |
| 2055 | 2504 | (truncated to an integer) are used. |
| 2056 | 2505 | |
| 2057 | 2506 | =end original |
| 2058 | 2507 | |
| 2059 | 2508 | 負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、 |
| 2060 | 2509 | L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが |
| 2061 | 2510 | 使われます。 |
| 2062 | 2511 | |
| 2063 | 2512 | =begin original |
| 2064 | 2513 | |
| 2065 | If NUMBER is omitted, uses C<$_>. | |
| 2514 | If NUMBER is omitted, uses L<C<$_>|perlvar/$_>. | |
| 2066 | 2515 | |
| 2067 | 2516 | =end original |
| 2068 | 2517 | |
| 2069 | NUMBER が省略された場合、C<$_> を使います。 | |
| 2518 | NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。 | |
| 2070 | 2519 | |
| 2071 | 2520 | =begin original |
| 2072 | 2521 | |
| 2073 | For the reverse, use L</ord>. | |
| 2522 | For the reverse, use L<C<ord>|/ord EXPR>. | |
| 2074 | 2523 | |
| 2075 | 2524 | =end original |
| 2076 | 2525 | |
| 2077 | 逆を行うためには、L</ord> を参照してください。 | |
| 2526 | 逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。 | |
| 2078 | 2527 | |
| 2079 | 2528 | =begin original |
| 2080 | 2529 | |
| 2081 | 2530 | Note that characters from 128 to 255 (inclusive) are by default |
| 2082 | 2531 | internally not encoded as UTF-8 for backward compatibility reasons. |
| 2083 | 2532 | |
| 2084 | 2533 | =end original |
| 2085 | 2534 | |
| 2086 | 2535 | 128 から 255 までの文字は過去との互換性のために |
| 2087 | 2536 | デフォルトでは UTF-8 Unicode にエンコードされません。 |
| 2088 | 2537 | |
| 2089 | 2538 | =begin original |
| 2090 | 2539 | |
| 2091 | 2540 | See L<perlunicode> for more about Unicode. |
| 2092 | 2541 | |
| 2093 | 2542 | =end original |
| 2094 | 2543 | |
| 2095 | 2544 | Unicode については L<perlunicode> を参照してください。 |
| 2096 | 2545 | |
| 2097 | 2546 | =item chroot FILENAME |
| 2098 | 2547 | X<chroot> X<root> |
| 2099 | 2548 | |
| 2100 | 2549 | =item chroot |
| 2101 | 2550 | |
| 2102 | 2551 | =for Pod::Functions make directory new root for path lookups |
| 2103 | 2552 | |
| 2104 | 2553 | =begin original |
| 2105 | 2554 | |
| 2106 | 2555 | This function works like the system call by the same name: it makes the |
| 2107 | 2556 | named directory the new root directory for all further pathnames that |
| 2108 | 2557 | begin with a C</> by your process and all its children. (It doesn't |
| 2109 | 2558 | change your current working directory, which is unaffected.) For security |
| 2110 | 2559 | reasons, this call is restricted to the superuser. If FILENAME is |
| 2111 | omitted, does a C<chroot> to C<$_>. | |
| 2560 | omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>. | |
| 2112 | 2561 | |
| 2113 | 2562 | =end original |
| 2114 | 2563 | |
| 2115 | 2564 | 同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに |
| 2116 | 2565 | 対して、C</>で始まるパス名に関して指定されたディレクトリを新しい |
| 2117 | 2566 | ルートディレクトリとして扱います。 |
| 2118 | 2567 | (これはカレントディレクトリを変更しません; カレントディレクトリは |
| 2119 | 2568 | そのままです。) |
| 2120 | 2569 | セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。 |
| 2121 | FILENAME を省略すると、C<$_> | |
| 2570 | FILENAME を省略すると、L<C<$_>|perlvar/$_> へ | |
| 2571 | L<C<chroot>|/chroot FILENAME> します。 | |
| 2122 | 2572 | |
| 2123 | 2573 | =begin original |
| 2124 | 2574 | |
| 2575 | B<NOTE:> It is mandatory for security to C<chdir("/")> | |
| 2576 | (L<C<chdir>|/chdir EXPR> to the root directory) immediately after a | |
| 2577 | L<C<chroot>|/chroot FILENAME>, otherwise the current working directory | |
| 2578 | may be outside of the new root. | |
| 2579 | ||
| 2580 | =end original | |
| 2581 | ||
| 2582 | B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに | |
| 2583 | L<C<chdir>|/chdir EXPR> する) | |
| 2584 | C<chdir("/")> するのはセキュリティ上必須です; | |
| 2585 | さもなければ現在の作業ディレクトリは新しいルートの外側かもしれません。 | |
| 2586 | ||
| 2587 | =begin original | |
| 2588 | ||
| 2125 | 2589 | Portability issues: L<perlport/chroot>. |
| 2126 | 2590 | |
| 2127 | 2591 | =end original |
| 2128 | 2592 | |
| 2129 | 2593 | 移植性の問題: L<perlport/chroot>。 |
| 2130 | 2594 | |
| 2595 | =item class NAMESPACE | |
| 2596 | ||
| 2597 | =item class NAMESPACE VERSION | |
| 2598 | ||
| 2599 | =item class NAMESPACE BLOCK | |
| 2600 | ||
| 2601 | =item class NAMESPACE VERSION BLOCK | |
| 2602 | ||
| 2603 | =for Pod::Functions declare a separate global namespace that is an object class | |
| 2604 | ||
| 2605 | =begin original | |
| 2606 | ||
| 2607 | Declares the BLOCK or the rest of the compilation unit as being in the given | |
| 2608 | namespace, which implements an object class. This behaves similarly to | |
| 2609 | L<C<package>|/package NAMESPACE>, except that the newly-created package behaves | |
| 2610 | as a class. | |
| 2611 | ||
| 2612 | =end original | |
| 2613 | ||
| 2614 | Declares the BLOCK or the rest of the compilation unit as being in the given | |
| 2615 | namespace, which implements an object class. This behaves similarly to | |
| 2616 | L<C<package>|/package NAMESPACE>, except that the newly-created package behaves | |
| 2617 | as a class. | |
| 2618 | (TBT) | |
| 2619 | ||
| 2131 | 2620 | =item close FILEHANDLE |
| 2132 | 2621 | X<close> |
| 2133 | 2622 | |
| 2134 | 2623 | =item close |
| 2135 | 2624 | |
| 2136 | 2625 | =for Pod::Functions close file (or pipe or socket) handle |
| 2137 | 2626 | |
| 2138 | 2627 | =begin original |
| 2139 | 2628 | |
| 2140 | 2629 | Closes the file or pipe associated with the filehandle, flushes the IO |
| 2141 | 2630 | buffers, and closes the system file descriptor. Returns true if those |
| 2142 | 2631 | operations succeed and if no error was reported by any PerlIO |
| 2143 | 2632 | layer. Closes the currently selected filehandle if the argument is |
| 2144 | 2633 | omitted. |
| 2145 | 2634 | |
| 2146 | 2635 | =end original |
| 2147 | 2636 | |
| 2148 | 2637 | FILEHANDLE に対応したファイルまたはパイプをクローズして、 |
| 2149 | 2638 | IO バッファをフラッシュし、システムファイル記述子をクローズします。 |
| 2150 | 2639 | 操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。 |
| 2151 | 2640 | 引数が省略された場合、現在選択されているファイルハンドルをクローズします。 |
| 2152 | 2641 | |
| 2153 | 2642 | =begin original |
| 2154 | 2643 | |
| 2155 | 2644 | You don't have to close FILEHANDLE if you are immediately going to do |
| 2156 | another C<open> on it, becaus | |
| 2645 | another L<C<open>|/open FILEHANDLE,MODE,EXPR> on it, because | |
| 2157 | L<open|/open FILEHANDLE> | |
| 2646 | L<C<open>|/open FILEHANDLE,MODE,EXPR> closes it for you. (See | |
| 2158 | ||
| 2647 | L<C<open>|/open FILEHANDLE,MODE,EXPR>.) However, an explicit | |
| 2648 | L<C<close>|/close FILEHANDLE> on an input file resets the line counter | |
| 2649 | (L<C<$.>|perlvar/$.>), while the implicit close done by | |
| 2650 | L<C<open>|/open FILEHANDLE,MODE,EXPR> does not. | |
| 2159 | 2651 | |
| 2160 | 2652 | =end original |
| 2161 | 2653 | |
| 2162 | 2654 | クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう |
| 2163 | 場合には、C<open> が自動的に | |
| 2655 | 場合には、L<C<open>|/open FILEHANDLE,MODE,EXPR> が自動的に | |
| 2656 | L<C<close>|/close FILEHANDLE> を行ないますので、 | |
| 2164 | 2657 | close FILEHANDLE する必要はありません。 |
| 2165 | (L<open|/open FILEHANDLE> を参照してください。) | |
| 2658 | (L<C<open>|/open FILEHANDLE,MODE,EXPR> を参照してください。) | |
| 2166 | 2659 | ただし、明示的にクローズを行なったときにのみ入力ファイルの |
| 2167 | 行番号 (C<$.>) のリセットが行なわれ、 | |
| 2660 | 行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、 | |
| 2168 | ||
| 2661 | L<C<open>|/open FILEHANDLE,MODE,EXPR> によって行なわれる | |
| 2662 | 暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。 | |
| 2169 | 2663 | |
| 2170 | 2664 | =begin original |
| 2171 | 2665 | |
| 2172 | If the filehandle came from a piped open, C<close> | |
| 2666 | If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE> | |
| 2173 | the other syscalls involved fails or if its | |
| 2667 | returns false if one of the other syscalls involved fails or if its | |
| 2174 | status. If the only problem was that the | |
| 2668 | program exits with non-zero status. If the only problem was that the | |
| 2175 | ||
| 2669 | program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>. | |
| 2176 | on | |
| 2670 | Closing a pipe also waits for the process executing on the pipe to | |
| 2177 | ||
| 2671 | exit--in case you wish to look at the output of the pipe afterwards--and | |
| 2178 | ||
| 2672 | implicitly puts the exit status value of that command into | |
| 2673 | L<C<$?>|perlvar/$?> and | |
| 2674 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 2179 | 2675 | |
| 2180 | 2676 | =end original |
| 2181 | 2677 | |
| 2182 | ファイルハンドルがパイプつきオープンなら、C<close> は | |
| 2678 | ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は | |
| 2183 | システムコールが失敗したりプログラムが非ゼロのステータスで終了した | |
| 2679 | その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した | |
| 2184 | 偽を返します。 | |
| 2680 | 場合にも偽を返します。 | |
| 2185 | プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>に | |
| 2681 | プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> が C<0> に | |
| 2682 | セットされます。 | |
| 2186 | 2683 | 後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で |
| 2187 | 2684 | 実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を |
| 2188 | C<$?> | |
| 2685 | L<C<$?>|perlvar/$?> と | |
| 2686 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。 | |
| 2189 | 2687 | |
| 2190 | 2688 | =begin original |
| 2191 | 2689 | |
| 2192 | If there are multiple threads running, C<close> | |
| 2690 | If there are multiple threads running, L<C<close>|/close FILEHANDLE> on | |
| 2193 | piped open returns true without waiting for the | |
| 2691 | a filehandle from a piped open returns true without waiting for the | |
| 2194 | if the filehandle is still open in another | |
| 2692 | child process to terminate, if the filehandle is still open in another | |
| 2693 | thread. | |
| 2195 | 2694 | |
| 2196 | 2695 | =end original |
| 2197 | 2696 | |
| 2198 | 2697 | 複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する |
| 2199 | C<close> は、そのファイルハンドルが他のスレッドで | |
| 2698 | L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで | |
| 2200 | 子プロセスの終了を待たずに真を返します。 | |
| 2699 | まだ開かれている場合、子プロセスの終了を待たずに真を返します。 | |
| 2201 | 2700 | |
| 2202 | 2701 | =begin original |
| 2203 | 2702 | |
| 2204 | 2703 | Closing the read end of a pipe before the process writing to it at the |
| 2205 | 2704 | other end is done writing results in the writer receiving a SIGPIPE. If |
| 2206 | 2705 | the other end can't handle that, be sure to read all the data before |
| 2207 | 2706 | closing the pipe. |
| 2208 | 2707 | |
| 2209 | 2708 | =end original |
| 2210 | 2709 | |
| 2211 | 2710 | 書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 |
| 2212 | 2711 | 書き込み側に SIGPIPE が配送されます。 |
| 2213 | 2712 | 書き込み側がこれを扱えない場合、パイプを閉じる前に |
| 2214 | 2713 | 確実に全てのデータが読み込まれるようにする必要があります。 |
| 2215 | 2714 | |
| 2216 | 2715 | =begin original |
| 2217 | 2716 | |
| 2218 | 2717 | Example: |
| 2219 | 2718 | |
| 2220 | 2719 | =end original |
| 2221 | 2720 | |
| 2222 | 2721 | 例: |
| 2223 | 2722 | |
| 2224 | 2723 | open(OUTPUT, '|sort >foo') # pipe to sort |
| 2225 | 2724 | or die "Can't start sort: $!"; |
| 2226 | 2725 | #... # print stuff to output |
| 2227 | 2726 | close OUTPUT # wait for sort to finish |
| 2228 | 2727 | or warn $! ? "Error closing sort pipe: $!" |
| 2229 | 2728 | : "Exit status $? from sort"; |
| 2230 | 2729 | open(INPUT, 'foo') # get sort's results |
| 2231 | 2730 | or die "Can't open 'foo' for input: $!"; |
| 2232 | 2731 | |
| 2233 | 2732 | =begin original |
| 2234 | 2733 | |
| 2235 | 2734 | FILEHANDLE may be an expression whose value can be used as an indirect |
| 2236 | 2735 | filehandle, usually the real filehandle name or an autovivified handle. |
| 2237 | 2736 | |
| 2238 | 2737 | =end original |
| 2239 | 2738 | |
| 2240 | 2739 | FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと |
| 2241 | 2740 | して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。 |
| 2242 | 2741 | |
| 2243 | 2742 | =item closedir DIRHANDLE |
| 2244 | 2743 | X<closedir> |
| 2245 | 2744 | |
| 2246 | 2745 | =for Pod::Functions close directory handle |
| 2247 | 2746 | |
| 2248 | 2747 | =begin original |
| 2249 | 2748 | |
| 2250 | Closes a directory opened by C<opendir> | |
| 2749 | Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and | |
| 2251 | system call. | |
| 2750 | returns the success of that system call. | |
| 2252 | 2751 | |
| 2253 | 2752 | =end original |
| 2254 | 2753 | |
| 2255 | C<opendir> でオープンしたディレクトリをクローズし、 | |
| 2754 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、 | |
| 2256 | 2755 | システムコールの返り値を返します。 |
| 2257 | 2756 | |
| 2258 | 2757 | =item connect SOCKET,NAME |
| 2259 | 2758 | X<connect> |
| 2260 | 2759 | |
| 2261 | 2760 | =for Pod::Functions connect to a remote socket |
| 2262 | 2761 | |
| 2263 | 2762 | =begin original |
| 2264 | 2763 | |
| 2265 | Attempts to connect to a remote socket, just like connect(2). | |
| 2764 | Attempts to connect to a remote socket, just like L<connect(2)>. | |
| 2266 | 2765 | Returns true if it succeeded, false otherwise. NAME should be a |
| 2267 | 2766 | packed address of the appropriate type for the socket. See the examples in |
| 2268 | 2767 | L<perlipc/"Sockets: Client/Server Communication">. |
| 2269 | 2768 | |
| 2270 | 2769 | =end original |
| 2271 | 2770 | |
| 2272 | connect(2) システムコールと同様に、リモートソケットへの接続を試みます。 | |
| 2771 | L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。 | |
| 2273 | 2772 | 成功時には真を、さもなければ偽を返します。 |
| 2274 | 2773 | NAME は、ソケットに対する、適切な型のパックされた |
| 2275 | 2774 | アドレスでなければなりません。 |
| 2276 | 2775 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 2277 | 2776 | |
| 2278 | 2777 | =item continue BLOCK |
| 2279 | 2778 | X<continue> |
| 2280 | 2779 | |
| 2281 | 2780 | =item continue |
| 2282 | 2781 | |
| 2283 | 2782 | =for Pod::Functions optional trailing block in a while or foreach |
| 2284 | 2783 | |
| 2285 | 2784 | =begin original |
| 2286 | 2785 | |
| 2287 | When followed by a BLOCK, C<continue> is actually a | |
| 2786 | When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a | |
| 2288 | flow control statement rather than a function. If | |
| 2787 | flow control statement rather than a function. If there is a | |
| 2289 | ||
| 2788 | L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a | |
| 2290 | C<foreach>), it is always executed just before the | |
| 2789 | C<while> or C<foreach>), it is always executed just before the | |
| 2291 | be evaluated again, just like the third part of | |
| 2790 | conditional is about to be evaluated again, just like the third part of | |
| 2292 | it can be used to increment a loop variable, | |
| 2791 | a C<for> loop in C. Thus it can be used to increment a loop variable, | |
| 2293 | ||
| 2792 | even when the loop has been continued via the L<C<next>|/next LABEL> | |
| 2793 | statement (which is similar to the C L<C<continue>|/continue BLOCK> | |
| 2294 | 2794 | statement). |
| 2295 | 2795 | |
| 2296 | 2796 | =end original |
| 2297 | 2797 | |
| 2298 | BLOCK が引き続く場合、C<continue> は実際には関数ではなく、 | |
| 2798 | BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、 | |
| 2299 | ||
| 2799 | 実行制御文です。 | |
| 2300 | ||
| 2800 | L<C<continue>|/continue BLOCK> BLOCK が BLOCK (典型的には C<while> または | |
| 2301 | C<for> | |
| 2801 | C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます; | |
| 2302 | ||
| 2802 | これは C における C<for> ループの 3 番目の部分と同様です。 | |
| 2803 | 従って、これは L<C<next>|/next LABEL> 文 (これは C の | |
| 2804 | L<C<continue>|/continue BLOCK> 文と似ています) を使って | |
| 2303 | 2805 | ループが繰り返されるときでもループ変数を増やしたいときに使えます。 |
| 2304 | 2806 | |
| 2305 | 2807 | =begin original |
| 2306 | 2808 | |
| 2307 | C<last>, C<next> | |
| 2809 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or | |
| 2308 | ||
| 2810 | L<C<redo>|/redo LABEL> may appear within a | |
| 2309 | t | |
| 2811 | L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and | |
| 2310 | ||
| 2812 | L<C<redo>|/redo LABEL> behave as if they had been executed within the | |
| 2813 | main block. So will L<C<next>|/next LABEL>, but since it will execute a | |
| 2814 | L<C<continue>|/continue BLOCK> block, it may be more entertaining. | |
| 2311 | 2815 | |
| 2312 | 2816 | =end original |
| 2313 | 2817 | |
| 2314 | C<last>, C<next>, C<redo> | |
| 2818 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
| 2315 | C< | |
| 2819 | L<C<continue>|/continue BLOCK> ブロック内に現れる可能性があります; | |
| 2316 | C< | |
| 2820 | L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの中で | |
| 2317 | ||
| 2821 | 実行されたのと同じように振舞います。 | |
| 2822 | L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを | |
| 2823 | 実行することになるので、より面白いことになります。 | |
| 2318 | 2824 | |
| 2319 | 2825 | while (EXPR) { |
| 2320 | 2826 | ### redo always comes here |
| 2321 | 2827 | do_something; |
| 2322 | 2828 | } continue { |
| 2323 | 2829 | ### next always comes here |
| 2324 | 2830 | do_something_else; |
| 2325 | 2831 | # then back the top to re-check EXPR |
| 2326 | 2832 | } |
| 2327 | 2833 | ### last always comes here |
| 2328 | 2834 | |
| 2329 | 2835 | =begin original |
| 2330 | 2836 | |
| 2331 | Omitting the C<continue> section is equivalent to | |
| 2837 | Omitting the L<C<continue>|/continue BLOCK> section is equivalent to | |
| 2332 | empty one, logically enough, so C<next> goes | |
| 2838 | using an empty one, logically enough, so L<C<next>|/next LABEL> goes | |
| 2333 | to check the condition at the top of the loop. | |
| 2839 | directly back to check the condition at the top of the loop. | |
| 2334 | 2840 | |
| 2335 | 2841 | =end original |
| 2336 | 2842 | |
| 2337 | C<continue> 節を省略するのは、空の節を指定したのと同じで、 | |
| 2843 | L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、 | |
| 2338 | 論理的には十分なので、この場合、C<next> は直接ループ先頭の | |
| 2844 | 論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の | |
| 2339 | 2845 | 条件チェックに戻ります。 |
| 2340 | 2846 | |
| 2341 | 2847 | =begin original |
| 2342 | 2848 | |
| 2343 | When there is no BLOCK, C<continue> is a function | |
| 2849 | When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function | |
| 2344 | falls through the current C<when> or C<default> block instead of | |
| 2850 | that falls through the current C<when> or C<default> block instead of | |
| 2345 | a dynamically enclosing C<foreach> or exiting a lexically | |
| 2851 | iterating a dynamically enclosing C<foreach> or exiting a lexically | |
| 2346 | In Perl 5.14 and earlier, this form of | |
| 2852 | enclosing C<given>. In Perl 5.14 and earlier, this form of | |
| 2347 | only available when the | |
| 2853 | L<C<continue>|/continue BLOCK> was only available when the | |
| 2348 | ||
| 2854 | L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See | |
| 2349 | information. | |
| 2855 | L<feature> and L<perlsyn/"Switch Statements"> for more information. | |
| 2350 | 2856 | |
| 2351 | 2857 | =end original |
| 2352 | 2858 | |
| 2353 | BLOCK がなければ、C<continue> は動的に囲まれた C<foreach> や | |
| 2859 | BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や | |
| 2354 | 2860 | レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または |
| 2355 | 2861 | C<default> のブロックを通り抜けるための文です。 |
| 2356 | Perl 5.14 以前では、この形式の C<continue> | |
| 2862 | Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は | |
| 2357 | 場合にのみ | |
| 2863 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ | |
| 2864 | 利用可能です。 | |
| 2358 | 2865 | さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を |
| 2359 | 2866 | 参照してください。 |
| 2360 | 2867 | |
| 2361 | 2868 | =item cos EXPR |
| 2362 | 2869 | X<cos> X<cosine> X<acos> X<arccosine> |
| 2363 | 2870 | |
| 2364 | 2871 | =item cos |
| 2365 | 2872 | |
| 2366 | 2873 | =for Pod::Functions cosine function |
| 2367 | 2874 | |
| 2368 | 2875 | =begin original |
| 2369 | 2876 | |
| 2370 | 2877 | Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, |
| 2371 | takes the cosine of C<$_>. | |
| 2878 | takes the cosine of L<C<$_>|perlvar/$_>. | |
| 2372 | 2879 | |
| 2373 | 2880 | =end original |
| 2374 | 2881 | |
| 2375 | 2882 | (ラジアンで示した) EXPR の余弦を返します。 |
| 2376 | EXPR が省略されたときには、C<$_> の余弦を取ります。 | |
| 2883 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。 | |
| 2377 | 2884 | |
| 2378 | 2885 | =begin original |
| 2379 | 2886 | |
| 2380 | For the inverse cosine operation, you may use the | |
| 2887 | For the inverse cosine operation, you may use the | |
| 2381 | function, or use this relation: | |
| 2888 | L<C<Math::Trig::acos>|Math::Trig> function, or use this relation: | |
| 2382 | 2889 | |
| 2383 | 2890 | =end original |
| 2384 | 2891 | |
| 2385 | 逆余弦を求めるためには、C<Math::Trig::acos | |
| 2892 | 逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、 | |
| 2386 | 2893 | 以下の関係を使ってください。 |
| 2387 | 2894 | |
| 2388 | 2895 | sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } |
| 2389 | 2896 | |
| 2390 | 2897 | =item crypt PLAINTEXT,SALT |
| 2391 | 2898 | X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password> |
| 2392 | 2899 | X<decrypt> X<cryptography> X<passwd> X<encrypt> |
| 2393 | 2900 | |
| 2394 | 2901 | =for Pod::Functions one-way passwd-style encryption |
| 2395 | 2902 | |
| 2396 | 2903 | =begin original |
| 2397 | 2904 | |
| 2398 | Creates a digest string exactly like the crypt(3) function in the C | |
| 2905 | Creates a digest string exactly like the L<crypt(3)> function in the C | |
| 2399 | 2906 | library (assuming that you actually have a version there that has not |
| 2400 | 2907 | been extirpated as a potential munition). |
| 2401 | 2908 | |
| 2402 | 2909 | =end original |
| 2403 | 2910 | |
| 2404 | C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を | |
| 2911 | C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を | |
| 2405 | 2912 | 作成します(一時的な必需品として、まだ絶滅していないバージョンを |
| 2406 | 2913 | 持っていると仮定しています)。 |
| 2407 | 2914 | |
| 2408 | 2915 | =begin original |
| 2409 | 2916 | |
| 2410 | crypt | |
| 2917 | L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The | |
| 2918 | PLAINTEXT and SALT are turned | |
| 2411 | 2919 | into a short string, called a digest, which is returned. The same |
| 2412 | 2920 | PLAINTEXT and SALT will always return the same string, but there is no |
| 2413 | 2921 | (known) way to get the original PLAINTEXT from the hash. Small |
| 2414 | 2922 | changes in the PLAINTEXT or SALT will result in large changes in the |
| 2415 | 2923 | digest. |
| 2416 | 2924 | |
| 2417 | 2925 | =end original |
| 2418 | 2926 | |
| 2419 | crypt | |
| 2927 | L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。 | |
| 2420 | 2928 | PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、 |
| 2421 | 2929 | それが返されます。 |
| 2422 | 2930 | PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから |
| 2423 | 2931 | 元の PLAINTEXT を得る(既知の)方法はありません。 |
| 2424 | 2932 | PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。 |
| 2425 | 2933 | |
| 2426 | 2934 | =begin original |
| 2427 | 2935 | |
| 2428 | 2936 | There is no decrypt function. This function isn't all that useful for |
| 2429 | 2937 | cryptography (for that, look for F<Crypt> modules on your nearby CPAN |
| 2430 | 2938 | mirror) and the name "crypt" is a bit of a misnomer. Instead it is |
| 2431 | 2939 | primarily used to check if two pieces of text are the same without |
| 2432 | 2940 | having to transmit or store the text itself. An example is checking |
| 2433 | 2941 | if a correct password is given. The digest of the password is stored, |
| 2434 | 2942 | not the password itself. The user types in a password that is |
| 2435 | crypt | |
| 2943 | L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored | |
| 2436 | match, the password is correct. | |
| 2944 | digest. If the two digests match, the password is correct. | |
| 2437 | 2945 | |
| 2438 | 2946 | =end original |
| 2439 | 2947 | |
| 2440 | 2948 | 復号化関数はありません。 |
| 2441 | 2949 | この関数は暗号化のためにはまったく役に立ちません(このためには、 |
| 2442 | 2950 | お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、 |
| 2443 | 2951 | "crypt" という名前は少し間違った名前です。 |
| 2444 | 2952 | その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを |
| 2445 | 2953 | 転送したり保管したりせずにチェックするために使います。 |
| 2446 | 2954 | 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 |
| 2447 | 2955 | パスワード自身ではなく、パスワードのダイジェストが保管されます。 |
| 2448 | 2956 | ユーザーがパスワードを入力すると、保管されているダイジェストと同じ |
| 2449 | salt で crypt | |
| 2957 | salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。 | |
| 2450 | 2958 | 二つのダイジェストが同じなら、パスワードは正しいです。 |
| 2451 | 2959 | |
| 2452 | 2960 | =begin original |
| 2453 | 2961 | |
| 2454 | 2962 | When verifying an existing digest string you should use the digest as |
| 2455 | 2963 | the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used |
| 2456 | 2964 | to create the digest is visible as part of the digest. This ensures |
| 2457 | crypt | |
| 2965 | L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same | |
| 2458 | This allows your code to work with the standar | |
| 2966 | salt as the digest. This allows your code to work with the standard | |
| 2459 | with more exotic implementations. | |
| 2967 | L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations. | |
| 2460 | nothing about the returned string itself nor | |
| 2968 | In other words, assume nothing about the returned string itself nor | |
| 2461 | of SALT may matter. | |
| 2969 | about how many bytes of SALT may matter. | |
| 2462 | 2970 | |
| 2463 | 2971 | =end original |
| 2464 | 2972 | |
| 2465 | 2973 | すでにあるダイジェスト文字列を検証するには、ダイジェストを |
| 2466 | 2974 | (C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。 |
| 2467 | 2975 | ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 |
| 2468 | これにより、crypt | |
| 2976 | これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を | |
| 2469 | ハッシュ化できるようにします。 | |
| 2977 | ダイジェストとしてハッシュ化できるようにします。 | |
| 2470 | これによって標準的な C<crypt|/crypt> や、より風変わりな | |
| 2978 | これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな | |
| 2979 | 実装でも動作します。 | |
| 2471 | 2980 | 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 |
| 2472 | 2981 | どのような仮定もしてはいけません。 |
| 2473 | 2982 | |
| 2474 | 2983 | =begin original |
| 2475 | 2984 | |
| 2476 | 2985 | Traditionally the result is a string of 13 bytes: two first bytes of |
| 2477 | 2986 | the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only |
| 2478 | 2987 | the first eight bytes of PLAINTEXT mattered. But alternative |
| 2479 | 2988 | hashing schemes (like MD5), higher level security schemes (like C2), |
| 2480 | 2989 | and implementations on non-Unix platforms may produce different |
| 2481 | 2990 | strings. |
| 2482 | 2991 | |
| 2483 | 2992 | =end original |
| 2484 | 2993 | |
| 2485 | 2994 | 伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて |
| 2486 | 2995 | 集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の |
| 2487 | 2996 | 8 バイトだけが意味があります。 |
| 2488 | 2997 | しかし、(MD5 のように) 異なったハッシュ手法、 |
| 2489 | 2998 | (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの |
| 2490 | 2999 | 実装などでは異なった文字列が生成されることがあります。 |
| 2491 | 3000 | |
| 2492 | 3001 | =begin original |
| 2493 | 3002 | |
| 2494 | 3003 | When choosing a new salt create a random two character string whose |
| 2495 | 3004 | characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.', |
| 2496 | 3005 | '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of |
| 2497 | 3006 | characters is just a recommendation; the characters allowed in |
| 2498 | 3007 | the salt depend solely on your system's crypt library, and Perl can't |
| 2499 | restrict what salts C<crypt | |
| 3008 | restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts. | |
| 2500 | 3009 | |
| 2501 | 3010 | =end original |
| 2502 | 3011 | |
| 2503 | 3012 | 新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から |
| 2504 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
| 3013 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
| 2505 | ランダムに2 つの文字を選びます。 | |
| 3014 | ようにして)ランダムに2 つの文字を選びます。 | |
| 2506 | 3015 | この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 |
| 2507 | ライブラリだけに依存し、Perl は C<crypt | |
| 3016 | ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が | |
| 2508 | ついて制限しません。 | |
| 3017 | どのような salt を受け付けるかについて制限しません。 | |
| 2509 | 3018 | |
| 2510 | 3019 | =begin original |
| 2511 | 3020 | |
| 2512 | 3021 | Here's an example that makes sure that whoever runs this program knows |
| 2513 | 3022 | their password: |
| 2514 | 3023 | |
| 2515 | 3024 | =end original |
| 2516 | 3025 | |
| 2517 | 3026 | プログラムを実行する人が、 |
| 2518 | 3027 | 自分のパスワードを知っていることを確認する例です: |
| 2519 | 3028 | |
| 2520 | $pwd = (getpwuid($<))[1]; | |
| 3029 | my $pwd = (getpwuid($<))[1]; | |
| 2521 | 3030 | |
| 2522 | 3031 | system "stty -echo"; |
| 2523 | 3032 | print "Password: "; |
| 2524 | chomp($word = <STDIN>); | |
| 3033 | chomp(my $word = <STDIN>); | |
| 2525 | 3034 | print "\n"; |
| 2526 | 3035 | system "stty echo"; |
| 2527 | 3036 | |
| 2528 | 3037 | if (crypt($word, $pwd) ne $pwd) { |
| 2529 | 3038 | die "Sorry...\n"; |
| 2530 | 3039 | } else { |
| 2531 | 3040 | print "ok\n"; |
| 2532 | 3041 | } |
| 2533 | 3042 | |
| 2534 | 3043 | =begin original |
| 2535 | 3044 | |
| 2536 | 3045 | Of course, typing in your own password to whoever asks you |
| 2537 | 3046 | for it is unwise. |
| 2538 | 3047 | |
| 2539 | 3048 | =end original |
| 2540 | 3049 | |
| 2541 | 3050 | もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。 |
| 2542 | 3051 | |
| 2543 | 3052 | =begin original |
| 2544 | 3053 | |
| 2545 | The L<crypt|/crypt> function is unsuitable for hashing | |
| 3054 | The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing | |
| 2546 | of data, not least of all because you can't get the | |
| 3055 | large quantities of data, not least of all because you can't get the | |
| 2547 | back. Look at the L<Digest> module for more robust | |
| 3056 | information back. Look at the L<Digest> module for more robust | |
| 3057 | algorithms. | |
| 2548 | 3058 | |
| 2549 | 3059 | =end original |
| 2550 | 3060 | |
| 2551 | L<crypt|/crypt> 関数は大量のデータのハッシュ化に | |
| 3061 | L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には | |
| 2552 | 情報を戻せないという理由だけではありません。 | |
| 3062 | 向いていません; これは情報を戻せないという理由だけではありません。 | |
| 2553 | 3063 | より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。 |
| 2554 | 3064 | |
| 2555 | 3065 | =begin original |
| 2556 | 3066 | |
| 2557 | If using crypt | |
| 3067 | If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which | |
| 2558 | characters with codepoints above 255), Perl tries to | |
| 3068 | I<potentially> has characters with codepoints above 255), Perl tries to | |
| 2559 | of the situation by trying to downgrade (a copy of) | |
| 3069 | make sense of the situation by trying to downgrade (a copy of) the | |
| 2560 | ||
| 3070 | string back to an eight-bit byte string before calling | |
| 2561 | (on that copy). If that works, good. | |
| 3071 | L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good. | |
| 2562 | C< | |
| 3072 | If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with | |
| 3073 | L<C<Wide character in crypt>|perldiag/Wide character in %s>. | |
| 2563 | 3074 | |
| 2564 | 3075 | =end original |
| 2565 | 3076 | |
| 2566 | 3077 | Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を |
| 2567 | 含みます)に crypt | |
| 3078 | 含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は | |
| 3079 | L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた | |
| 2568 | 3080 | 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) |
| 2569 | 3081 | ことで状況のつじつまを合わせようとします。 |
| 2570 | 3082 | うまく動けば、それでよし。 |
| 2571 | 動かなければ、crypt | |
| 3083 | 動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は | |
| 2572 | die | |
| 3084 | L<C<Wide character in crypt>|perldiag/Wide character in %s> という | |
| 3085 | メッセージと共に die します。 | |
| 2573 | 3086 | |
| 2574 | 3087 | =begin original |
| 2575 | 3088 | |
| 2576 | 3089 | Portability issues: L<perlport/crypt>. |
| 2577 | 3090 | |
| 2578 | 3091 | =end original |
| 2579 | 3092 | |
| 2580 | 3093 | 移植性の問題: L<perlport/crypt>。 |
| 2581 | 3094 | |
| 2582 | 3095 | =item dbmclose HASH |
| 2583 | 3096 | X<dbmclose> |
| 2584 | 3097 | |
| 2585 | 3098 | =for Pod::Functions breaks binding on a tied dbm file |
| 2586 | 3099 | |
| 2587 | 3100 | =begin original |
| 2588 | 3101 | |
| 2589 | [This function has been largely superseded by the | |
| 3102 | [This function has been largely superseded by the | |
| 3103 | L<C<untie>|/untie VARIABLE> function.] | |
| 2590 | 3104 | |
| 2591 | 3105 | =end original |
| 2592 | 3106 | |
| 2593 | [この関数は、C<untie> 関数に大きくとって代わられました。] | |
| 3107 | [この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。] | |
| 2594 | 3108 | |
| 2595 | 3109 | =begin original |
| 2596 | 3110 | |
| 2597 | 3111 | Breaks the binding between a DBM file and a hash. |
| 2598 | 3112 | |
| 2599 | 3113 | =end original |
| 2600 | 3114 | |
| 2601 | 3115 | DBM ファイルとハッシュの連結をはずします。 |
| 2602 | 3116 | |
| 2603 | 3117 | =begin original |
| 2604 | 3118 | |
| 2605 | 3119 | Portability issues: L<perlport/dbmclose>. |
| 2606 | 3120 | |
| 2607 | 3121 | =end original |
| 2608 | 3122 | |
| 2609 | 3123 | 移植性の問題: L<perlport/dbmclose>。 |
| 2610 | 3124 | |
| 2611 | 3125 | =item dbmopen HASH,DBNAME,MASK |
| 2612 | 3126 | X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm> |
| 2613 | 3127 | |
| 2614 | 3128 | =for Pod::Functions create binding on a tied dbm file |
| 2615 | 3129 | |
| 2616 | 3130 | =begin original |
| 2617 | 3131 | |
| 2618 | 3132 | [This function has been largely superseded by the |
| 2619 | L<tie|/tie VARIABLE,CLASSNAME,LIST> function.] | |
| 3133 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.] | |
| 2620 | 3134 | |
| 2621 | 3135 | =end original |
| 2622 | 3136 | |
| 2623 | [この関数は、L<tie|/tie VARIABLE,CLASSNAME,LIST> 関数に | |
| 3137 | [この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に | |
| 2624 | 3138 | 大きくとって代わられました。] |
| 2625 | 3139 | |
| 2626 | 3140 | =begin original |
| 2627 | 3141 | |
| 2628 | This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley | |
| 3142 | This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley | |
| 2629 | hash. HASH is the name of the hash. (Unlike normal | |
| 3143 | DB file to a hash. HASH is the name of the hash. (Unlike normal | |
| 2630 | argument is I<not> a | |
| 3144 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, the first argument is I<not> a | |
| 2631 | i | |
| 3145 | filehandle, even though it looks like one). DBNAME is the name of the | |
| 2632 | ||
| 3146 | database (without the F<.dir> or F<.pag> extension if any). If the | |
| 2633 | ||
| 3147 | database does not exist, it is created with protection specified by MASK | |
| 2634 | the | |
| 3148 | (as modified by the L<C<umask>|/umask EXPR>). To prevent creation of | |
| 2635 | ||
| 3149 | the database if it doesn't exist, you may specify a MASK of 0, and the | |
| 2636 | ||
| 3150 | function will return a false value if it can't find an existing | |
| 2637 | only the older DBM functions, you may | |
| 3151 | database. If your system supports only the older DBM functions, you may | |
| 3152 | make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your | |
| 2638 | 3153 | program. In older versions of Perl, if your system had neither DBM nor |
| 2639 | ndbm, calling C<dbmopen> produced a fatal | |
| 3154 | ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal | |
| 2640 | sdbm(3). | |
| 3155 | error; it now falls back to L<sdbm(3)>. | |
| 2641 | 3156 | |
| 2642 | 3157 | =end original |
| 2643 | 3158 | |
| 2644 | dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは | |
| 3159 | L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは | |
| 2645 | 連想配列に結び付けます。 | |
| 3160 | Berkeley DB ファイルを連想配列に結び付けます。 | |
| 2646 | 3161 | HASH は、その連想配列の名前です。 |
| 2647 | (普通の C<open> とは違って、最初の引数は | |
| 3162 | (普通の L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違って、最初の引数は | |
| 2648 | まあ、似たようなものですが)。 | |
| 3163 | ファイルハンドル I<ではありません>; まあ、似たようなものですが)。 | |
| 2649 | 3164 | DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても |
| 2650 | 3165 | つけません)。 |
| 2651 | データベースが存在しなければ、M | |
| 3166 | データベースが存在しなければ、MASK (を L<C<umask>|/umask EXPR> で | |
| 2652 | 指定されたモードで作られます。 | |
| 3167 | 修正したもの) で指定されたモードで作られます。 | |
| 2653 | 存在しないときにデータベースを作成しないようにするには、M | |
| 3168 | 存在しないときにデータベースを作成しないようにするには、MASK に 0 を | |
| 2654 | 3169 | 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 |
| 2655 | 3170 | 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ |
| 2656 | dbmopen | |
| 3171 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。 | |
| 2657 | 3172 | 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 |
| 2658 | dbmopen | |
| 3173 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります; | |
| 2659 | フォールバックします。 | |
| 3174 | 現在では L<sdbm(3)> にフォールバックします。 | |
| 2660 | 3175 | |
| 2661 | 3176 | =begin original |
| 2662 | 3177 | |
| 2663 | 3178 | If you don't have write access to the DBM file, you can only read hash |
| 2664 | 3179 | variables, not set them. If you want to test whether you can write, |
| 2665 | either use file tests or try setting a dummy hash entry inside an | |
| 3180 | either use file tests or try setting a dummy hash entry inside an | |
| 2666 | to trap the error. | |
| 3181 | L<C<eval>|/eval EXPR> to trap the error. | |
| 2667 | 3182 | |
| 2668 | 3183 | =end original |
| 2669 | 3184 | |
| 2670 | 3185 | DBM ファイルに対して、書き込み権が無いときには、ハッシュ |
| 2671 | 3186 | 配列を読みだすことだけができ、設定することはできません。 |
| 2672 | 3187 | 書けるか否かを調べたい場合には、ファイルテスト |
| 2673 | 演算子を使うか、エラーをトラップするための C<eval> の中で、 | |
| 3188 | 演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、 | |
| 2674 | 3189 | ダミーのハッシュエントリを設定してみることになります。 |
| 2675 | 3190 | |
| 2676 | 3191 | =begin original |
| 2677 | 3192 | |
| 2678 | Note that functions such as C<keys> | |
| 3193 | Note that functions such as L<C<keys>|/keys HASH> and | |
| 2679 | ||
| 3194 | L<C<values>|/values HASH> may return huge lists when used on large DBM | |
| 2680 | f | |
| 3195 | files. You may prefer to use the L<C<each>|/each HASH> function to | |
| 3196 | iterate over large DBM files. Example: | |
| 2681 | 3197 | |
| 2682 | 3198 | =end original |
| 2683 | 3199 | |
| 2684 | 大きな DBM ファイルを扱うときには、C<keys> | |
| 3200 | 大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH> や | |
| 2685 | 巨大なリストを返します。 | |
| 3201 | L<C<values>|/values HASH> のような関数は、巨大なリストを返します。 | |
| 2686 | 大きな DBM ファイルでは、C<each> 関数を使って繰り返しを | |
| 3202 | 大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを | |
| 2687 | 良いかもしれません。 | |
| 3203 | 行なった方が良いかもしれません。 | |
| 2688 | 3204 | 例: |
| 2689 | 3205 | |
| 2690 | 3206 | # print out history file offsets |
| 2691 | 3207 | dbmopen(%HIST,'/usr/lib/news/history',0666); |
| 2692 | 3208 | while (($key,$val) = each %HIST) { |
| 2693 | 3209 | print $key, ' = ', unpack('L',$val), "\n"; |
| 2694 | 3210 | } |
| 2695 | 3211 | dbmclose(%HIST); |
| 2696 | 3212 | |
| 2697 | 3213 | =begin original |
| 2698 | 3214 | |
| 2699 | 3215 | See also L<AnyDBM_File> for a more general description of the pros and |
| 2700 | 3216 | cons of the various dbm approaches, as well as L<DB_File> for a particularly |
| 2701 | 3217 | rich implementation. |
| 2702 | 3218 | |
| 2703 | 3219 | =end original |
| 2704 | 3220 | |
| 2705 | 3221 | 様々な dbm 手法に対する利点欠点に関するより一般的な記述および |
| 2706 | 3222 | 特にリッチな実装である L<DB_File> に関しては |
| 2707 | 3223 | L<AnyDBM_File> も参照してください。 |
| 2708 | 3224 | |
| 2709 | 3225 | =begin original |
| 2710 | 3226 | |
| 2711 | 3227 | You can control which DBM library you use by loading that library |
| 2712 | before you call dbmopen | |
| 3228 | before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>: | |
| 2713 | 3229 | |
| 2714 | 3230 | =end original |
| 2715 | 3231 | |
| 2716 | dbmopen | |
| 3232 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを | |
| 2717 | どの DBM ライブラリを使うかを制御できます: | |
| 3233 | 読み込むことで、どの DBM ライブラリを使うかを制御できます: | |
| 2718 | 3234 | |
| 2719 | 3235 | use DB_File; |
| 2720 | 3236 | dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") |
| 2721 | 3237 | or die "Can't open netscape history file: $!"; |
| 2722 | 3238 | |
| 2723 | 3239 | =begin original |
| 2724 | 3240 | |
| 2725 | 3241 | Portability issues: L<perlport/dbmopen>. |
| 2726 | 3242 | |
| 2727 | 3243 | =end original |
| 2728 | 3244 | |
| 2729 | 3245 | 移植性の問題: L<perlport/dbmopen>。 |
| 2730 | 3246 | |
| 2731 | 3247 | =item defined EXPR |
| 2732 | 3248 | X<defined> X<undef> X<undefined> |
| 2733 | 3249 | |
| 2734 | 3250 | =item defined |
| 2735 | 3251 | |
| 2736 | 3252 | =for Pod::Functions test whether a value, variable, or function is defined |
| 2737 | 3253 | |
| 2738 | 3254 | =begin original |
| 2739 | 3255 | |
| 2740 | Returns a Boolean value telling whether EXPR has a value other than | |
| 3256 | Returns a Boolean value telling whether EXPR has a value other than the | |
| 2741 | ||
| 3257 | undefined value L<C<undef>|/undef EXPR>. If EXPR is not present, | |
| 2742 | checked. | |
| 3258 | L<C<$_>|perlvar/$_> is checked. | |
| 2743 | 3259 | |
| 2744 | 3260 | =end original |
| 2745 | 3261 | |
| 2746 | 左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、 | |
| 3262 | 左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、 | |
| 2747 | 返します。 | |
| 3263 | ブール値を返します。 | |
| 2748 | EXPR がない場合は、C<$_> がチェックされます。 | |
| 3264 | EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。 | |
| 2749 | 3265 | |
| 2750 | 3266 | =begin original |
| 2751 | 3267 | |
| 2752 | Many operations return C<undef> to indicate failure, end | |
| 3268 | Many operations return L<C<undef>|/undef EXPR> to indicate failure, end | |
| 2753 | system error, uninitialized variable, and other exceptional | |
| 3269 | of file, system error, uninitialized variable, and other exceptional | |
| 2754 | conditions. This function allows you to distinguish | |
| 3270 | conditions. This function allows you to distinguish | |
| 2755 | other values. (A simple Boolean test will | |
| 3271 | L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will | |
| 2756 | C<undef>, zero, the empty string, | |
| 3272 | not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string, | |
| 2757 | ||
| 3273 | and C<"0">, which are all equally false.) Note that since | |
| 2758 | d | |
| 3274 | L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't | |
| 2759 | ||
| 3275 | I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY> | |
| 2760 | ||
| 3276 | returns L<C<undef>|/undef EXPR> when its argument is an empty array, | |
| 3277 | I<or> when the element to return happens to be L<C<undef>|/undef EXPR>. | |
| 2761 | 3278 | |
| 2762 | 3279 | =end original |
| 2763 | 3280 | |
| 2764 | 3281 | 多くの演算子が、EOF や未初期化変数、システムエラーといった、 |
| 2765 | 例外的な条件で C<undef> を返すようになっています。 | |
| 3282 | 例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。 | |
| 2766 | この関数は、他の値と C<undef> とを区別するために使えます。 | |
| 3283 | この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。 | |
| 2767 | (単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を | |
| 3284 | (単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を | |
| 2768 | 区別することができません。) | |
| 3285 | 返すので、区別することができません。) | |
| 2769 | C<undef> は有効なスカラ値なので、その存在が I<必ずしも> | |
| 3286 | L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも> | |
| 2770 | 3287 | 例外的な状況を表すとは限らないということに注意してください: |
| 2771 | C<pop> は引数が空の配列だったときに C<undef> を | |
| 3288 | L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR> を | |
| 2772 | I<あるいは> 返すべき要素がたまたま | |
| 3289 | 返しますが、I<あるいは> 返すべき要素がたまたま | |
| 3290 | L<C<undef>|/undef EXPR> だったのかもしれません。 | |
| 2773 | 3291 | |
| 2774 | 3292 | =begin original |
| 2775 | 3293 | |
| 2776 | You may also use C<defined(&func)> to check whether subroutine C< | |
| 3294 | You may also use C<defined(&func)> to check whether subroutine C<func> | |
| 2777 | 3295 | has ever been defined. The return value is unaffected by any forward |
| 2778 | declarations of C< | |
| 3296 | declarations of C<func>. A subroutine that is not defined | |
| 2779 | 3297 | may still be callable: its package may have an C<AUTOLOAD> method that |
| 2780 | 3298 | makes it spring into existence the first time that it is called; see |
| 2781 | 3299 | L<perlsub>. |
| 2782 | 3300 | |
| 2783 | 3301 | =end original |
| 2784 | 3302 | |
| 2785 | C<defined(&func)> とすることでサブルーチン C< | |
| 3303 | C<defined(&func)> とすることでサブルーチン C<func> の存在を、 | |
| 2786 | 3304 | 確かめることもできます。 |
| 2787 | 返り値は C< | |
| 3305 | 返り値は C<func> の前方定義には影響されません。 | |
| 2788 | 3306 | 定義されていないサブルーチンも呼び出し可能です: |
| 2789 | 3307 | 最初に呼び出されたときに存在するようにするための |
| 2790 | 3308 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません; |
| 2791 | 3309 | L<perlsub> を参照してください。 |
| 2792 | 3310 | |
| 2793 | 3311 | =begin original |
| 2794 | 3312 | |
| 2795 | Use of C<defined> on aggregates (hashes and arrays) is | |
| 3313 | Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is | |
| 2796 | used to report whether memory for that | |
| 3314 | no longer supported. It used to report whether memory for that | |
| 2797 | allocated. | |
| 3315 | aggregate had ever been allocated. You should instead use a simple | |
| 2798 | ||
| 3316 | test for size: | |
| 2799 | 3317 | |
| 2800 | 3318 | =end original |
| 2801 | 3319 | |
| 2802 | 集合(ハッシュや配列)への C<defined> の使用は | |
| 3320 | 集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は | |
| 2803 | ||
| 3321 | もはや対応していません。 | |
| 2804 | 用いられていました。 | |
| 3322 | これはその集合にメモリが割り当てられたかを報告するのに用いられていました。 | |
| 2805 | この振る舞いは将来のバージョンの Perl では消滅するかもしれません。 | |
| 2806 | 3323 | 代わりにサイズに対する簡単なテストを使うべきです。 |
| 2807 | 3324 | |
| 2808 | 3325 | if (@an_array) { print "has array elements\n" } |
| 2809 | 3326 | if (%a_hash) { print "has hash members\n" } |
| 2810 | 3327 | |
| 2811 | 3328 | =begin original |
| 2812 | 3329 | |
| 2813 | 3330 | When used on a hash element, it tells you whether the value is defined, |
| 2814 | not whether the key exists in the hash. Use L< | |
| 3331 | not whether the key exists in the hash. Use L<C<exists>|/exists EXPR> | |
| 2815 | purpose. | |
| 3332 | for the latter purpose. | |
| 2816 | 3333 | |
| 2817 | 3334 | =end original |
| 2818 | 3335 | |
| 2819 | 3336 | ハッシュの要素に対して用いると、value が定義されているか否かを |
| 2820 | 3337 | 返すものであって、ハッシュに key が存在するか否かを返すのではありません。 |
| 2821 | この用途には、L</exists> を使ってください。 | |
| 3338 | この用途には、L<C<exists>|/exists EXPR> を使ってください。 | |
| 2822 | 3339 | |
| 2823 | 3340 | =begin original |
| 2824 | 3341 | |
| 2825 | 3342 | Examples: |
| 2826 | 3343 | |
| 2827 | 3344 | =end original |
| 2828 | 3345 | |
| 2829 | 3346 | 例: |
| 2830 | 3347 | |
| 2831 | 3348 | print if defined $switch{D}; |
| 2832 | 3349 | print "$val\n" while defined($val = pop(@ary)); |
| 2833 | 3350 | die "Can't readlink $sym: $!" |
| 2834 | 3351 | unless defined($value = readlink $sym); |
| 2835 | sub foo { defined &$bar ? | |
| 3352 | sub foo { defined &$bar ? $bar->(@_) : die "No bar"; } | |
| 2836 | 3353 | $debugging = 0 unless defined $debugging; |
| 2837 | 3354 | |
| 2838 | 3355 | =begin original |
| 2839 | 3356 | |
| 2840 | Note: Many folks tend to overuse C<defined> and are | |
| 3357 | Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are | |
| 2841 | discover that the number C<0> and C<""> (the | |
| 3358 | then surprised to discover that the number C<0> and C<""> (the | |
| 2842 | defined values. For example, if you | |
| 3359 | zero-length string) are, in fact, defined values. For example, if you | |
| 3360 | say | |
| 2843 | 3361 | |
| 2844 | 3362 | =end original |
| 2845 | 3363 | |
| 2846 | 注意: 多くの人々が C<defined> を使いすぎて、C<0> と | |
| 3364 | 注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と | |
| 2847 | 実際のところ定義された値であることに驚くようです。 | |
| 3365 | C<"">(空文字列) が実際のところ定義された値であることに驚くようです。 | |
| 2848 | 3366 | 例えば、以下のように書くと: |
| 2849 | 3367 | |
| 2850 | 3368 | "ab" =~ /a(.*)b/; |
| 2851 | 3369 | |
| 2852 | 3370 | =begin original |
| 2853 | 3371 | |
| 2854 | 3372 | The pattern match succeeds and C<$1> is defined, although it |
| 2855 | 3373 | matched "nothing". It didn't really fail to match anything. Rather, it |
| 2856 | 3374 | matched something that happened to be zero characters long. This is all |
| 2857 | 3375 | very above-board and honest. When a function returns an undefined value, |
| 2858 | 3376 | it's an admission that it couldn't give you an honest answer. So you |
| 2859 | should use C<defined> only when questioning the | |
| 3377 | should use L<C<defined>|/defined EXPR> only when questioning the | |
| 2860 | you're trying to do. At other times, a simple | |
| 3378 | integrity of what you're trying to do. At other times, a simple | |
| 2861 | what you want. | |
| 3379 | comparison to C<0> or C<""> is what you want. | |
| 2862 | 3380 | |
| 2863 | 3381 | =end original |
| 2864 | 3382 | |
| 2865 | 3383 | パターンマッチングが成功し、C<$1> が定義されても、実際には |
| 2866 | 3384 | 「なし」にマッチしています。 |
| 2867 | 3385 | しかしこれは何にもマッチしていないわけではありません。 |
| 2868 | 3386 | 何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。 |
| 2869 | 3387 | これは非常に率直で正直なことです。 |
| 2870 | 3388 | 関数が未定義値を返すとき、正直な答えを返すことができないことを |
| 2871 | 3389 | 告白しています。 |
| 2872 | 3390 | ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ |
| 2873 | C<defined> を使うべきです。 | |
| 3391 | L<C<defined>|/defined EXPR> を使うべきです。 | |
| 2874 | 3392 | その他の場合では、単に C<0> または C<""> と比較するというのがあなたの |
| 2875 | 3393 | 求めているものです。 |
| 2876 | 3394 | |
| 2877 | 3395 | =begin original |
| 2878 | 3396 | |
| 2879 | See also L</undef>, L< | |
| 3397 | See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, | |
| 3398 | L<C<ref>|/ref EXPR>. | |
| 2880 | 3399 | |
| 2881 | 3400 | =end original |
| 2882 | 3401 | |
| 2883 | L</undef>, L</exists>, L</ref> も | |
| 3402 | L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も | |
| 3403 | 参照してください。 | |
| 2884 | 3404 | |
| 2885 | 3405 | =item delete EXPR |
| 2886 | 3406 | X<delete> |
| 2887 | 3407 | |
| 2888 | 3408 | =for Pod::Functions deletes a value from a hash |
| 2889 | 3409 | |
| 2890 | 3410 | =begin original |
| 2891 | 3411 | |
| 2892 | Given an expression that specifies an element or slice of a hash, | |
| 3412 | Given an expression that specifies an element or slice of a hash, | |
| 2893 | deletes the specified elements from that hash | |
| 3413 | L<C<delete>|/delete EXPR> deletes the specified elements from that hash | |
| 2894 | ||
| 3414 | so that L<C<exists>|/exists EXPR> on that element no longer returns | |
| 2895 | ||
| 3415 | true. Setting a hash element to the undefined value does not remove its | |
| 3416 | key, but deleting it does; see L<C<exists>|/exists EXPR>. | |
| 2896 | 3417 | |
| 2897 | 3418 | =end original |
| 2898 | 3419 | |
| 2899 | ハッシュの要素やスライスを指定する式を取り、C<delete> は | |
| 3420 | ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は | |
| 2900 | 3421 | 指定された要素をハッシュから削除するので、 |
| 2901 | その要素に対する exists | |
| 3422 | その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。 | |
| 2902 | 3423 | ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、 |
| 2903 | delete では削除されます; L</exists> を参照してください。 | |
| 3424 | delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。 | |
| 2904 | 3425 | |
| 2905 | 3426 | =begin original |
| 2906 | 3427 | |
| 2907 | In list context, returns the value or values deleted, or the last such | |
| 3428 | In list context, usually returns the value or values deleted, or the last such | |
| 2908 | element in scalar context. The return list's length | |
| 3429 | element in scalar context. The return list's length corresponds to that of | |
| 2909 | 3430 | the argument list: deleting non-existent elements returns the undefined value |
| 2910 | in their corresponding positions. | |
| 3431 | in their corresponding positions. Since Perl 5.28, a | |
| 3432 | L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> can be passed | |
| 3433 | to C<delete>, and the return value is a list of key/value pairs (two elements | |
| 3434 | for each item deleted from the hash). | |
| 2911 | 3435 | |
| 2912 | 3436 | =end original |
| 2913 | 3437 | |
| 2914 | リストコンテキストでは削除された要素を返し、スカラコンテキストでは | |
| 3438 | リストコンテキストでは通常は削除された要素を返し、スカラコンテキストでは | |
| 2915 | 3439 | 削除された要素のうち最後のものを返します。 |
| 2916 | 返されたリストの長さは常に引数リストの長さ | |
| 3440 | 返されたリストの長さは常に引数リストの長さに対応します: | |
| 2917 | 3441 | 存在しない要素を削除すると、対応する位置に未定義値をセットして返します。 |
| 3442 | Perl 5.28 から、 | |
| 3443 | L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> を | |
| 3444 | C<delete> に渡すことができ、 | |
| 3445 | そして返り値はキー/値の組(それぞれのアイテムについて | |
| 3446 | 二つの要素が元のハッシュから削除されたもの)です。 | |
| 2918 | 3447 | |
| 2919 | 3448 | =begin original |
| 2920 | 3449 | |
| 2921 | delete | |
| 3450 | L<C<delete>|/delete EXPR> may also be used on arrays and array slices, | |
| 2922 | straightforward. Although | |
| 3451 | but its behavior is less straightforward. Although | |
| 2923 | ||
| 3452 | L<C<exists>|/exists EXPR> will return false for deleted entries, | |
| 2924 | ||
| 3453 | deleting array elements never changes indices of existing values; use | |
| 2925 | ||
| 3454 | L<C<shift>|/shift ARRAY> or L<C<splice>|/splice | |
| 2926 | ||
| 3455 | ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements | |
| 3456 | fall at the end of an array, the array's size shrinks to the position of | |
| 3457 | the highest element that still tests true for L<C<exists>|/exists EXPR>, | |
| 3458 | or to 0 if none do. In other words, an array won't have trailing | |
| 3459 | nonexistent elements after a delete. | |
| 2927 | 3460 | |
| 2928 | 3461 | =end original |
| 2929 | 3462 | |
| 2930 | delete | |
| 3463 | L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その | |
| 2931 | あまり直感的ではありません。 | |
| 3464 | 振る舞いはあまり直感的ではありません。 | |
| 2932 | 削除されたエントリに対しては exists | |
| 3465 | 削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、 | |
| 2933 | 3466 | 配列要素を削除しても、存在する値の添え字は変わりません; このためには |
| 2934 | shift | |
| 3467 | L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を | |
| 2935 | ||
| 3468 | 使ってください。 | |
| 2936 | ||
| 3469 | しかし、削除された要素が配列の末尾であった場合、配列のサイズは | |
| 3470 | L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に | |
| 3471 | 切り詰められます。 | |
| 3472 | 言い換えると、delete の後には配列の末尾に値のない要素はありません。 | |
| 2937 | 3473 | |
| 2938 | 3474 | =begin original |
| 2939 | 3475 | |
| 2940 | B<WARNING:> Calling delete on array values is | |
| 3476 | B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is | |
| 2941 | ||
| 3477 | strongly discouraged. The | |
| 3478 | notion of deleting or checking the existence of Perl array elements is not | |
| 3479 | conceptually coherent, and can lead to surprising behavior. | |
| 2942 | 3480 | |
| 2943 | 3481 | =end original |
| 2944 | 3482 | |
| 2945 | B<警告:> 配列の値に対して delete を呼び出すことは | |
| 3483 | B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く | |
| 2946 | ||
| 3484 | 非推奨です。 | |
| 3485 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
| 3486 | 驚くべき振る舞いを引き起こすことがあります。 | |
| 2947 | 3487 | |
| 2948 | 3488 | =begin original |
| 2949 | 3489 | |
| 2950 | Deleting from C<%ENV> modifies the environment. | |
| 3490 | Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment. | |
| 2951 | a DBM file deletes the entry from the DBM | |
| 3491 | Deleting from a hash tied to a DBM file deletes the entry from the DBM | |
| 2952 | ||
| 3492 | file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not | |
| 2953 | ||
| 3493 | necessarily return anything; it depends on the implementation of the | |
| 3494 | L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever | |
| 3495 | it pleases. | |
| 2954 | 3496 | |
| 2955 | 3497 | =end original |
| 2956 | 3498 | |
| 2957 | C<%ENV> から削除を行なうと、実際に環境変数を変更します。 | |
| 3499 | L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。 | |
| 2958 | 3500 | DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを |
| 2959 | 3501 | 削除します。 |
| 2960 | しかし、C<tie> されたハッシュや配列からの | |
| 3502 | しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの | |
| 2961 | 値を返すとは限りません; これは | |
| 3503 | 削除は、値を返すとは限りません; これは | |
| 3504 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE | |
| 2962 | 3505 | メソッドの実装に依存するので、どんなことでも起こります。 |
| 2963 | 3506 | |
| 2964 | 3507 | =begin original |
| 2965 | 3508 | |
| 2966 | 3509 | The C<delete local EXPR> construct localizes the deletion to the current |
| 2967 | 3510 | block at run time. Until the block exits, elements locally deleted |
| 2968 | 3511 | temporarily no longer exist. See L<perlsub/"Localized deletion of elements |
| 2969 | 3512 | of composite types">. |
| 2970 | 3513 | |
| 2971 | 3514 | =end original |
| 2972 | 3515 | |
| 2973 | 3516 | C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。 |
| 2974 | 3517 | ブロックから出るまで、ローカルで削除された要素は存在しなくなります。 |
| 2975 | 3518 | L<perlsub/"Localized deletion of elements of composite types"> を |
| 2976 | 3519 | 参照してください。 |
| 2977 | 3520 | |
| 2978 | %hash = (foo => 11, bar => 22, baz => 33); | |
| 3521 | my %hash = (foo => 11, bar => 22, baz => 33); | |
| 2979 | $scalar = delete $hash{foo}; # $scalar is 11 | |
| 3522 | my $scalar = delete $hash{foo}; # $scalar is 11 | |
| 2980 | 3523 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 |
| 2981 | @array = delete @hash{qw(foo baz)}; # @array is (undef,33) | |
| 3524 | my @array = delete @hash{qw(foo baz)}; # @array is (undef,33) | |
| 2982 | 3525 | |
| 2983 | 3526 | =begin original |
| 2984 | 3527 | |
| 2985 | 3528 | The following (inefficiently) deletes all the values of %HASH and @ARRAY: |
| 2986 | 3529 | |
| 2987 | 3530 | =end original |
| 2988 | 3531 | |
| 2989 | 3532 | 以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します: |
| 2990 | 3533 | |
| 2991 | foreach $key (keys %HASH) { | |
| 3534 | foreach my $key (keys %HASH) { | |
| 2992 | 3535 | delete $HASH{$key}; |
| 2993 | 3536 | } |
| 2994 | 3537 | |
| 2995 | foreach $index (0 .. $#ARRAY) { | |
| 3538 | foreach my $index (0 .. $#ARRAY) { | |
| 2996 | 3539 | delete $ARRAY[$index]; |
| 2997 | 3540 | } |
| 2998 | 3541 | |
| 2999 | 3542 | =begin original |
| 3000 | 3543 | |
| 3001 | 3544 | And so do these: |
| 3002 | 3545 | |
| 3003 | 3546 | =end original |
| 3004 | 3547 | |
| 3005 | 3548 | そして以下のようにもできます: |
| 3006 | 3549 | |
| 3007 | 3550 | delete @HASH{keys %HASH}; |
| 3008 | 3551 | |
| 3009 | 3552 | delete @ARRAY[0 .. $#ARRAY]; |
| 3010 | 3553 | |
| 3011 | 3554 | =begin original |
| 3012 | 3555 | |
| 3013 | 3556 | But both are slower than assigning the empty list |
| 3014 | or undefining %HASH or @ARRAY, which is the customary | |
| 3557 | or undefining %HASH or @ARRAY, which is the customary | |
| 3015 | 3558 | way to empty out an aggregate: |
| 3016 | 3559 | |
| 3017 | 3560 | =end original |
| 3018 | 3561 | |
| 3019 | 3562 | しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、 |
| 3020 | 3563 | 単に空リストを代入するか、%HASH や @ARRAY を |
| 3021 | 3564 | undef するより遅いです: |
| 3022 | 3565 | |
| 3023 | 3566 | %HASH = (); # completely empty %HASH |
| 3024 | 3567 | undef %HASH; # forget %HASH ever existed |
| 3025 | 3568 | |
| 3026 | 3569 | @ARRAY = (); # completely empty @ARRAY |
| 3027 | 3570 | undef @ARRAY; # forget @ARRAY ever existed |
| 3028 | 3571 | |
| 3029 | 3572 | =begin original |
| 3030 | 3573 | |
| 3031 | 3574 | The EXPR can be arbitrarily complicated provided its |
| 3032 | 3575 | final operation is an element or slice of an aggregate: |
| 3033 | 3576 | |
| 3034 | 3577 | =end original |
| 3035 | 3578 | |
| 3036 | 3579 | 最終的な操作が集合の要素かスライスである限りは、 |
| 3037 | 3580 | いずれかである限りは、EXPR には任意の複雑な式を置くことができます: |
| 3038 | 3581 | |
| 3039 | 3582 | delete $ref->[$x][$y]{$key}; |
| 3040 | delete | |
| 3583 | delete $ref->[$x][$y]->@{$key1, $key2, @morekeys}; | |
| 3041 | 3584 | |
| 3042 | 3585 | delete $ref->[$x][$y][$index]; |
| 3043 | delete | |
| 3586 | delete $ref->[$x][$y]->@[$index1, $index2, @moreindices]; | |
| 3044 | 3587 | |
| 3045 | 3588 | =item die LIST |
| 3046 | 3589 | X<die> X<throw> X<exception> X<raise> X<$@> X<abort> |
| 3047 | 3590 | |
| 3048 | 3591 | =for Pod::Functions raise an exception or bail out |
| 3049 | 3592 | |
| 3050 | 3593 | =begin original |
| 3051 | 3594 | |
| 3052 | C<die> raises an exception. Inside an C<eval> | |
| 3595 | L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR> | |
| 3053 | into C<$@> and the C<eval> | |
| 3596 | the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval | |
| 3054 | ||
| 3597 | EXPR> is terminated with the undefined value. If the exception is | |
| 3055 | ||
| 3598 | outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught | |
| 3056 | ||
| 3599 | exception is printed to C<STDERR> and perl exits with an exit code | |
| 3600 | indicating failure. If you need to exit the process with a specific | |
| 3601 | exit code, see L<C<exit>|/exit EXPR>. | |
| 3057 | 3602 | |
| 3058 | 3603 | =end original |
| 3059 | 3604 | |
| 3060 | C<die> は例外を発生させます。 | |
| 3605 | L<C<die>|/die LIST> は例外を発生させます。 | |
| 3061 | C<eval> の中で使用すると、 | |
| 3606 | L<C<eval>|/eval EXPR> の中で使用すると、例外が | |
| 3607 | L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は | |
| 3062 | 3608 | 未定義値を返して終了します。 |
| 3063 | 例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は | |
| 3609 | 例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は | |
| 3064 | C<STDERR> に表示 | |
| 3610 | C<STDERR> に表示され、perl は失敗を示す終了コードで終了します。 | |
| 3065 | 特定の終了コードでプロセスを終了させる必要がある場合は、 | |
| 3611 | 特定の終了コードでプロセスを終了させる必要がある場合は、 | |
| 3066 | 参照してください。 | |
| 3612 | L<C<exit>|/exit EXPR> を参照してください。 | |
| 3067 | 3613 | |
| 3068 | 3614 | =begin original |
| 3069 | 3615 | |
| 3070 | 3616 | Equivalent examples: |
| 3071 | 3617 | |
| 3072 | 3618 | =end original |
| 3073 | 3619 | |
| 3074 | 3620 | 等価な例: |
| 3075 | 3621 | |
| 3076 | 3622 | die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; |
| 3077 | 3623 | chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" |
| 3078 | 3624 | |
| 3079 | 3625 | =begin original |
| 3080 | 3626 | |
| 3081 | ||
| 3627 | Most of the time, C<die> is called with a string to use as the exception. | |
| 3082 | ||
| 3628 | You may either give a single non-reference operand to serve as the | |
| 3083 | ||
| 3629 | exception, or a list of two or more items, which will be stringified | |
| 3630 | and concatenated to make the exception. | |
| 3631 | ||
| 3632 | =end original | |
| 3633 | ||
| 3634 | ほとんどの場合、C<die> は例外として使うための文字列と共に呼び出されます。 | |
| 3635 | 例外として圧から割れる単一の非リファレンスオペランドか、 | |
| 3636 | 例外を作るために文字列化されて連結される、二つ以上のアイテムのリストを | |
| 3637 | 指定することができます。 | |
| 3638 | ||
| 3639 | =begin original | |
| 3640 | ||
| 3641 | If the string exception does not end in a newline, the current | |
| 3642 | script line number and input line number (if any) and a newline | |
| 3643 | are appended to it. Note that the "input line number" (also | |
| 3084 | 3644 | known as "chunk") is subject to whatever notion of "line" happens to |
| 3085 | 3645 | be currently in effect, and is also available as the special variable |
| 3086 | C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. | |
| 3646 | L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. | |
| 3087 | 3647 | |
| 3088 | 3648 | =end original |
| 3089 | 3649 | |
| 3090 | ||
| 3650 | 文字列例外が改行で終わっていなければ、その時点のスクリプト名と | |
| 3091 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が | |
| 3651 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が | |
| 3092 | ||
| 3652 | それに追加されます。 | |
| 3093 | 3653 | 「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると |
| 3094 | 仮定しています; また特殊変数 C<$.> でも利用可能です。 | |
| 3654 | 仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。 | |
| 3095 | 3655 | L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。 |
| 3096 | 3656 | |
| 3097 | 3657 | =begin original |
| 3098 | 3658 | |
| 3099 | 3659 | Hint: sometimes appending C<", stopped"> to your message will cause it |
| 3100 | 3660 | to make better sense when the string C<"at foo line 123"> is appended. |
| 3101 | 3661 | Suppose you are running script "canasta". |
| 3102 | 3662 | |
| 3103 | 3663 | =end original |
| 3104 | 3664 | |
| 3105 | 3665 | ヒント: メッセージの最後を C<", stopped"> のようなもので |
| 3106 | 3666 | 終わるようにしておけば、C<"at foo line 123"> のように |
| 3107 | 3667 | 追加されて、わかりやすくなります。 |
| 3108 | 3668 | "canasta" というスクリプトを実行しているとします。 |
| 3109 | 3669 | |
| 3110 | 3670 | die "/etc/games is no good"; |
| 3111 | 3671 | die "/etc/games is no good, stopped"; |
| 3112 | 3672 | |
| 3113 | 3673 | =begin original |
| 3114 | 3674 | |
| 3115 | 3675 | produce, respectively |
| 3116 | 3676 | |
| 3117 | 3677 | =end original |
| 3118 | 3678 | |
| 3119 | 3679 | これは、それぞれ以下のように表示します。 |
| 3120 | 3680 | |
| 3121 | 3681 | /etc/games is no good at canasta line 123. |
| 3122 | 3682 | /etc/games is no good, stopped at canasta line 123. |
| 3123 | 3683 | |
| 3124 | 3684 | =begin original |
| 3125 | 3685 | |
| 3126 | If | |
| 3686 | If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@> | |
| 3127 | ||
| 3687 | already contains an exception value (typically from a previous | |
| 3128 | ||
| 3688 | L<C<eval>|/eval EXPR>), then that value is reused after | |
| 3689 | appending C<"\t...propagated">. This is useful for propagating exceptions: | |
| 3129 | 3690 | |
| 3130 | 3691 | =end original |
| 3131 | 3692 | |
| 3132 | 出力が空 | |
| 3693 | 出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が | |
| 3694 | (典型的には前回の L<C<eval>|/eval EXPR> で) | |
| 3695 | 既に例外値を持っている場合、 | |
| 3133 | 3696 | 値は C<"\t...propagated"> を追加した後再利用されます。 |
| 3134 | 3697 | これは例外を伝播させる場合に有効です: |
| 3135 | 3698 | |
| 3136 | 3699 | eval { ... }; |
| 3137 | 3700 | die unless $@ =~ /Expected exception/; |
| 3138 | 3701 | |
| 3139 | 3702 | =begin original |
| 3140 | 3703 | |
| 3141 | If | |
| 3704 | If LIST was empty or made an empty string, | |
| 3142 | C< | |
| 3705 | and L<C<$@>|perlvar/$@> contains an object | |
| 3143 | ||
| 3706 | reference that has a C<PROPAGATE> method, that method will be called | |
| 3144 | ||
| 3707 | with additional file and line number parameters. The return value | |
| 3145 | ||
| 3708 | replaces the value in L<C<$@>|perlvar/$@>; i.e., as if | |
| 3709 | C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called. | |
| 3146 | 3710 | |
| 3147 | 3711 | =end original |
| 3148 | 3712 | |
| 3149 | 出力が空 | |
| 3713 | 出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを | |
| 3150 | リファレンスを含む場合、 | |
| 3714 | 含むオブジェクトへのリファレンスを含む場合、 | |
| 3151 | 呼び出されます。 | |
| 3715 | このメソッドが追加ファイルと行番号を引数として呼び出されます。 | |
| 3152 | 返り値は C<$@> の値を置き換えます; | |
| 3716 | 返り値は L<C<$@>|perlvar/$@> の値を置き換えます; | |
| 3153 | 3717 | つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が |
| 3154 | 3718 | 呼び出されたかのようになります。 |
| 3155 | 3719 | |
| 3156 | 3720 | =begin original |
| 3157 | 3721 | |
| 3158 | If | |
| 3722 | If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@> | |
| 3723 | is also empty, then the string C<"Died"> is used. | |
| 3159 | 3724 | |
| 3160 | 3725 | =end original |
| 3161 | 3726 | |
| 3162 | C<$@> | |
| 3727 | LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> も空の場合、 | |
| 3728 | C<"Died"> が使われます。 | |
| 3163 | 3729 | |
| 3164 | 3730 | =begin original |
| 3165 | 3731 | |
| 3166 | ||
| 3732 | You can also call L<C<die>|/die LIST> with a reference argument, and if | |
| 3167 | ||
| 3733 | this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@> | |
| 3734 | contains that reference. This permits more elaborate exception handling | |
| 3735 | using objects that maintain arbitrary state about the exception. Such a | |
| 3736 | scheme is sometimes preferable to matching particular string values of | |
| 3737 | L<C<$@>|perlvar/$@> with regular expressions. | |
| 3168 | 3738 | |
| 3169 | 3739 | =end original |
| 3170 | 3740 | |
| 3171 | ||
| 3741 | L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが | |
| 3172 | ||
| 3742 | L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は | |
| 3743 | そのリファレンスを持ちます。 | |
| 3744 | これは、例外の性質について任意の状態を管理するオブジェクトを使った | |
| 3745 | より複雑な例外処理の実装を可能にします。 | |
| 3746 | このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って | |
| 3747 | マッチングするときに時々好まれます。 | |
| 3173 | 3748 | |
| 3174 | exit $! if $!; # errno | |
| 3175 | exit $? >> 8 if $? >> 8; # child exit status | |
| 3176 | exit 255; # last resort | |
| 3177 | ||
| 3178 | 3749 | =begin original |
| 3179 | 3750 | |
| 3180 | ||
| 3751 | Because Perl stringifies uncaught exception messages before display, | |
| 3181 | ||
| 3752 | you'll probably want to overload stringification operations on | |
| 3182 | co | |
| 3753 | exception objects. See L<overload> for details about that. | |
| 3183 | ||
| 3754 | The stringified message should be non-empty, and should end in a newline, | |
| 3184 | ||
| 3755 | in order to fit in with the treatment of string exceptions. | |
| 3185 | upon | |
| 3756 | Also, because an exception object reference cannot be stringified | |
| 3757 | without destroying it, Perl doesn't attempt to append location or other | |
| 3758 | information to a reference exception. If you want location information | |
| 3759 | with a complex exception object, you'll have to arrange to put the | |
| 3760 | location information into the object yourself. | |
| 3186 | 3761 | |
| 3187 | 3762 | =end original |
| 3188 | 3763 | |
| 3189 | ||
| 3764 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 | |
| 3190 | ||
| 3765 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと | |
| 3191 | ||
| 3766 | 思うかもしれません。 | |
| 3192 | ||
| 3767 | これに関する詳細は L<overload> を参照してください。 | |
| 3193 | ||
| 3768 | 文字列化されたメッセージは、文字列例外の扱いに合わせるために、 | |
| 3194 | ||
| 3769 | 空ではなく、末尾は改行であるべきです。 | |
| 3770 | また、例外オブジェクトリファレンスはそれを破壊することなく | |
| 3771 | 文字列化することができないので、Perl はリファレンス例外に位置や | |
| 3772 | その他の情報を追加しようとしません。 | |
| 3773 | 複雑な例外オブジェクトに位置情報が欲しい場合、 | |
| 3774 | オブジェクト自身に位置情報を設定するように用意する必要があります。 | |
| 3195 | 3775 | |
| 3196 | 3776 | =begin original |
| 3197 | 3777 | |
| 3198 | ||
| 3778 | Because L<C<$@>|perlvar/$@> is a global variable, be careful that | |
| 3199 | ||
| 3779 | analyzing an exception caught by C<eval> doesn't replace the reference | |
| 3200 | ||
| 3780 | in the global variable. It's | |
| 3201 | a | |
| 3781 | easiest to make a local copy of the reference before any manipulations. | |
| 3202 | ||
| 3782 | Here's an example: | |
| 3203 | is a global variable and C<eval> may be used within object implementations, | |
| 3204 | be careful that analyzing the error object doesn't replace the reference in | |
| 3205 | the global variable. It's easiest to make a local copy of the reference | |
| 3206 | before any manipulations. Here's an example: | |
| 3207 | 3783 | |
| 3208 | 3784 | =end original |
| 3209 | 3785 | |
| 3210 | ||
| 3786 | L<C<$@>|perlvar/$@> はグローバル変数なので、 | |
| 3211 | eval | |
| 3787 | C<eval> により補足された例外の解析はグローバル変数の | |
| 3212 | これは、例外の性質について任意の状態を管理するオブジェクトを使った | |
| 3213 | より複雑な例外処理の実装を可能にします。 | |
| 3214 | このようなスキームは C<$@> の特定の文字列値を正規表現を使って | |
| 3215 | マッチングするときに時々好まれます。 | |
| 3216 | C<$@> はグローバル変数で、C<eval> はオブジェクト実装の内部で | |
| 3217 | 使われることがあるので、エラーオブジェクトの解析はグローバル変数の | |
| 3218 | 3788 | リファレンスを置き換えないことに注意を払わなければなりません。 |
| 3219 | 3789 | 他の操作をする前にリファレンスのローカルコピーを |
| 3220 | 3790 | 作るのが一番簡単です。 |
| 3221 | 3791 | 以下に例を示します: |
| 3222 | 3792 | |
| 3223 | 3793 | use Scalar::Util "blessed"; |
| 3224 | 3794 | |
| 3225 | 3795 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; |
| 3226 | 3796 | if (my $ev_err = $@) { |
| 3227 | 3797 | if (blessed($ev_err) |
| 3228 | 3798 | && $ev_err->isa("Some::Module::Exception")) { |
| 3229 | 3799 | # handle Some::Module::Exception |
| 3230 | 3800 | } |
| 3231 | 3801 | else { |
| 3232 | 3802 | # handle all other possible exceptions |
| 3233 | 3803 | } |
| 3234 | 3804 | } |
| 3235 | 3805 | |
| 3236 | 3806 | =begin original |
| 3237 | 3807 | |
| 3238 | ||
| 3808 | If an uncaught exception results in interpreter exit, the exit code is | |
| 3239 | ||
| 3809 | determined from the values of L<C<$!>|perlvar/$!> and | |
| 3240 | ||
| 3810 | L<C<$?>|perlvar/$?> with this pseudocode: | |
| 3241 | 3811 | |
| 3242 | 3812 | =end original |
| 3243 | 3813 | |
| 3244 | ||
| 3814 | 例外が捕捉されないとインタプリタは終了し、終了コードは以下の | |
| 3245 | ||
| 3815 | 擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> の値から | |
| 3246 | ||
| 3816 | 決定されます: | |
| 3247 | これに関する詳細は L<overload> を参照してください。 | |
| 3248 | 3817 | |
| 3818 | exit $! if $!; # errno | |
| 3819 | exit $? >> 8 if $? >> 8; # child exit status | |
| 3820 | exit 255; # last resort | |
| 3821 | ||
| 3249 | 3822 | =begin original |
| 3250 | 3823 | |
| 3251 | ||
| 3824 | As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to | |
| 3252 | ||
| 3825 | unwinding the call stack; any C<DESTROY> or C<END> handlers can then | |
| 3253 | ||
| 3826 | alter this value, and thus Perl's exit code. | |
| 3254 | ||
| 3255 | ||
| 3828 | =end original | |
| 3256 | ||
| 3257 | ||
| 3830 | L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に | |
| 3258 | ||
| 3831 | L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが | |
| 3259 | ||
| 3832 | それからこの値を変更して、これが Perl の終了コードになります。 | |
| 3833 | ||
| 3834 | =begin original | |
| 3835 | ||
| 3836 | The intent is to squeeze as much possible information about the likely cause | |
| 3837 | into the limited space of the system exit code. However, as | |
| 3838 | L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by | |
| 3839 | any system call, this means that the value of the exit code used by | |
| 3840 | L<C<die>|/die LIST> can be non-predictable, so should not be relied | |
| 3841 | upon, other than to be non-zero. | |
| 3842 | ||
| 3843 | =end original | |
| 3844 | ||
| 3845 | この意図は、できるだけ多くの似たような原因に関する情報を、システム終了 | |
| 3846 | コードという限られた領域に圧縮することです。 | |
| 3847 | しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の | |
| 3848 | C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は | |
| 3849 | 予測不能であることを意味するので、非 0 ということ以上にこの値に | |
| 3850 | 依存するべきではありません。 | |
| 3851 | ||
| 3852 | =begin original | |
| 3853 | ||
| 3854 | You can arrange for a callback to be run just before the | |
| 3855 | L<C<die>|/die LIST> does its deed, by setting the | |
| 3856 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called | |
| 3857 | with the exception as an argument, and can change the exception, | |
| 3858 | if it sees fit, by | |
| 3859 | calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on | |
| 3860 | setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some | |
| 3861 | examples. Although this feature was to be run only right before your | |
| 3862 | program was to exit, this is not currently so: the | |
| 3863 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside | |
| 3864 | L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do | |
| 3260 | 3865 | nothing in such situations, put |
| 3261 | 3866 | |
| 3262 | 3867 | =end original |
| 3263 | 3868 | |
| 3264 | C<$SIG{__DIE__}> フックをセットすることで、 | |
| 3869 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、 | |
| 3870 | L<C<die>|/die LIST> がその行動を行う | |
| 3265 | 3871 | 直前に実行されるコールバックを設定できます。 |
| 3266 | 結び付けられたハンドラは | |
| 3872 | 結び付けられたハンドラは例外を引数として呼び出され、 | |
| 3267 | 必要なら再び C<die> を呼び出すことで | |
| 3873 | 必要なら再び L<C<die>|/die LIST> を呼び出すことで例外を変更できます。 | |
| 3268 | C<%SIG> のエントリをセットする詳細については | |
| 3874 | L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、 | |
| 3269 | 例については L< | |
| 3875 | L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。 | |
| 3270 | 3876 | この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、 |
| 3271 | 3877 | 現在ではそうではありません: |
| 3272 | C<$SIG{__DIE__}> フックは eval | |
| 3878 | L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された | |
| 3273 | 呼ばれるのです! | |
| 3879 | ブロック/文字列の中でも呼ばれるのです! | |
| 3274 | 3880 | もしそのような状況で何もしなくない時は: |
| 3275 | 3881 | |
| 3276 | 3882 | die @_ if $^S; |
| 3277 | 3883 | |
| 3278 | 3884 | =begin original |
| 3279 | 3885 | |
| 3280 | 3886 | as the first line of the handler (see L<perlvar/$^S>). Because |
| 3281 | 3887 | this promotes strange action at a distance, this counterintuitive |
| 3282 | 3888 | behavior may be fixed in a future release. |
| 3283 | 3889 | |
| 3284 | 3890 | =end original |
| 3285 | 3891 | |
| 3286 | 3892 | をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。 |
| 3287 | 3893 | これは離れたところで不思議な行動を引き起こすので、 |
| 3288 | 3894 | この直感的でない振る舞いは将来のリリースで修正されるかもしれません。 |
| 3289 | 3895 | |
| 3290 | 3896 | =begin original |
| 3291 | 3897 | |
| 3292 | See also exit | |
| 3898 | See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp> | |
| 3899 | module. | |
| 3293 | 3900 | |
| 3294 | 3901 | =end original |
| 3295 | 3902 | |
| 3296 | exit | |
| 3903 | L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも | |
| 3904 | 参照してください。 | |
| 3297 | 3905 | |
| 3298 | 3906 | =item do BLOCK |
| 3299 | 3907 | X<do> X<block> |
| 3300 | 3908 | |
| 3301 | 3909 | =for Pod::Functions turn a BLOCK into a TERM |
| 3302 | 3910 | |
| 3303 | 3911 | =begin original |
| 3304 | 3912 | |
| 3305 | 3913 | Not really a function. Returns the value of the last command in the |
| 3306 | 3914 | sequence of commands indicated by BLOCK. When modified by the C<while> or |
| 3307 | 3915 | C<until> loop modifier, executes the BLOCK once before testing the loop |
| 3308 | 3916 | condition. (On other statements the loop modifiers test the conditional |
| 3309 | 3917 | first.) |
| 3310 | 3918 | |
| 3311 | 3919 | =end original |
| 3312 | 3920 | |
| 3313 | 3921 | 実際は関数ではありません。 |
| 3314 | 3922 | BLOCK で示されるコマンド列の最後の値を返します。 |
| 3315 | 3923 | C<while> や C<until> ループ修飾子で修飾すると、 |
| 3316 | 3924 | ループ条件を調べる前に 1 度、BLOCK を実行します。 |
| 3317 | 3925 | (これ以外の実行文は、ループ修飾子により、条件が最初に |
| 3318 | 3926 | 調べられます。) |
| 3319 | 3927 | |
| 3320 | 3928 | =begin original |
| 3321 | 3929 | |
| 3322 | 3930 | C<do BLOCK> does I<not> count as a loop, so the loop control statements |
| 3323 | C<next> | |
| 3931 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or | |
| 3932 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
| 3324 | 3933 | See L<perlsyn> for alternative strategies. |
| 3325 | 3934 | |
| 3326 | 3935 | =end original |
| 3327 | 3936 | |
| 3328 | C<do BLOCK> はループとしては I<扱われません>; 従って、C<next> | |
| 3937 | C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>, | |
| 3329 | C<redo> といったループ制御文は | |
| 3938 | L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は | |
| 3330 | 再開することはできません。 | |
| 3939 | ブロックから抜けたり再開することはできません。 | |
| 3331 | 3940 | その他の戦略については L<perlsyn> を参照してください。 |
| 3332 | 3941 | |
| 3333 | =item do SUBROUTINE(LIST) | |
| 3334 | X<do> | |
| 3335 | ||
| 3336 | =begin original | |
| 3337 | ||
| 3338 | This form of subroutine call is deprecated. SUBROUTINE can be a bareword | |
| 3339 | or scalar variable. | |
| 3340 | ||
| 3341 | =end original | |
| 3342 | ||
| 3343 | この形のサブルーチン呼び出しは非推奨です。 | |
| 3344 | SUBROUTINE には裸の単語またはスカラ変数が使えます。 | |
| 3345 | ||
| 3346 | 3942 | =item do EXPR |
| 3347 | 3943 | X<do> |
| 3348 | 3944 | |
| 3349 | 3945 | =begin original |
| 3350 | 3946 | |
| 3351 | 3947 | Uses the value of EXPR as a filename and executes the contents of the |
| 3352 | file as a Perl script | |
| 3948 | file as a Perl script: | |
| 3353 | 3949 | |
| 3354 | 3950 | =end original |
| 3355 | 3951 | |
| 3356 | 3952 | EXPR の値をファイル名として用い、そのファイルの中身を |
| 3357 | Perl のスクリプトとして実行します | |
| 3953 | Perl のスクリプトとして実行します: | |
| 3358 | 3954 | |
| 3955 | # load the exact specified file (./ and ../ special-cased) | |
| 3956 | do '/foo/stat.pl'; | |
| 3957 | do './stat.pl'; | |
| 3958 | do '../foo/stat.pl'; | |
| 3959 | ||
| 3960 | # search for the named file within @INC | |
| 3359 | 3961 | do 'stat.pl'; |
| 3962 | do 'foo/stat.pl'; | |
| 3360 | 3963 | |
| 3361 | 3964 | =begin original |
| 3362 | 3965 | |
| 3363 | is largely like | |
| 3966 | C<do './stat.pl'> is largely like | |
| 3364 | 3967 | |
| 3365 | 3968 | =end original |
| 3366 | 3969 | |
| 3367 | はだいたい以下のものと同じようなものですが、 | |
| 3970 | C<do './stat.pl'> はだいたい以下のものと同じようなものですが、 | |
| 3368 | 3971 | |
| 3369 | 3972 | eval `cat stat.pl`; |
| 3370 | 3973 | |
| 3371 | 3974 | =begin original |
| 3372 | 3975 | |
| 3373 | except that it's more concise, runs no external processes, keeps | |
| 3976 | except that it's more concise, runs no external processes, and keeps | |
| 3374 | the current | |
| 3977 | track of the current filename for error messages. It also differs in that | |
| 3375 | ||
| 3978 | code evaluated with C<do FILE> cannot see lexicals in the enclosing | |
| 3376 | C< | |
| 3979 | scope; C<eval STRING> does. It's the same, however, in that it does | |
| 3377 | ||
| 3980 | reparse the file every time you call it, so you probably don't want | |
| 3378 | ||
| 3981 | to do this inside a loop. | |
| 3379 | same, however, in that it does reparse the file every time you call it, | |
| 3380 | so you probably don't want to do this inside a loop. | |
| 3381 | 3982 | |
| 3382 | 3983 | =end original |
| 3383 | 3984 | |
| 3384 | 3985 | より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、 |
| 3385 | カレントディレクトリでファイルが見つからなかったときに | |
| 3386 | C<@INC> ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、 | |
| 3387 | 3986 | といったことがあります。 |
| 3388 | ||
| 3987 | C<do FILE> で評価されたコードは、入れ子のスコープにある | |
| 3389 | 参照してください。 | |
| 3390 | C<do FILENAME> で評価されたコードは、入れ子のスコープにある | |
| 3391 | 3988 | レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、 |
| 3392 | 3989 | という違いがあります。 |
| 3393 | 3990 | しかし、呼び出すたびにファイルを解析し直すという点では同じですから、 |
| 3394 | 3991 | ループ内でこれを使おうなどとは、間違っても思ったりしないように。 |
| 3395 | 3992 | |
| 3396 | 3993 | =begin original |
| 3397 | 3994 | |
| 3398 | ||
| 3995 | Using C<do> with a relative path (except for F<./> and F<../>), like | |
| 3399 | an error message in C<$@>. If C<do> cannot read the file, it returns undef | |
| 3400 | and sets C<$!> to the error. Always check C<$@> first, as compilation | |
| 3401 | could fail in a way that also sets C<$!>. If the file is successfully | |
| 3402 | compiled, C<do> returns the value of the last expression evaluated. | |
| 3403 | 3996 | |
| 3404 | 3997 | =end original |
| 3405 | 3998 | |
| 3406 | C<do> | |
| 3999 | 次のように、C<do> に (F<./> と F<../> 以外の) 相対パスを使うと: | |
| 3407 | C<undef> を返して C<$@> にエラーメッセージを設定します。 | |
| 3408 | C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に | |
| 3409 | エラーを設定します。 | |
| 3410 | コンパイルに失敗したときにも C<$!> が設定されるので、常に C<$@> を | |
| 3411 | 先にチェックします。 | |
| 3412 | ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。 | |
| 3413 | 4000 | |
| 4001 | do 'foo/stat.pl'; | |
| 4002 | ||
| 3414 | 4003 | =begin original |
| 3415 | 4004 | |
| 4005 | will search the L<C<@INC>|perlvar/@INC> directories, and update | |
| 4006 | L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC> | |
| 4007 | and L<perlvar/%INC> for these variables. In particular, note that | |
| 4008 | whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the | |
| 4009 | current directory) making these two cases equivalent, that is no | |
| 4010 | longer necessarily the case, as '.' is not included in C<@INC> by default | |
| 4011 | in perl versions 5.26.0 onwards. Instead, perl will now warn: | |
| 4012 | ||
| 4013 | =end original | |
| 4014 | ||
| 4015 | L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば | |
| 4016 | L<C<%INC>|perlvar/%INC> を更新します。 | |
| 4017 | これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。 | |
| 4018 | 特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を | |
| 4019 | 含んでいたのでこの二つの場合は等価でしたが、 | |
| 4020 | perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を | |
| 4021 | 含んでいないので、もはやそうではないことに注意してください。 | |
| 4022 | 代わりに、perl は次のような警告を出します: | |
| 4023 | ||
| 4024 | do "stat.pl" failed, '.' is no longer in @INC; | |
| 4025 | did you mean do "./stat.pl"? | |
| 4026 | ||
| 4027 | =begin original | |
| 4028 | ||
| 4029 | If L<C<do>|/do EXPR> can read the file but cannot compile it, it | |
| 4030 | returns L<C<undef>|/undef EXPR> and sets an error message in | |
| 4031 | L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it | |
| 4032 | returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check | |
| 4033 | L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also | |
| 4034 | sets L<C<$!>|perlvar/$!>. If the file is successfully compiled, | |
| 4035 | L<C<do>|/do EXPR> returns the value of the last expression evaluated. | |
| 4036 | ||
| 4037 | =end original | |
| 4038 | ||
| 4039 | L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、 | |
| 4040 | L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを | |
| 4041 | 設定します。 | |
| 4042 | L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して | |
| 4043 | L<C<$!>|perlvar/$!> にエラーを設定します。 | |
| 4044 | コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、 | |
| 4045 | 常に L<C<$@>|perlvar/$@> を先にチェックします。 | |
| 4046 | ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の | |
| 4047 | 値を返します。 | |
| 4048 | ||
| 4049 | =begin original | |
| 4050 | ||
| 3416 | 4051 | Inclusion of library modules is better done with the |
| 3417 | C<use> and C<require> | |
| 4052 | L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION> | |
| 3418 | and raise an exception | |
| 4053 | operators, which also do automatic error checking and raise an exception | |
| 4054 | if there's a problem. | |
| 3419 | 4055 | |
| 3420 | 4056 | =end original |
| 3421 | 4057 | |
| 3422 | ライブラリモジュールのインクルードには、 | |
| 4058 | ライブラリモジュールのインクルードには、 | |
| 3423 | ||
| 4059 | L<C<use>|/use Module VERSION LIST> 演算子や | |
| 3424 | ||
| 4060 | L<C<require>|/require VERSION> 演算子を使った方がよいです; | |
| 4061 | これらは自動的にエラーをチェックして、問題があれば例外を発生させます。 | |
| 3425 | 4062 | |
| 3426 | 4063 | =begin original |
| 3427 | 4064 | |
| 3428 | You might like to use C<do> to read in a program | |
| 4065 | You might like to use L<C<do>|/do EXPR> to read in a program | |
| 3429 | file. Manual error checking can be done this way: | |
| 4066 | configuration file. Manual error checking can be done this way: | |
| 3430 | 4067 | |
| 3431 | 4068 | =end original |
| 3432 | 4069 | |
| 3433 | C<do> をプログラム設定ファイルを読み込むのに | |
| 4070 | L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに | |
| 4071 | 使いたいかもしれません。 | |
| 3434 | 4072 | 手動のエラーチェックは以下のようにして行えます: |
| 3435 | 4073 | |
| 3436 | # | |
| 4074 | # Read in config files: system first, then user. | |
| 4075 | # Beware of using relative pathnames here. | |
| 3437 | 4076 | for $file ("/share/prog/defaults.rc", |
| 3438 | 4077 | "$ENV{HOME}/.someprogrc") |
| 3439 | 4078 | { |
| 3440 | 4079 | unless ($return = do $file) { |
| 3441 | 4080 | warn "couldn't parse $file: $@" if $@; |
| 3442 | 4081 | warn "couldn't do $file: $!" unless defined $return; |
| 3443 | 4082 | warn "couldn't run $file" unless $return; |
| 3444 | 4083 | } |
| 3445 | 4084 | } |
| 3446 | 4085 | |
| 3447 | 4086 | =item dump LABEL |
| 3448 | 4087 | X<dump> X<core> X<undump> |
| 3449 | 4088 | |
| 3450 | 4089 | =item dump EXPR |
| 3451 | 4090 | |
| 3452 | 4091 | =item dump |
| 3453 | 4092 | |
| 3454 | 4093 | =for Pod::Functions create an immediate core dump |
| 3455 | 4094 | |
| 3456 | 4095 | =begin original |
| 3457 | 4096 | |
| 3458 | 4097 | This function causes an immediate core dump. See also the B<-u> |
| 3459 | command-line switch in L<perlrun>, which does the same thing. | |
| 4098 | command-line switch in L<perlrun|perlrun/-u>, which does the same thing. | |
| 3460 | 4099 | Primarily this is so that you can use the B<undump> program (not |
| 3461 | 4100 | supplied) to turn your core dump into an executable binary after |
| 3462 | 4101 | having initialized all your variables at the beginning of the |
| 3463 | 4102 | program. When the new binary is executed it will begin by executing |
| 3464 | a C<goto LABEL> (with all the restrictions that C<goto> | |
| 4103 | a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL> | |
| 4104 | suffers). | |
| 3465 | 4105 | Think of it as a goto with an intervening core dump and reincarnation. |
| 3466 | 4106 | If C<LABEL> is omitted, restarts the program from the top. The |
| 3467 | 4107 | C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be |
| 3468 | 4108 | computed at run time, being otherwise identical to C<dump LABEL>. |
| 3469 | 4109 | |
| 3470 | 4110 | =end original |
| 3471 | 4111 | |
| 3472 | 4112 | この関数は即座にコアダンプを行ないます。 |
| 3473 | 同様のことを行う | |
| 4113 | 同様のことを行う <perlrun|perlrun/-u> の B<-u> オプションも参照してください。 | |
| 3474 | 4114 | プログラムの先頭で、 |
| 3475 | 4115 | すべての変数を初期化したあとのコアダンプを B<undump> |
| 3476 | 4116 | プログラム(提供していません)を使って実行ファイルに返ることができます。 |
| 3477 | 4117 | この新しいバイナリが実行されると、C<goto LABEL> から始めます |
| 3478 | (C<goto> に関する制限はすべて適用されます)。 | |
| 4118 | (L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。 | |
| 3479 | 4119 | コアダンプをはさんで再生する goto と考えてください。 |
| 3480 | 4120 | C<LABEL> が省略されると、プログラムを先頭から再開します。 |
| 3481 | 4121 | Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される |
| 3482 | 4122 | 名前が使えます; その他は C<dump LABEL> と同一です。 |
| 3483 | 4123 | |
| 3484 | 4124 | =begin original |
| 3485 | 4125 | |
| 3486 | 4126 | B<WARNING>: Any files opened at the time of the dump will I<not> |
| 3487 | 4127 | be open any more when the program is reincarnated, with possible |
| 3488 | 4128 | resulting confusion by Perl. |
| 3489 | 4129 | |
| 3490 | 4130 | =end original |
| 3491 | 4131 | |
| 3492 | 4132 | B<警告>: dump 時点でオープンされていたファイルは、プログラムが |
| 3493 | 再生されたときには、もはやオープンされていません; Perl を | |
| 4133 | 再生されたときには、もはやオープンされて I<いません>; Perl を | |
| 3494 | あります。 | |
| 4134 | 混乱させる可能性があります。 | |
| 3495 | 4135 | |
| 3496 | 4136 | =begin original |
| 3497 | 4137 | |
| 3498 | 4138 | This function is now largely obsolete, mostly because it's very hard to |
| 3499 | convert a core file into an executable. | |
| 4139 | convert a core file into an executable. As of Perl 5.30, it must be invoked | |
| 3500 | ||
| 4140 | as C<CORE::dump()>. | |
| 3501 | typo. | |
| 3502 | 4141 | |
| 3503 | 4142 | =end original |
| 3504 | 4143 | |
| 3505 | 4144 | この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを |
| 3506 | 4145 | 実行形式に変換するのが非常に困難であることです。 |
| 3507 | これ | |
| 4146 | Perl 5.30 から、これは C<CORE::dump()> として起動しなければなりません。 | |
| 3508 | C<CORE::dump()> として起動するべき理由です。 | |
| 3509 | 4147 | |
| 3510 | 4148 | =begin original |
| 3511 | 4149 | |
| 3512 | 4150 | Unlike most named operators, this has the same precedence as assignment. |
| 3513 | 4151 | It is also exempt from the looks-like-a-function rule, so |
| 3514 | 4152 | C<dump ("foo")."bar"> will cause "bar" to be part of the argument to |
| 3515 | C<dump>. | |
| 4153 | L<C<dump>|/dump LABEL>. | |
| 3516 | 4154 | |
| 3517 | 4155 | =end original |
| 3518 | 4156 | |
| 3519 | 4157 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
| 3520 | 4158 | また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と |
| 3521 | すると "bar" は C<dump> への引数の一部になります。 | |
| 4159 | すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。 | |
| 3522 | 4160 | |
| 3523 | 4161 | =begin original |
| 3524 | 4162 | |
| 3525 | 4163 | Portability issues: L<perlport/dump>. |
| 3526 | 4164 | |
| 3527 | 4165 | =end original |
| 3528 | 4166 | |
| 3529 | 4167 | 移植性の問題: L<perlport/dump>。 |
| 3530 | 4168 | |
| 3531 | 4169 | =item each HASH |
| 3532 | 4170 | X<each> X<hash, iterator> |
| 3533 | 4171 | |
| 3534 | 4172 | =item each ARRAY |
| 3535 | 4173 | X<array, iterator> |
| 3536 | 4174 | |
| 3537 | =item each EXPR | |
| 3538 | ||
| 3539 | 4175 | =for Pod::Functions retrieve the next key/value pair from a hash |
| 3540 | 4176 | |
| 3541 | 4177 | =begin original |
| 3542 | 4178 | |
| 3543 | 4179 | When called on a hash in list context, returns a 2-element list |
| 3544 | 4180 | consisting of the key and value for the next element of a hash. In Perl |
| 3545 | 4181 | 5.12 and later only, it will also return the index and value for the next |
| 3546 | 4182 | element of an array so that you can iterate over it; older Perls consider |
| 3547 | 4183 | this a syntax error. When called in scalar context, returns only the key |
| 3548 | 4184 | (not the value) in a hash, or the index in an array. |
| 3549 | 4185 | |
| 3550 | 4186 | =end original |
| 3551 | 4187 | |
| 3552 | 4188 | ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、 |
| 3553 | 4189 | ハッシュのキーと値を返します。 |
| 3554 | 4190 | Perl 5.12 以降でのみ、配列のインデックスと値からなる |
| 3555 | 4191 | 2 要素のリストを返すので、反復を行えます; より古い Perl ではこれは |
| 3556 | 4192 | 文法エラーと考えられます。 |
| 3557 | 4193 | スカラコンテキストで呼び出した場合は、 |
| 3558 | 4194 | ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。 |
| 3559 | 4195 | |
| 3560 | 4196 | =begin original |
| 3561 | 4197 | |
| 3562 | 4198 | Hash entries are returned in an apparently random order. The actual random |
| 3563 | 4199 | order is specific to a given hash; the exact same series of operations |
| 3564 | on two hashes may result in a different order for each hash. Any insertion | |
| 4200 | on two hashes may result in a different order for each hash. Any insertion | |
| 3565 | 4201 | into the hash may change the order, as will any deletion, with the exception |
| 3566 | that the most recent key returned by C<each> | |
| 4202 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 3567 | without changing the order. So | |
| 4203 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 3568 | ||
| 4204 | long as a given hash is unmodified you may rely on | |
| 3569 | ||
| 4205 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
| 3570 | ||
| 4206 | L<C<each>|/each HASH> to repeatedly return the same order | |
| 4207 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 4208 | details on why hash order is randomized. Aside from the guarantees | |
| 3571 | 4209 | provided here the exact details of Perl's hash algorithm and the hash |
| 3572 | 4210 | traversal order are subject to change in any release of Perl. |
| 3573 | 4211 | |
| 3574 | 4212 | =end original |
| 3575 | 4213 | |
| 3576 | 4214 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
| 3577 | 4215 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
| 3578 | 4216 | 操作を行っても、ハッシュによって異なった順序になります。 |
| 3579 | 4217 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
| 3580 | C<each> または C<keys> によって返されたもっとも | |
| 4218 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 3581 | 変えることなく削除できます。 | |
| 4219 | 最近のキーは順序を変えることなく削除できます。 | |
| 3582 | ハッシュが変更されない限り、C<keys>, C<values> | |
| 4220 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 3583 | 返すことに依存してもかまいません。 | |
| 4221 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 | |
| 3584 | 4222 | なぜハッシュの順序がランダム化されているかの詳細については |
| 3585 | 4223 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
| 3586 | 4224 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
| 3587 | 4225 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
| 3588 | 4226 | |
| 3589 | 4227 | =begin original |
| 3590 | 4228 | |
| 3591 | After C<each> has returned all entries from the hash or | |
| 4229 | After L<C<each>|/each HASH> has returned all entries from the hash or | |
| 3592 | call to C<each> returns the empty list | |
| 4230 | array, the next call to L<C<each>|/each HASH> returns the empty list in | |
| 3593 | ||
| 4231 | list context and L<C<undef>|/undef EXPR> in scalar context; the next | |
| 3594 | ||
| 4232 | call following I<that> one restarts iteration. Each hash or array has | |
| 3595 | ||
| 4233 | its own internal iterator, accessed by L<C<each>|/each HASH>, | |
| 3596 | ||
| 4234 | L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is | |
| 3597 | ||
| 4235 | implicitly reset when L<C<each>|/each HASH> has reached the end as just | |
| 3598 | e | |
| 4236 | described; it can be explicitly reset by calling L<C<keys>|/keys HASH> | |
| 3599 | ||
| 4237 | or L<C<values>|/values HASH> on the hash or array, or by referencing | |
| 3600 | t | |
| 4238 | the hash (but not array) in list context. If you add or delete | |
| 3601 | ||
| 4239 | a hash's elements while iterating over it, the effect on the iterator is | |
| 4240 | unspecified; for example, entries may be skipped or duplicated--so don't | |
| 4241 | do that. Exception: It is always safe to delete the item most recently | |
| 4242 | returned by L<C<each>|/each HASH>, so the following code works properly: | |
| 3602 | 4243 | |
| 3603 | 4244 | =end original |
| 3604 | 4245 | |
| 3605 | C<each> がハッシュをすべて読み込んでしまった後、 | |
| 4246 | L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、 | |
| 3606 | ||
| 4247 | 次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが | |
| 4248 | 返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます; | |
| 3607 | 4249 | I<そのあと> もう一度呼び出すと、再び反復を始めます。 |
| 3608 | ハッシュや配列毎にそれぞれ反復子があり、C<each> | |
| 4250 | ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、 | |
| 3609 | アクセスされます。 | |
| 4251 | L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。 | |
| 3610 | 反復子は、前述したように C<each> が要素をすべて読むことによって | |
| 4252 | 反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって | |
| 3611 | 暗黙にリセットされます; また、ハッシュや配列に対して | |
| 4253 | 暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>, | |
| 3612 | C< | |
| 4254 | L<C<values>|/values HASH> を呼び出すか、リストコンテキストで | |
| 4255 | (配列ではなく)ハッシュを参照ことで明示的にリセットできます。 | |
| 3613 | 4256 | 繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、 |
| 3614 | 要素が飛ばされたり重複したり | |
| 4257 | 反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします-- | |
| 3615 | ||
| 4258 | 従って、してはいけません。 | |
| 4259 | 例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に | |
| 3616 | 4260 | 安全です; これは以下のようなコードが正しく動くことを意味します: |
| 3617 | 4261 | |
| 3618 | | |
| 4262 | while (my ($key, $value) = each %hash) { | |
| 3619 | | |
| 4263 | print $key, "\n"; | |
| 3620 | | |
| 4264 | delete $hash{$key}; # This is safe | |
| 3621 | | |
| 4265 | } | |
| 3622 | 4266 | |
| 3623 | 4267 | =begin original |
| 3624 | 4268 | |
| 3625 | T | |
| 4269 | Tied hashes may have a different ordering behaviour to perl's hash | |
| 4270 | implementation. | |
| 4271 | ||
| 4272 | =end original | |
| 4273 | ||
| 4274 | tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。 | |
| 4275 | ||
| 4276 | =begin original | |
| 4277 | ||
| 4278 | The iterator used by C<each> is attached to the hash or array, and is | |
| 4279 | shared between all iteration operations applied to the same hash or array. | |
| 4280 | Thus all uses of C<each> on a single hash or array advance the same | |
| 4281 | iterator location. All uses of C<each> are also subject to having the | |
| 4282 | iterator reset by any use of C<keys> or C<values> on the same hash or | |
| 4283 | array, or by the hash (but not array) being referenced in list context. | |
| 4284 | This makes C<each>-based loops quite fragile: it is easy to arrive at | |
| 4285 | such a loop with the iterator already part way through the object, or to | |
| 4286 | accidentally clobber the iterator state during execution of the loop body. | |
| 4287 | It's easy enough to explicitly reset the iterator before starting a loop, | |
| 4288 | but there is no way to insulate the iterator state used by a loop from | |
| 4289 | the iterator state used by anything else that might execute during the | |
| 4290 | loop body. To avoid these problems, use a C<foreach> loop rather than | |
| 4291 | C<while>-C<each>. | |
| 4292 | ||
| 4293 | =end original | |
| 4294 | ||
| 4295 | C<each> で使われる反復子はハッシュや配列に付随し、 | |
| 4296 | 同じハッシュや配列に適用される全ての反復操作の間で共有されます。 | |
| 4297 | 従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を | |
| 4298 | 進めます。 | |
| 4299 | また、全ての C<each> は、同じハッシュまたはキーに対する | |
| 4300 | C<keys> や C<values> の使用によって、または | |
| 4301 | (リストではなく)ハッシュがリストコンテキストで参照されることによって、 | |
| 4302 | 反復子がリセットされることになります。 | |
| 4303 | これは、C<each> を基にしたループをかなり不安定にします: | |
| 4304 | そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、 | |
| 4305 | ループ本体の実行中に誤って反復子の状態を壊すことは容易です。 | |
| 4306 | ループを始める前に反復子を明示的にリセットするのは十分容易ですが、 | |
| 4307 | ループ本体の間に実行しているかもしれない他の何かによって使われている | |
| 4308 | 反復子の状態から、 | |
| 4309 | ループによって使われている反復子の状態を分離する方法はありません。 | |
| 4310 | これらの問題を避けるには、C<while>-C<each> ではなく | |
| 4311 | C<foreach> ループを使ってください。 | |
| 4312 | ||
| 4313 | =begin original | |
| 4314 | ||
| 4315 | This extends to using C<each> on the result of an anonymous hash or | |
| 4316 | array constructor. A new underlying array or hash is created each | |
| 4317 | time so each will always start iterating from scratch, eg: | |
| 4318 | ||
| 4319 | =end original | |
| 4320 | ||
| 4321 | これは、無名ハッシュや配列のコンストラクタの結果に | |
| 4322 | C<each> を使うように拡張します。 | |
| 4323 | 新しい基となる配列やハッシュは毎回作られるので、 | |
| 4324 | それぞれは常に最初から反復します; 例: | |
| 4325 | ||
| 4326 | # loops forever | |
| 4327 | while (my ($key, $value) = each @{ +{ a => 1 } }) { | |
| 4328 | print "$key=$value\n"; | |
| 4329 | } | |
| 4330 | ||
| 4331 | =begin original | |
| 4332 | ||
| 4333 | This prints out your environment like the L<printenv(1)> program, | |
| 3626 | 4334 | but in a different order: |
| 3627 | 4335 | |
| 3628 | 4336 | =end original |
| 3629 | 4337 | |
| 3630 | これは、printenv(1) プログラムのように環境変数を表示しますが、 | |
| 4338 | これは、L<printenv(1)> プログラムのように環境変数を表示しますが、 | |
| 3631 | 4339 | 順序は異なっています: |
| 3632 | 4340 | |
| 3633 | while (($key,$value) = each %ENV) { | |
| 4341 | while (my ($key,$value) = each %ENV) { | |
| 3634 | 4342 | print "$key=$value\n"; |
| 3635 | 4343 | } |
| 3636 | 4344 | |
| 3637 | 4345 | =begin original |
| 3638 | 4346 | |
| 3639 | Starting with Perl 5.14, | |
| 4347 | Starting with Perl 5.14, an experimental feature allowed | |
| 3640 | ||
| 4348 | L<C<each>|/each HASH> to take a scalar expression. This experiment has | |
| 3641 | ||
| 4349 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
| 3642 | The exact behaviour may change in a future version of Perl. | |
| 3643 | 4350 | |
| 3644 | 4351 | =end original |
| 3645 | 4352 | |
| 3646 | Perl 5.14 から、C<each> | |
| 4353 | Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来るという | |
| 3647 | ||
| 4354 | 実験的機能がありました。 | |
| 3648 | ||
| 4355 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 3649 | C<each> のこの動作は高度に実験的であると考えられています。 | |
| 3650 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 3651 | 4356 | |
| 3652 | while (($key,$value) = each $hashref) { ... } | |
| 3653 | ||
| 3654 | 4357 | =begin original |
| 3655 | 4358 | |
| 3656 | As of Perl 5.18 you can use a bare C<each> in a C<while> | |
| 4359 | As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while> | |
| 3657 | which will set C<$_> on every iteration. | |
| 4360 | loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
| 4361 | If either an C<each> expression or an explicit assignment of an C<each> | |
| 4362 | expression to a scalar is used as a C<while>/C<for> condition, then | |
| 4363 | the condition actually tests for definedness of the expression's value, | |
| 4364 | not for its regular truth value. | |
| 3658 | 4365 | |
| 3659 | 4366 | =end original |
| 3660 | 4367 | |
| 3661 | Perl 5.18 から C<while> ループの中に裸の C<each> を書けます; | |
| 4368 | Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます; | |
| 3662 | 繰り返し毎に C<$_> を設定します。 | |
| 4369 | これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。 | |
| 4370 | C<each> 式または C<each> 式からスカラへの明示的な代入が | |
| 4371 | C<while>/C<for> の条件部として使われた場合、 | |
| 4372 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 4373 | テストします。 | |
| 3663 | 4374 | |
| 3664 | while(each %ENV) { | |
| 4375 | while (each %ENV) { | |
| 3665 | 4376 | print "$_=$ENV{$_}\n"; |
| 3666 | 4377 | } |
| 3667 | 4378 | |
| 3668 | 4379 | =begin original |
| 3669 | 4380 | |
| 3670 | 4381 | To avoid confusing would-be users of your code who are running earlier |
| 3671 | 4382 | versions of Perl with mysterious syntax errors, put this sort of thing at |
| 3672 | 4383 | the top of your file to signal that your code will work I<only> on Perls of |
| 3673 | 4384 | a recent vintage: |
| 3674 | 4385 | |
| 3675 | 4386 | =end original |
| 3676 | 4387 | |
| 3677 | 4388 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
| 3678 | 4389 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
| 3679 | 4390 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
| 3680 | 4391 | 書いてください: |
| 3681 | 4392 | |
| 3682 | use 5. | |
| 4393 | use v5.12; # so keys/values/each work on arrays | |
| 3683 | use 5. | |
| 4394 | use v5.18; # so each assigns to $_ in a lone while test | |
| 3684 | use 5.018; # so each assigns to $_ in a lone while test | |
| 3685 | 4395 | |
| 3686 | 4396 | =begin original |
| 3687 | 4397 | |
| 3688 | See also C<keys>, C<values>, and | |
| 4398 | See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and | |
| 4399 | L<C<sort>|/sort SUBNAME LIST>. | |
| 3689 | 4400 | |
| 3690 | 4401 | =end original |
| 3691 | 4402 | |
| 3692 | C<keys> や C<values> | |
| 4403 | L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や | |
| 4404 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
| 3693 | 4405 | |
| 3694 | 4406 | =item eof FILEHANDLE |
| 3695 | 4407 | X<eof> |
| 3696 | 4408 | X<end of file> |
| 3697 | 4409 | X<end-of-file> |
| 3698 | 4410 | |
| 3699 | 4411 | =item eof () |
| 3700 | 4412 | |
| 3701 | 4413 | =item eof |
| 3702 | 4414 | |
| 3703 | 4415 | =for Pod::Functions test a filehandle for its end |
| 3704 | 4416 | |
| 3705 | 4417 | =begin original |
| 3706 | 4418 | |
| 3707 | 4419 | Returns 1 if the next read on FILEHANDLE will return end of file I<or> if |
| 3708 | 4420 | FILEHANDLE is not open. FILEHANDLE may be an expression whose value |
| 3709 | 4421 | gives the real filehandle. (Note that this function actually |
| 3710 | 4422 | reads a character and then C<ungetc>s it, so isn't useful in an |
| 3711 | 4423 | interactive context.) Do not read from a terminal file (or call |
| 3712 | 4424 | C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such |
| 3713 | 4425 | as terminals may lose the end-of-file condition if you do. |
| 3714 | 4426 | |
| 3715 | 4427 | =end original |
| 3716 | 4428 | |
| 3717 | 4429 | 次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 |
| 3718 | 4430 | I<または> FILEHANDLE がオープンされていないと、1 を返します。 |
| 3719 | 4431 | FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 |
| 3720 | 4432 | (この関数は、実際に文字を読み、C<ungetc> を行ないますので、 |
| 3721 | 4433 | 対話型の場合には有用ではありません。) |
| 3722 | 4434 | 端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を |
| 3723 | 4435 | 呼び出したりしてはいけません。 |
| 3724 | 4436 | そのようなことをすると、端末のようなファイルタイプは |
| 3725 | 4437 | EOF 状態を失ってしまうかもしれません。 |
| 3726 | 4438 | |
| 3727 | 4439 | =begin original |
| 3728 | 4440 | |
| 3729 | An C<eof> without an argument uses the last file | |
| 4441 | An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file | |
| 3730 | with empty parentheses is | |
| 4442 | read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is | |
| 3731 | f | |
| 4443 | different. It refers to the pseudo file formed from the files listed on | |
| 3732 | C<< <> >> operator. Since | |
| 4444 | the command line and accessed via the C<< <> >> operator. Since | |
| 3733 | as a normal filehandle is, a | |
| 4445 | C<< <> >> isn't explicitly opened, as a normal filehandle is, an | |
| 3734 | ||
| 4446 | L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause | |
| 3735 | ||
| 4447 | L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is | |
| 3736 | ||
| 4448 | available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >> | |
| 3737 | and | |
| 4449 | has returned end-of-file will assume you are processing another | |
| 3738 | ||
| 4450 | L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set | |
| 4451 | L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see | |
| 4452 | L<perlop/"I/O Operators">. | |
| 3739 | 4453 | |
| 3740 | 4454 | =end original |
| 3741 | 4455 | |
| 3742 | 引数を省略した C<eof> は、最後に読み込みを行なった | |
| 4456 | 引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった | |
| 3743 | ||
| 4457 | ファイルを使います。 | |
| 4458 | 空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。 | |
| 3744 | 4459 | これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で |
| 3745 | 4460 | アクセスされる擬似ファイルを示すために用いられます。 |
| 3746 | 4461 | 通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、 |
| 3747 | C<< <> >> を使う前に C<eof()> を使うと、 | |
| 4462 | C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、 | |
| 3748 | 入力が正常か確認するために C<@ARGV> がテストされます。 | |
| 4463 | 入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。 | |
| 3749 | 同様に、C<< <> >> が EOF を返した後の C<eof()> は、 | |
| 4464 | 同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、 | |
| 3750 | 他の C<@ARGV> リストを処理していると仮定し、もし | |
| 4465 | 他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし | |
| 3751 | セットしていないときは C<STDIN> から読み込みます; | |
| 4466 | L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます; | |
| 3752 | 4467 | L<perlop/"I/O Operators"> を参照してください。 |
| 3753 | 4468 | |
| 3754 | 4469 | =begin original |
| 3755 | 4470 | |
| 3756 | In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> | |
| 4471 | In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)> | |
| 3757 | detect the end of each file, whereas | |
| 4472 | can be used to detect the end of each file, whereas | |
| 3758 | of the very last file | |
| 4473 | L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file | |
| 4474 | only. Examples: | |
| 3759 | 4475 | |
| 3760 | 4476 | =end original |
| 3761 | 4477 | |
| 3762 | 4478 | C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、 |
| 3763 | C<eof> か C<eof(ARGV)> を用いるのに対して | |
| 4479 | L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して | |
| 3764 | C<eof()> は最後のファイルの終わりのみを調べます。 | |
| 4480 | L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。 | |
| 3765 | 4481 | 例: |
| 3766 | 4482 | |
| 3767 | 4483 | # reset line numbering on each input file |
| 3768 | 4484 | while (<>) { |
| 3769 | 4485 | next if /^\s*#/; # skip comments |
| 3770 | 4486 | print "$.\t$_"; |
| 3771 | 4487 | } continue { |
| 3772 | 4488 | close ARGV if eof; # Not eof()! |
| 3773 | 4489 | } |
| 3774 | 4490 | |
| 3775 | 4491 | # insert dashes just before last line of last file |
| 3776 | 4492 | while (<>) { |
| 3777 | 4493 | if (eof()) { # check for end of last file |
| 3778 | 4494 | print "--------------\n"; |
| 3779 | 4495 | } |
| 3780 | 4496 | print; |
| 3781 | 4497 | last if eof(); # needed if we're reading from a terminal |
| 3782 | 4498 | } |
| 3783 | 4499 | |
| 3784 | 4500 | =begin original |
| 3785 | 4501 | |
| 3786 | Practical hint: you almost never need to use C<eof> | |
| 4502 | Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE> | |
| 3787 | input operators typically return C<undef> | |
| 4503 | in Perl, because the input operators typically return L<C<undef>|/undef | |
| 3788 | encounter an error. | |
| 4504 | EXPR> when they run out of data or encounter an error. | |
| 3789 | 4505 | |
| 3790 | 4506 | =end original |
| 3791 | 4507 | |
| 3792 | 現実的なヒント: Perl で C<eof> が必要となることは、 | |
| 4508 | 現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、 | |
| 4509 | ほとんどありません; | |
| 3793 | 4510 | 基本的には、データがなくなったときやエラーがあったときに、入力演算子が |
| 3794 | C<undef> を返してくれるからです。 | |
| 4511 | L<C<undef>|/undef EXPR> を返してくれるからです。 | |
| 3795 | 4512 | |
| 3796 | 4513 | =item eval EXPR |
| 3797 | 4514 | X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute> |
| 3798 | 4515 | X<error, handling> X<exception, handling> |
| 3799 | 4516 | |
| 3800 | 4517 | =item eval BLOCK |
| 3801 | 4518 | |
| 3802 | 4519 | =item eval |
| 3803 | 4520 | |
| 3804 | 4521 | =for Pod::Functions catch exceptions or compile and run code |
| 3805 | 4522 | |
| 3806 | 4523 | =begin original |
| 3807 | 4524 | |
| 3808 | ||
| 4525 | C<eval> in all its forms is used to execute a little Perl program, | |
| 3809 | ||
| 4526 | trapping any errors encountered so they don't crash the calling program. | |
| 3810 | determined within scalar context) is first parsed, and if there were no | |
| 3811 | errors, executed as a block within the lexical context of the current Perl | |
| 3812 | program. This means, that in particular, any outer lexical variables are | |
| 3813 | visible to it, and any package variable settings or subroutine and format | |
| 3814 | definitions remain afterwards. | |
| 3815 | 4527 | |
| 3816 | 4528 | =end original |
| 3817 | 4529 | |
| 3818 | ||
| 4530 | どの型式の C<eval> も、小さな Perl のプログラムであるかのように実行され、 | |
| 3819 | ||
| 4531 | 遭遇した全てのエラーをトラップするので、呼び出したプログラムが | |
| 3820 | ||
| 4532 | クラッシュすることはありません。 | |
| 3821 | エラーがなければ | |
| 3822 | Perl プログラムのレキシカルコンテキストの中のブロックとして実行されます。 | |
| 3823 | これは、特に、外側のレキシカル変数は見えていて、パッケージ変数の設定や | |
| 3824 | サブルーチンやフォーマットの定義はその後も残っているということです。 | |
| 3825 | 4533 | |
| 3826 | 4534 | =begin original |
| 3827 | 4535 | |
| 4536 | Plain C<eval> with no argument is just C<eval EXPR>, where the | |
| 4537 | expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus | |
| 4538 | there are only two real C<eval> forms; the one with an EXPR is often | |
| 4539 | called "string eval". In a string eval, the value of the expression | |
| 4540 | (which is itself determined within scalar context) is first parsed, and | |
| 4541 | if there were no errors, executed as a block within the lexical context | |
| 4542 | of the current Perl program. This form is typically used to delay | |
| 4543 | parsing and subsequent execution of the text of EXPR until run time. | |
| 3828 | 4544 | Note that the value is parsed every time the C<eval> executes. |
| 3829 | If EXPR is omitted, evaluates C<$_>. This form is typically used to | |
| 3830 | delay parsing and subsequent execution of the text of EXPR until run time. | |
| 3831 | 4545 | |
| 3832 | 4546 | =end original |
| 3833 | 4547 | |
| 3834 | ||
| 4548 | 引数なしの C<eval> は単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_> に | |
| 3835 | ||
| 4549 | 含まれているものとして考えられます。 | |
| 4550 | 従って実際には二つだけの C<eval> 形式があります: | |
| 4551 | EXPR のものはしばしば「文字列 eval」(string eval) と呼ばれます。 | |
| 4552 | 「文字列 eval」では、 | |
| 4553 | 式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、 | |
| 4554 | エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして | |
| 4555 | 実行されます。 | |
| 3836 | 4556 | この形は主に EXPR のテキストのパースと実行を実行時にまで |
| 3837 | 4557 | 遅延させるのに用います。 |
| 4558 | 返される値は C<eval> が実行されるごとにパースされることに注意してください。 | |
| 3838 | 4559 | |
| 3839 | 4560 | =begin original |
| 3840 | 4561 | |
| 3841 | ||
| 4562 | The other form is called "block eval". It is less general than string | |
| 3842 | ||
| 4563 | eval, but the code within the BLOCK is parsed only once (at the same | |
| 3843 | ||
| 4564 | time the code surrounding the C<eval> itself was parsed) and executed | |
| 3844 | ||
| 4565 | within the context of the current Perl program. This form is typically | |
| 3845 | ||
| 4566 | used to trap exceptions more efficiently than the first, while also | |
| 3846 | on the | |
| 4567 | providing the benefit of checking the code within BLOCK at compile time. | |
| 3847 | ||
| 4568 | BLOCK is parsed and compiled just once. Since errors are trapped, it | |
| 3848 | ||
| 4569 | often is used to check if a given feature is available. | |
| 3849 | always treats its input as a byte stream and works properly with source | |
| 3850 | filters, and the L<feature> pragma. | |
| 3851 | 4570 | |
| 3852 | 4571 | =end original |
| 3853 | 4572 | |
| 3854 | ||
| 4573 | もう一つの型式は「ブロック eval」と呼ばれます。 | |
| 3855 | ||
| 4574 | これは文字列 eval ほど一般的ではありませんが、 | |
| 3856 | ||
| 4575 | BLOCK 内部のコードは一度だけパースされ (コードを | |
| 3857 | C< | |
| 4576 | 囲む C<eval> 自身がパースされるのと同じ時点です) 現在の | |
| 3858 | ||
| 4577 | Perl プログラムのコンテキストで実行されます。 | |
| 3859 | ||
| 4578 | この形式は典型的には第一の形式より効率的に例外をトラップします; | |
| 3860 | ||
| 4579 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 | |
| 3861 | ||
| 4580 | BLOCK は一度だけパース及びコンパイルされます。 | |
| 3862 | ||
| 4581 | エラーはトラップされてるので、しばしば与えられた機能が利用可能かを | |
| 3863 | ||
| 4582 | チェックするために使われます。 | |
| 3864 | 4583 | |
| 3865 | 4584 | =begin original |
| 3866 | 4585 | |
| 3867 | In th | |
| 4586 | In both forms, the value returned is the value of the last expression | |
| 3868 | ||
| 4587 | evaluated inside the mini-program; a return statement may also be used, just | |
| 3869 | within | |
| 4588 | as with subroutines. The expression providing the return value is evaluated | |
| 3870 | ||
| 4589 | in void, scalar, or list context, depending on the context of the | |
| 3871 | al | |
| 4590 | C<eval> itself. See L<C<wantarray>|/wantarray> for more | |
| 3872 | time. | |
| 4591 | on how the evaluation context can be determined. | |
| 3873 | 4592 | |
| 3874 | 4593 | =end original |
| 3875 | 4594 | |
| 3876 | ||
| 4595 | どちらの形式でも、返される値はミニプログラムの内部で最後に評価された | |
| 3877 | ||
| 4596 | 表現の値です; サブルーチンと同様、return 文も使えます。 | |
| 3878 | コンテキスト | |
| 4597 | 返り値として提供される表現は、C<eval> 自身のコンテキストに | |
| 3879 | ||
| 4598 | 依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。 | |
| 3880 | ||
| 4599 | 評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を | |
| 4600 | 参照してください。 | |
| 3881 | 4601 | |
| 3882 | 4602 | =begin original |
| 3883 | 4603 | |
| 3884 | ||
| 4604 | If there is a syntax error or runtime error, or a L<C<die>|/die LIST> | |
| 3885 | t | |
| 4605 | statement is executed, C<eval> returns | |
| 4606 | L<C<undef>|/undef EXPR> in scalar context, or an empty list in list | |
| 4607 | context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to | |
| 4608 | 5.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list | |
| 4609 | context for syntax errors, but not for runtime errors.) If there was no | |
| 4610 | error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow | |
| 4611 | operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can | |
| 4612 | bypass the setting of L<C<$@>|perlvar/$@>. Beware that using | |
| 4613 | C<eval> neither silences Perl from printing warnings to | |
| 4614 | STDERR, nor does it stuff the text of warning messages into | |
| 4615 | L<C<$@>|perlvar/$@>. To do either of those, you have to use the | |
| 4616 | L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside | |
| 4617 | the BLOCK or EXPR using S<C<no warnings 'all'>>. See | |
| 4618 | L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>. | |
| 3886 | 4619 | |
| 3887 | 4620 | =end original |
| 3888 | 4621 | |
| 3889 | ||
| 4622 | 構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、 | |
| 4623 | C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、 | |
| 4624 | リストコンテキストでは空リストが設定され、 | |
| 4625 | L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。 | |
| 4626 | (5.16 以前では、バグによって、リストコンテキストで構文エラーの時には | |
| 4627 | L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には | |
| 4628 | 返していませんでした。) | |
| 4629 | エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。 | |
| 4630 | L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は | |
| 4631 | L<C<$@>|perlvar/$@> の設定を回避できます。 | |
| 4632 | C<eval> を、STDERR に警告メッセージを表示させない目的や、 | |
| 4633 | 警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。 | |
| 4634 | そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、 | |
| 4635 | S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を | |
| 4636 | オフにする必要があります。 | |
| 4637 | L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。 | |
| 3890 | 4638 | |
| 3891 | 4639 | =begin original |
| 3892 | 4640 | |
| 3893 | ||
| 4641 | Note that, because C<eval> traps otherwise-fatal errors, | |
| 3894 | ||
| 4642 | it is useful for determining whether a particular feature (such as | |
| 3895 | ||
| 4643 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or | |
| 3896 | in | |
| 4644 | L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also | |
| 3897 | ||
| 4645 | Perl's exception-trapping mechanism, where the L<C<die>|/die LIST> | |
| 3898 | ||
| 4646 | operator is used to raise exceptions. | |
| 3899 | 4647 | |
| 3900 | 4648 | =end original |
| 3901 | 4649 | |
| 3902 | ||
| 4650 | C<eval> は、致命的エラーとなるようなものを | |
| 3903 | ||
| 4651 | トラップすることができるので、 | |
| 3904 | ||
| 4652 | (L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や | |
| 3905 | ||
| 4653 | L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が | |
| 3906 | ||
| 4654 | 実装されているかを、 | |
| 4655 | 調べるために使うことができることに注意してください。 | |
| 4656 | L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、 | |
| 4657 | Perl の例外捕捉機能と捉えることもできます。 | |
| 3907 | 4658 | |
| 3908 | 4659 | =begin original |
| 3909 | 4660 | |
| 3910 | ||
| 4661 | Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before | |
| 3911 | ||
| 4662 | restoration | |
| 3912 | o | |
| 4663 | of localized variables, which means that for your code to run on older | |
| 3913 | ||
| 4664 | versions, a temporary is required if you want to mask some, but not all | |
| 3914 | ||
| 4665 | errors: | |
| 3915 | If there was no error, C<$@> is set to the empty string. A | |
| 3916 | control flow operator like C<last> or C<goto> can bypass the setting of | |
| 3917 | C<$@>. Beware that using C<eval> neither silences Perl from printing | |
| 3918 | warnings to STDERR, nor does it stuff the text of warning messages into C<$@>. | |
| 3919 | To do either of those, you have to use the C<$SIG{__WARN__}> facility, or | |
| 3920 | turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>. | |
| 3921 | See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>. | |
| 3922 | 4666 | |
| 3923 | 4667 | =end original |
| 3924 | 4668 | |
| 3925 | ||
| 4669 | Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の | |
| 3926 | ||
| 4670 | 復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの | |
| 3927 | ||
| 4671 | エラーをマスクしたい場合には一時変数が必要です: | |
| 3928 | (5.16 以前では、バグによって、リストコンテキストで構文エラーの時には | |
| 3929 | C<undef> を返していましたが、実行エラーの時には返していませんでした。) | |
| 3930 | エラーがなければ、C<$@> は空文字列に設定されます。 | |
| 3931 | C<last> や C<goto> のようなフロー制御演算子は C<$@> の設定を回避できます。 | |
| 3932 | C<eval> を、STDERR に警告メッセージを表示させない目的や、 | |
| 3933 | 警告メッセージを C<$@> に格納する目的では使わないでください。 | |
| 3934 | そのような用途では、C<$SIG{__WARN__}> 機能を使うか、 | |
| 3935 | S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を | |
| 3936 | オフにする必要があります。 | |
| 3937 | L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。 | |
| 3938 | 4672 | |
| 4673 | # alter $@ on nefarious repugnancy only | |
| 4674 | { | |
| 4675 | my $e; | |
| 4676 | { | |
| 4677 | local $@; # protect existing $@ | |
| 4678 | eval { test_repugnancy() }; | |
| 4679 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
| 4680 | $@ =~ /nefarious/ and $e = $@; | |
| 4681 | } | |
| 4682 | die $e if defined $e | |
| 4683 | } | |
| 4684 | ||
| 3939 | 4685 | =begin original |
| 3940 | 4686 | |
| 3941 | ||
| 4687 | There are some different considerations for each form: | |
| 3942 | determining whether a particular feature (such as C<socket> or C<symlink>) | |
| 3943 | is implemented. It is also Perl's exception-trapping mechanism, where | |
| 3944 | the die operator is used to raise exceptions. | |
| 3945 | 4688 | |
| 3946 | 4689 | =end original |
| 3947 | 4690 | |
| 3948 | ||
| 4691 | それぞれの型式について、異なった考慮事項があります: | |
| 3949 | (C<socket> や C<symlink> といった) 特定の機能が実装されているかを、 | |
| 3950 | 調べるために使うことができることに注意してください。 | |
| 3951 | die 演算子が例外を発生させるものとすれば、これはまた、Perl の例外捕捉機能と | |
| 3952 | 捉えることもできます。 | |
| 3953 | 4692 | |
| 4693 | =over 4 | |
| 4694 | ||
| 4695 | =item String eval | |
| 4696 | ||
| 4697 | (文字列 eval) | |
| 4698 | ||
| 3954 | 4699 | =begin original |
| 3955 | 4700 | |
| 3956 | ||
| 4701 | Since the return value of EXPR is executed as a block within the lexical | |
| 3957 | t | |
| 4702 | context of the current Perl program, any outer lexical variables are | |
| 3958 | ||
| 4703 | visible to it, and any package variable settings or subroutine and | |
| 4704 | format definitions remain afterwards. | |
| 3959 | 4705 | |
| 3960 | 4706 | =end original |
| 3961 | 4707 | |
| 3962 | X | |
| 4708 | EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で | |
| 3963 | ||
| 4709 | 実行されるので、外側のレキシカルスコープはそこから見え、 | |
| 3964 | ||
| 4710 | パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。 | |
| 3965 | 致命的エラーになるかもしれません。 | |
| 3966 | L<perlrun> を参照してください。 | |
| 3967 | 4711 | |
| 3968 | 4712 | =begin original |
| 3969 | 4713 | |
| 3970 | ||
| 4714 | Note that when C<BEGIN {}> blocks are embedded inside of an eval block | |
| 3971 | ||
| 4715 | the contents of the block will be executed immediately and before the rest | |
| 3972 | ||
| 4716 | of the eval code is executed. You can disable this entirely by | |
| 3973 | Examples: | |
| 3974 | 4717 | |
| 3975 | 4718 | =end original |
| 3976 | 4719 | |
| 3977 | ||
| 4720 | Note that when C<BEGIN {}> blocks are embedded inside of an eval block | |
| 3978 | ||
| 4721 | the contents of the block will be executed immediately and before the rest | |
| 3979 | eval | |
| 4722 | of the eval code is executed. You can disable this entirely by | |
| 3980 | ||
| 4723 | (TBT) | |
| 3981 | 例: | |
| 3982 | 4724 | |
| 3983 | | |
| 4725 | local ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} = 0; | |
| 3984 | | |
| 4726 | eval $string; | |
| 3985 | 4727 | |
| 3986 | ||
| 4728 | =begin original | |
| 3987 | eval '$answer = $a / $b'; warn $@ if $@; | |
| 3988 | 4729 | |
| 3989 | | |
| 4730 | which will cause any embedded C<BEGIN> blocks in C<$string> to throw an | |
| 3990 | ||
| 4731 | exception. | |
| 3991 | 4732 | |
| 3992 | ||
| 4733 | =end original | |
| 3993 | eval '$answer ='; # sets $@ | |
| 3994 | 4734 | |
| 4735 | which will cause any embedded C<BEGIN> blocks in C<$string> to throw an | |
| 4736 | exception. | |
| 4737 | (TBT) | |
| 4738 | ||
| 4739 | =over 4 | |
| 4740 | ||
| 4741 | =item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 4742 | ||
| 3995 | 4743 | =begin original |
| 3996 | 4744 | |
| 3997 | ||
| 4745 | If this feature is enabled (which is the default under a C<use 5.16> or | |
| 3998 | i | |
| 4746 | higher declaration), Perl assumes that EXPR is a character string. | |
| 3999 | ||
| 4747 | Any S<C<use utf8>> or S<C<no utf8>> declarations within | |
| 4000 | ||
| 4748 | the string thus have no effect. Source filters are forbidden as well. | |
| 4001 | ||
| 4749 | (C<unicode_strings>, however, can appear within the string.) | |
| 4002 | 4750 | |
| 4003 | 4751 | =end original |
| 4004 | 4752 | |
| 4005 | C<e | |
| 4753 | この機能が有効の場合(これは C<use 5.16> またはそれ以上が | |
| 4006 | ||
| 4754 | 宣言されている場合はデフォルトです)、 | |
| 4007 | ||
| 4755 | Perl は EXPR が文字の文字列であると仮定します。 | |
| 4008 | ||
| 4756 | 従って文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効です。 | |
| 4009 | ||
| 4757 | ソースフィルタも禁止されます。 | |
| 4758 | (しかし、C<unicode_strings> は文字列の中に現れます。) | |
| 4010 | 4759 | |
| 4011 | ||
| 4760 | =begin original | |
| 4012 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; | |
| 4013 | warn $@ if $@; | |
| 4014 | 4761 | |
| 4762 | See also the L<C<evalbytes>|/evalbytes EXPR> operator, which works properly | |
| 4763 | with source filters. | |
| 4764 | ||
| 4765 | =end original | |
| 4766 | ||
| 4767 | ソースフィルタが適切に動作する | |
| 4768 | L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。 | |
| 4769 | ||
| 4770 | =item Outside the C<"unicode_eval"> feature | |
| 4771 | ||
| 4015 | 4772 | =begin original |
| 4016 | 4773 | |
| 4017 | ||
| 4774 | In this case, the behavior is problematic and is not so easily | |
| 4018 | ||
| 4775 | described. Here are two bugs that cannot easily be fixed without | |
| 4776 | breaking existing programs: | |
| 4019 | 4777 | |
| 4020 | 4778 | =end original |
| 4021 | 4779 | |
| 4022 | こ | |
| 4780 | この場合、振る舞いには問題があり、それほど簡単には説明できません。 | |
| 4023 | ||
| 4781 | 既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります: | |
| 4024 | 4782 | |
| 4025 | ||
| 4783 | =over 4 | |
| 4026 | { | |
| 4027 | local $SIG{'__DIE__'} = | |
| 4028 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; | |
| 4029 | eval { die "foo lives here" }; | |
| 4030 | print $@ if $@; # prints "bar lives here" | |
| 4031 | } | |
| 4032 | 4784 | |
| 4785 | =item * | |
| 4786 | ||
| 4033 | 4787 | =begin original |
| 4034 | 4788 | |
| 4035 | ||
| 4789 | Perl's internal storage of EXPR affects the behavior of the executed code. | |
| 4036 | ||
| 4790 | For example: | |
| 4037 | 4791 | |
| 4038 | 4792 | =end original |
| 4039 | 4793 | |
| 4040 | ||
| 4794 | Perl's internal storage of | |
| 4041 | ||
| 4795 | EXPR の Perl の内部ストーレージは実行されるコードの振る舞いに影響を与えます。 | |
| 4796 | 例えば: | |
| 4042 | 4797 | |
| 4798 | my $v = eval "use utf8; '$expr'"; | |
| 4799 | ||
| 4043 | 4800 | =begin original |
| 4044 | 4801 | |
| 4045 | ||
| 4802 | If $expr is C<"\xc4\x80"> (U+0100 in UTF-8), then the value stored in C<$v> | |
| 4046 | ||
| 4803 | will depend on whether Perl stores $expr "upgraded" (cf. L<utf8>) or | |
| 4804 | not: | |
| 4047 | 4805 | |
| 4048 | 4806 | =end original |
| 4049 | 4807 | |
| 4050 | C< | |
| 4808 | $expr が C<"\xc4\x80"> (U+0100 in UTF-8) の場合、C<$v> に保管される値は、 | |
| 4051 | ||
| 4809 | Perl が $expr を「昇格」(L<utf8> 参照)して保管するかどうかによります: | |
| 4052 | 4810 | |
| 4811 | =over | |
| 4812 | ||
| 4813 | =item * If upgraded, C<$v> will be C<"\xc4\x80"> (i.e., the | |
| 4814 | C<use utf8> has no effect.) | |
| 4815 | ||
| 4816 | (昇格されると、C<$v> will be C<"\xc4\x80"> になります (つまり、C<use utf8> は無効です。)) | |
| 4817 | ||
| 4818 | =item * If non-upgraded, C<$v> will be C<"\x{100}">. | |
| 4819 | ||
| 4820 | (昇格されないと、C<$v> は C<"\x{100}">です。) | |
| 4821 | ||
| 4822 | =back | |
| 4823 | ||
| 4824 | This is undesirable since being | |
| 4825 | upgraded or not should not affect a string's behavior. | |
| 4826 | ||
| 4827 | =item * | |
| 4828 | ||
| 4829 | =begin original | |
| 4830 | ||
| 4831 | Source filters activated within C<eval> leak out into whichever file | |
| 4832 | scope is currently being compiled. To give an example with the CPAN module | |
| 4833 | L<Semi::Semicolons>: | |
| 4834 | ||
| 4835 | =end original | |
| 4836 | ||
| 4837 | C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで | |
| 4838 | コンパイルされているかをリークさせます。 | |
| 4839 | CPAN モジュール L<Semi::Semicolons> を使った例は: | |
| 4840 | ||
| 4841 | BEGIN { eval "use Semi::Semicolons; # not filtered" } | |
| 4842 | # filtered here! | |
| 4843 | ||
| 4844 | =begin original | |
| 4845 | ||
| 4846 | L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would | |
| 4847 | expect: | |
| 4848 | ||
| 4849 | =end original | |
| 4850 | ||
| 4851 | L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように | |
| 4852 | これを修正します: | |
| 4853 | ||
| 4854 | use feature "evalbytes"; | |
| 4855 | BEGIN { evalbytes "use Semi::Semicolons; # filtered" } | |
| 4856 | # not filtered | |
| 4857 | ||
| 4858 | =back | |
| 4859 | ||
| 4860 | =back | |
| 4861 | ||
| 4862 | =begin original | |
| 4863 | ||
| 4864 | Problems can arise if the string expands a scalar containing a floating | |
| 4865 | point number. That scalar can expand to letters, such as C<"NaN"> or | |
| 4866 | C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the | |
| 4867 | decimal point character may be something other than a dot (such as a | |
| 4868 | comma). None of these are likely to parse as you are likely expecting. | |
| 4869 | ||
| 4870 | =end original | |
| 4871 | ||
| 4872 | 文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。 | |
| 4873 | そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に | |
| 4874 | 展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、 | |
| 4875 | 小数点文字は (カンマのような) ドット以外の文字かもしれません。 | |
| 4876 | これらはどれもあなたがおそらく予測しているようにはパースされません。 | |
| 4877 | ||
| 4878 | =begin original | |
| 4879 | ||
| 4880 | You should be especially careful to remember what's being looked at | |
| 4881 | when: | |
| 4882 | ||
| 4883 | =end original | |
| 4884 | ||
| 4885 | 以下のような場合に、何が調べられるかに特に注意しておくことが必要です: | |
| 4886 | ||
| 4053 | 4887 | eval $x; # CASE 1 |
| 4054 | 4888 | eval "$x"; # CASE 2 |
| 4055 | 4889 | |
| 4056 | 4890 | eval '$x'; # CASE 3 |
| 4057 | 4891 | eval { $x }; # CASE 4 |
| 4058 | 4892 | |
| 4059 | 4893 | eval "\$$x++"; # CASE 5 |
| 4060 | 4894 | $$x++; # CASE 6 |
| 4061 | 4895 | |
| 4062 | 4896 | =begin original |
| 4063 | 4897 | |
| 4064 | 4898 | Cases 1 and 2 above behave identically: they run the code contained in |
| 4065 | 4899 | the variable $x. (Although case 2 has misleading double quotes making |
| 4066 | 4900 | the reader wonder what else might be happening (nothing is).) Cases 3 |
| 4067 | 4901 | and 4 likewise behave in the same way: they run the code C<'$x'>, which |
| 4068 | 4902 | does nothing but return the value of $x. (Case 4 is preferred for |
| 4069 | 4903 | purely visual reasons, but it also has the advantage of compiling at |
| 4070 | 4904 | compile-time instead of at run-time.) Case 5 is a place where |
| 4071 | 4905 | normally you I<would> like to use double quotes, except that in this |
| 4072 | 4906 | particular situation, you can just use symbolic references instead, as |
| 4073 | 4907 | in case 6. |
| 4074 | 4908 | |
| 4075 | 4909 | =end original |
| 4076 | 4910 | |
| 4077 | 4911 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の |
| 4078 | 4912 | コードを実行します。 |
| 4079 | 4913 | (ただし、CASE 2 では、必要のないダブルクォートによって、 |
| 4080 | 4914 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) |
| 4081 | 4915 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に |
| 4082 | 何もしない C<$x> というコードを実行します | |
| 4916 | 何もしない C<$x> というコードを実行します。 | |
| 4083 | 4917 | (純粋に見た目の問題で、CASE 4 が好まれますが、 |
| 4084 | 4918 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 |
| 4085 | CASE 5 の場合は、通常ダブルクォートを使用します | |
| 4919 | CASE 5 の場合は、通常ダブルクォートを使用 I<します>; | |
| 4086 | 4920 | この状況を除けば、CASE 6 のように、単に |
| 4087 | 4921 | シンボリックリファレンスを使えば良いでしょう。 |
| 4088 | 4922 | |
| 4089 | 4923 | =begin original |
| 4090 | 4924 | |
| 4091 | ||
| 4925 | An C<eval ''> executed within a subroutine defined | |
| 4092 | ||
| 4926 | in the C<DB> package doesn't see the usual | |
| 4093 | ||
| 4927 | surrounding lexical scope, but rather the scope of the first non-DB piece | |
| 4094 | er | |
| 4928 | of code that called it. You don't normally need to worry about this unless | |
| 4929 | you are writing a Perl debugger. | |
| 4095 | 4930 | |
| 4096 | 4931 | =end original |
| 4097 | 4932 | |
| 4098 | ||
| 4933 | C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の | |
| 4099 | ||
| 4934 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の | |
| 4100 | ||
| 4935 | スコープになります。 | |
| 4936 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は | |
| 4937 | ありません。 | |
| 4101 | 4938 | |
| 4102 | ||
| 4939 | =begin original | |
| 4940 | ||
| 4941 | The final semicolon, if any, may be omitted from the value of EXPR. | |
| 4942 | ||
| 4943 | =end original | |
| 4944 | ||
| 4945 | 最後のセミコロンは、もしあれば、EXPR の値から省くことができます。 | |
| 4946 | ||
| 4947 | =item Block eval | |
| 4948 | ||
| 4949 | =begin original | |
| 4950 | ||
| 4951 | If the code to be executed doesn't vary, you may use the eval-BLOCK | |
| 4952 | form to trap run-time errors without incurring the penalty of | |
| 4953 | recompiling each time. The error, if any, is still returned in | |
| 4954 | L<C<$@>|perlvar/$@>. | |
| 4955 | Examples: | |
| 4956 | ||
| 4957 | =end original | |
| 4958 | ||
| 4959 | 実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、 | |
| 4960 | 実行時エラーのトラップを行なうために、 | |
| 4961 | eval-BLOCK 形式を使うことができます。 | |
| 4962 | エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。 | |
| 4963 | 例: | |
| 4964 | ||
| 4965 | # make divide-by-zero nonfatal | |
| 4966 | eval { $answer = $a / $b; }; warn $@ if $@; | |
| 4967 | ||
| 4968 | # same thing, but less efficient | |
| 4969 | eval '$answer = $a / $b'; warn $@ if $@; | |
| 4970 | ||
| 4971 | # a compile-time error | |
| 4972 | eval { $answer = }; # WRONG | |
| 4973 | ||
| 4974 | # a run-time error | |
| 4975 | eval '$answer ='; # sets $@ | |
| 4976 | ||
| 4977 | =begin original | |
| 4978 | ||
| 4979 | If you want to trap errors when loading an XS module, some problems with | |
| 4980 | the binary interface (such as Perl version skew) may be fatal even with | |
| 4981 | C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See | |
| 4982 | L<perlrun|perlrun/PERL_DL_NONLAZY>. | |
| 4983 | ||
| 4984 | =end original | |
| 4985 | ||
| 4986 | XS モジュールのロード中のエラーをトラップしたいなら、 | |
| 4987 | (Perl バージョンの違いのような) バイナリインターフェースに関する問題に | |
| 4988 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない | |
| 4989 | C<eval> でも致命的エラーになるかもしれません。 | |
| 4990 | L<perlrun|perlrun/PERL_DL_NONLAZY> を参照してください。 | |
| 4991 | ||
| 4992 | =begin original | |
| 4993 | ||
| 4994 | Using the C<eval {}> form as an exception trap in libraries does have some | |
| 4995 | issues. Due to the current arguably broken state of C<__DIE__> hooks, you | |
| 4996 | may wish not to trigger any C<__DIE__> hooks that user code may have installed. | |
| 4997 | You can use the C<local $SIG{__DIE__}> construct for this purpose, | |
| 4998 | as this example shows: | |
| 4999 | ||
| 5000 | =end original | |
| 5001 | ||
| 5002 | C<eval{}> 形式をライブラリの例外を捕捉するために使うときには | |
| 5003 | 問題があります。 | |
| 5004 | 現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、 | |
| 5005 | ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。 | |
| 5006 | この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。 | |
| 5007 | ||
| 5008 | # a private exception trap for divide-by-zero | |
| 5009 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; | |
| 5010 | warn $@ if $@; | |
| 5011 | ||
| 5012 | =begin original | |
| 5013 | ||
| 5014 | This is especially significant, given that C<__DIE__> hooks can call | |
| 5015 | L<C<die>|/die LIST> again, which has the effect of changing their error | |
| 5016 | messages: | |
| 5017 | ||
| 5018 | =end original | |
| 5019 | ||
| 5020 | これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を | |
| 5021 | もう一度呼び出すことができ、これによってエラーメッセージを変える | |
| 5022 | 効果があります: | |
| 5023 | ||
| 5024 | # __DIE__ hooks may modify error messages | |
| 4103 | 5025 | { |
| 4104 | | |
| 5026 | local $SIG{'__DIE__'} = | |
| 4105 | { | |
| 5027 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; | |
| 4106 | | |
| 5028 | eval { die "foo lives here" }; | |
| 4107 | | |
| 5029 | print $@ if $@; # prints "bar lives here" | |
| 4108 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
| 4109 | $@ =~ /nefarious/ and $e = $@; | |
| 4110 | } | |
| 4111 | die $e if defined $e | |
| 4112 | 5030 | } |
| 4113 | 5031 | |
| 4114 | 5032 | =begin original |
| 4115 | 5033 | |
| 5034 | Because this promotes action at a distance, this counterintuitive behavior | |
| 5035 | may be fixed in a future release. | |
| 5036 | ||
| 5037 | =end original | |
| 5038 | ||
| 5039 | これは距離の離れた行動であるため、この直感的でない振る舞いは | |
| 5040 | 将来のリリースでは修正されるかもしれません。 | |
| 5041 | ||
| 5042 | =begin original | |
| 5043 | ||
| 4116 | 5044 | C<eval BLOCK> does I<not> count as a loop, so the loop control statements |
| 4117 | C<next> | |
| 5045 | L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or | |
| 5046 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
| 4118 | 5047 | |
| 4119 | 5048 | =end original |
| 4120 | 5049 | |
| 4121 | C<eval BLOCK> はループとして I<扱われません>; 従って、C<next> | |
| 5050 | C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>, | |
| 4122 | C<redo> といったループ制御文で | |
| 5051 | L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で | |
| 5052 | ブロックから離れたり再実行したりはできません。 | |
| 4123 | 5053 | |
| 4124 | 5054 | =begin original |
| 4125 | 5055 | |
| 4126 | ||
| 5056 | The final semicolon, if any, may be omitted from within the BLOCK. | |
| 4127 | in the C<DB> package doesn't see the usual | |
| 4128 | surrounding lexical scope, but rather the scope of the first non-DB piece | |
| 4129 | of code that called it. You don't normally need to worry about this unless | |
| 4130 | you are writing a Perl debugger. | |
| 4131 | 5057 | |
| 4132 | 5058 | =end original |
| 4133 | 5059 | |
| 4134 | ||
| 5060 | 最後のセミコロンは、もしあれば、BLOCK の中から削除されます。 | |
| 4135 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の | |
| 4136 | スコープになります。 | |
| 4137 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は | |
| 4138 | ありません。 | |
| 4139 | 5061 | |
| 5062 | =back | |
| 5063 | ||
| 4140 | 5064 | =item evalbytes EXPR |
| 4141 | 5065 | X<evalbytes> |
| 4142 | 5066 | |
| 4143 | 5067 | =item evalbytes |
| 4144 | 5068 | |
| 4145 | 5069 | =for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream |
| 4146 | 5070 | |
| 4147 | 5071 | =begin original |
| 4148 | 5072 | |
| 4149 | This function is | |
| 5073 | This function is similar to a L<string eval|/eval EXPR>, except it | |
| 4150 | parses its argument | |
| 5074 | always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted) | |
| 4151 | string contain | |
| 5075 | as a byte string. If the string contains any code points above 255, then | |
| 4152 | ||
| 5076 | it cannot be a byte string, and the C<evalbytes> will fail with the error | |
| 4153 | ||
| 5077 | stored in C<$@>. | |
| 4154 | 5078 | |
| 4155 | 5079 | =end original |
| 4156 | 5080 | |
| 4157 | この関数は文字列 | |
| 5081 | この関数は L<文字列 eval|/eval EXPR> に似ていますが、引数(EXPR が | |
| 4158 | C<$_>) を常にバイト単位のの文字列として | |
| 5082 | 省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として | |
| 4159 | ||
| 5083 | 扱います。 | |
| 5084 | 文字列に 255 を超える符号位置が含まれている場合、バイト単位文字列に | |
| 5085 | することができないので、 | |
| 5086 | C<evalbytes> は失敗し、エラーは C<$@> に保管されます。 | |
| 5087 | ||
| 5088 | =begin original | |
| 5089 | ||
| 5090 | C<use utf8> and C<no utf8> within the string have their usual effect. | |
| 5091 | ||
| 5092 | =end original | |
| 5093 | ||
| 5094 | 文字列中の C<use utf8> と C<no utf8> は通常の効果を持ちます。 | |
| 5095 | ||
| 5096 | =begin original | |
| 5097 | ||
| 5098 | Source filters activated within the evaluated code apply to the code | |
| 5099 | itself. | |
| 5100 | ||
| 5101 | =end original | |
| 5102 | ||
| 4160 | 5103 | eval されたコード内で有効になったソースフィルタはコード自体に適用されます。 |
| 4161 | 5104 | |
| 4162 | 5105 | =begin original |
| 4163 | 5106 | |
| 4164 | ||
| 5107 | L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To | |
| 4165 | ||
| 5108 | access it, you must say C<CORE::evalbytes>, but you can omit the | |
| 4166 | ||
| 5109 | C<CORE::> if the | |
| 5110 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 5111 | is enabled. This is enabled automatically with a C<use v5.16> (or | |
| 5112 | higher) declaration in the current scope. | |
| 4167 | 5113 | |
| 4168 | 5114 | =end original |
| 4169 | 5115 | |
| 4170 | ||
| 5116 | L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。 | |
| 4171 | ||
| 5117 | これにアクセスするには C<CORE::evalbytes> とする必要がありますが、 | |
| 4172 | ||
| 5118 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が | |
| 5119 | 有効なら C<CORE::> を省略できます。 | |
| 5120 | これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると | |
| 5121 | 自動的に有効になります。 | |
| 4173 | 5122 | |
| 4174 | 5123 | =item exec LIST |
| 4175 | 5124 | X<exec> X<execute> |
| 4176 | 5125 | |
| 4177 | 5126 | =item exec PROGRAM LIST |
| 4178 | 5127 | |
| 4179 | 5128 | =for Pod::Functions abandon this program to run another |
| 4180 | 5129 | |
| 4181 | 5130 | =begin original |
| 4182 | 5131 | |
| 4183 | The C<exec> function executes a system command I<and never | |
| 5132 | The L<C<exec>|/exec LIST> function executes a system command I<and never | |
| 4184 | use C<system> instead of C<exec> | |
| 5133 | returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST> | |
| 5134 | if you want it to return. It fails and | |
| 4185 | 5135 | returns false only if the command does not exist I<and> it is executed |
| 4186 | 5136 | directly instead of via your system's command shell (see below). |
| 4187 | 5137 | |
| 4188 | 5138 | =end original |
| 4189 | 5139 | |
| 4190 | C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>; | |
| 5140 | L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>; | |
| 4191 | 戻って欲しい場合には、C<exec>ではなく | |
| 5141 | 戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく | |
| 5142 | L<C<system>|/system LIST> 関数を使ってください。 | |
| 4192 | 5143 | コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく |
| 4193 | 5144 | 直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。 |
| 4194 | 5145 | |
| 4195 | 5146 | =begin original |
| 4196 | 5147 | |
| 4197 | Since it's a common mistake to use C<exec> instead of | |
| 5148 | Since it's a common mistake to use L<C<exec>|/exec LIST> instead of | |
| 4198 | warns you if C<exec> | |
| 5149 | L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is | |
| 4199 | ||
| 5150 | called in void context and if there is a following statement that isn't | |
| 4200 | ||
| 5151 | L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if | |
| 4201 | wi | |
| 5152 | L<warnings> are enabled--but you always do that, right?). If you | |
| 5153 | I<really> want to follow an L<C<exec>|/exec LIST> with some other | |
| 5154 | statement, you can use one of these styles to avoid the warning: | |
| 4202 | 5155 | |
| 4203 | 5156 | =end original |
| 4204 | 5157 | |
| 4205 | C<system> の代わりに C<exec> を使うという | |
| 5158 | L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという | |
| 4206 | C<exec> が無効コンテキストで | |
| 5159 | よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで | |
| 4207 | C< | |
| 5160 | 呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, | |
| 4208 | ||
| 5161 | L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が | |
| 4209 | ||
| 5162 | 有効の場合 -- でもいつもセットしてますよね?)。 | |
| 4210 | ||
| 5163 | もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の | |
| 5164 | どちらかのスタイルを使うことで警告を回避できます: | |
| 4211 | 5165 | |
| 4212 | 5166 | exec ('foo') or print STDERR "couldn't exec foo: $!"; |
| 4213 | 5167 | { exec ('foo') }; print STDERR "couldn't exec foo: $!"; |
| 4214 | 5168 | |
| 4215 | 5169 | =begin original |
| 4216 | 5170 | |
| 4217 | If there is more than one argument in LIST, | |
| 5171 | If there is more than one argument in LIST, this calls L<execvp(3)> with the | |
| 4218 | ||
| 5172 | arguments in LIST. If there is only one element in LIST, the argument is | |
| 4219 | ||
| 5173 | checked for shell metacharacters, and if there are any, the entire | |
| 4220 | ||
| 5174 | argument is passed to the system's command shell for parsing (this is | |
| 4221 | ||
| 5175 | C</bin/sh -c> on Unix platforms, but varies on other platforms). If | |
| 4222 | ||
| 5176 | there are no shell metacharacters in the argument, it is split into words | |
| 4223 | ||
| 5177 | and passed directly to C<execvp>, which is more efficient. Examples: | |
| 4224 | words and passed directly to C<execvp>, which is more efficient. | |
| 4225 | Examples: | |
| 4226 | 5178 | |
| 4227 | 5179 | =end original |
| 4228 | 5180 | |
| 4229 | LIST に複数の引数がある場合 | |
| 5181 | LIST に複数の引数がある場合は、LIST の引数を使って L<execvp(3)> を | |
| 4230 | ||
| 5182 | 呼び出します。 | |
| 4231 | ||
| 5183 | LIST に要素が一つのみの場合には、その引数からシェルのメタ文字をチェックし、 | |
| 4232 | ||
| 5184 | もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では | |
| 4233 | 引数全体をシステムのコマンドシェル(これはUnix では | |
| 4234 | 5185 | C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。 |
| 4235 | 5186 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
| 4236 | 5187 | 渡されます; この方がより効率的です。 |
| 4237 | 5188 | 例: |
| 4238 | 5189 | |
| 4239 | 5190 | exec '/bin/echo', 'Your arguments are: ', @ARGV; |
| 4240 | 5191 | exec "sort $outfile | uniq"; |
| 4241 | 5192 | |
| 4242 | 5193 | =begin original |
| 4243 | 5194 | |
| 4244 | 5195 | If you don't really want to execute the first argument, but want to lie |
| 4245 | 5196 | to the program you are executing about its own name, you can specify |
| 4246 | 5197 | the program you actually want to run as an "indirect object" (without a |
| 4247 | comma) in front of the LIST. (This always | |
| 5198 | comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always | |
| 4248 | LIST as a multivalued list, even if there | |
| 5199 | forces interpretation of the LIST as a multivalued list, even if there | |
| 4249 | the list.) Example: | |
| 5200 | is only a single scalar in the list.) Example: | |
| 4250 | 5201 | |
| 4251 | 5202 | =end original |
| 4252 | 5203 | |
| 4253 | 第一引数に指定するものを本当に実行したいが、実行する | |
| 5204 | 第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の | |
| 4254 | ||
| 5205 | 名前を教えたい場合には、C<exec PROGRAM LIST> のように、LIST の前に | |
| 4255 | 「間接オブジェクト」(コンマなし) として | |
| 5206 | 「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを | |
| 4256 | ||
| 5207 | 指定することができます。 | |
| 4257 | (これによって、LIST に単一のスカラしかなくても、複数 | |
| 5208 | (これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、 | |
| 4258 | ||
| 5209 | LIST の解釈を行ないます。) | |
| 4259 | 5210 | 例: |
| 4260 | 5211 | |
| 4261 | $shell = '/bin/csh'; | |
| 5212 | my $shell = '/bin/csh'; | |
| 4262 | 5213 | exec $shell '-sh'; # pretend it's a login shell |
| 4263 | 5214 | |
| 4264 | 5215 | =begin original |
| 4265 | 5216 | |
| 4266 | 5217 | or, more directly, |
| 4267 | 5218 | |
| 4268 | 5219 | =end original |
| 4269 | 5220 | |
| 4270 | 5221 | あるいは、より直接的に、 |
| 4271 | 5222 | |
| 4272 | 5223 | exec {'/bin/csh'} '-sh'; # pretend it's a login shell |
| 4273 | 5224 | |
| 4274 | 5225 | =begin original |
| 4275 | 5226 | |
| 4276 | 5227 | When the arguments get executed via the system shell, results are |
| 4277 | 5228 | subject to its quirks and capabilities. See L<perlop/"`STRING`"> |
| 4278 | 5229 | for details. |
| 4279 | 5230 | |
| 4280 | 5231 | =end original |
| 4281 | 5232 | |
| 4282 | 5233 | 引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって |
| 4283 | 5234 | 変わります。 |
| 4284 | 5235 | 詳細については L<perlop/"`STRING`"> を参照してください。 |
| 4285 | 5236 | |
| 4286 | 5237 | =begin original |
| 4287 | 5238 | |
| 4288 | Using an indirect object with C<exec> | |
| 5239 | Using an indirect object with L<C<exec>|/exec LIST> or | |
| 4289 | secure. This usage (which also | |
| 5240 | L<C<system>|/system LIST> is also more secure. This usage (which also | |
| 5241 | works fine with L<C<system>|/system LIST>) forces | |
| 4290 | 5242 | interpretation of the arguments as a multivalued list, even if the |
| 4291 | 5243 | list had just one argument. That way you're safe from the shell |
| 4292 | 5244 | expanding wildcards or splitting up words with whitespace in them. |
| 4293 | 5245 | |
| 4294 | 5246 | =end original |
| 4295 | 5247 | |
| 4296 | C<exec> や C<system> で間接オブジェクトを | |
| 5248 | L<C<exec>|/exec LIST> や L<C<system>|/system LIST> で間接オブジェクトを | |
| 4297 | ||
| 5249 | 使うのもより安全です。 | |
| 4298 | ||
| 5250 | この使い方(L<C<system>|/system LIST> でも同様にうまく動きます)は、たとえ | |
| 5251 | 引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを | |
| 5252 | 強制します。 | |
| 4299 | 5253 | この方法で、シェルによるワイルドカード展開や、空白による単語の分割から |
| 4300 | 5254 | 守られます。 |
| 4301 | 5255 | |
| 4302 | @args = ( "echo surprise" ); | |
| 5256 | my @args = ( "echo surprise" ); | |
| 4303 | 5257 | |
| 4304 | 5258 | exec @args; # subject to shell escapes |
| 4305 | 5259 | # if @args == 1 |
| 4306 | 5260 | exec { $args[0] } @args; # safe even with one-arg list |
| 4307 | 5261 | |
| 4308 | 5262 | =begin original |
| 4309 | 5263 | |
| 4310 | 5264 | The first version, the one without the indirect object, ran the I<echo> |
| 4311 | 5265 | program, passing it C<"surprise"> an argument. The second version didn't; |
| 4312 | 5266 | it tried to run a program named I<"echo surprise">, didn't find it, and set |
| 4313 | C<$?> to a non-zero value indicating failure. | |
| 5267 | L<C<$?>|perlvar/$?> to a non-zero value indicating failure. | |
| 4314 | 5268 | |
| 4315 | 5269 | =end original |
| 4316 | 5270 | |
| 4317 | 5271 | 間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、 |
| 4318 | 5272 | C<"surprise"> が引数として渡されます。 |
| 4319 | 5273 | 二つ目のバージョンでは違います; I<"echo surprise"> という名前の |
| 4320 | 5274 | プログラムを実行しようとして、見つからないので、失敗したことを示すために |
| 4321 | C<$?> に非 0 がセットされます。 | |
| 5275 | L<C<$?>|perlvar/$?> に非 0 がセットされます。 | |
| 4322 | 5276 | |
| 4323 | 5277 | =begin original |
| 4324 | 5278 | |
| 5279 | On Windows, only the C<exec PROGRAM LIST> indirect object syntax will | |
| 5280 | reliably avoid using the shell; C<exec LIST>, even with more than one | |
| 5281 | element, will fall back to the shell if the first spawn fails. | |
| 5282 | ||
| 5283 | =end original | |
| 5284 | ||
| 5285 | Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを | |
| 5286 | 使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が | |
| 5287 | あっても、最初の spawn が失敗したときにシェルに | |
| 5288 | フォールバックすることがあります。 | |
| 5289 | ||
| 5290 | =begin original | |
| 5291 | ||
| 4325 | 5292 | Perl attempts to flush all files opened for output before the exec, |
| 4326 | 5293 | but this may not be supported on some platforms (see L<perlport>). |
| 4327 | To be safe, you may need to set C<$ | |
| 5294 | To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> | |
| 4328 | call the C<autoflush | |
| 5295 | (C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of | |
| 4329 | to avoid lost | |
| 5296 | L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost | |
| 5297 | output. | |
| 4330 | 5298 | |
| 4331 | 5299 | =end original |
| 4332 | 5300 | |
| 4333 | ||
| 5301 | Perl は exec の前に出力用に開かれている全てのファイルを | |
| 4334 | 5302 | フラッシュしようとしますが、これに対応していないプラットフォームもあります |
| 4335 | 5303 | (L<perlport> を参照してください)。 |
| 4336 | 5304 | 安全のためには、出力が重複するのを避けるために、全てのオープンしている |
| 4337 | ハンドルに対して C<$ | |
| 5305 | ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> | |
| 4338 | ||
| 5306 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 | |
| 4339 | ||
| 5307 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを | |
| 5308 | 呼ぶ必要があるかもしれません。 | |
| 4340 | 5309 | |
| 4341 | 5310 | =begin original |
| 4342 | 5311 | |
| 4343 | Note that C<exec> will not call your C<END> blocks, nor | |
| 5312 | Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor | |
| 4344 | C<DESTROY> methods on your objects. | |
| 5313 | will it invoke C<DESTROY> methods on your objects. | |
| 4345 | 5314 | |
| 4346 | 5315 | =end original |
| 4347 | 5316 | |
| 4348 | C<exec> は C<END> ブロックや、オブジェクトの | |
| 5317 | L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの | |
| 4349 | 起動しないことに注意してください。 | |
| 5318 | C<DESTROY> メソッドを起動しないことに注意してください。 | |
| 4350 | 5319 | |
| 4351 | 5320 | =begin original |
| 4352 | 5321 | |
| 4353 | 5322 | Portability issues: L<perlport/exec>. |
| 4354 | 5323 | |
| 4355 | 5324 | =end original |
| 4356 | 5325 | |
| 4357 | 5326 | 移植性の問題: L<perlport/exec>。 |
| 4358 | 5327 | |
| 4359 | 5328 | =item exists EXPR |
| 4360 | 5329 | X<exists> X<autovivification> |
| 4361 | 5330 | |
| 4362 | 5331 | =for Pod::Functions test whether a hash key is present |
| 4363 | 5332 | |
| 4364 | 5333 | =begin original |
| 4365 | 5334 | |
| 4366 | 5335 | Given an expression that specifies an element of a hash, returns true if the |
| 4367 | 5336 | specified element in the hash has ever been initialized, even if the |
| 4368 | 5337 | corresponding value is undefined. |
| 4369 | 5338 | |
| 4370 | 5339 | =end original |
| 4371 | 5340 | |
| 4372 | 5341 | ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、 |
| 4373 | 5342 | たとえ対応する値が未定義でも真を返します。 |
| 4374 | 5343 | |
| 4375 | 5344 | print "Exists\n" if exists $hash{$key}; |
| 4376 | 5345 | print "Defined\n" if defined $hash{$key}; |
| 4377 | 5346 | print "True\n" if $hash{$key}; |
| 4378 | 5347 | |
| 4379 | 5348 | =begin original |
| 4380 | 5349 | |
| 4381 | 5350 | exists may also be called on array elements, but its behavior is much less |
| 4382 | obvious and is strongly tied to the use of L</delete> on | |
| 5351 | obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on | |
| 4383 | ||
| 5352 | arrays. | |
| 4384 | a future version of Perl. | |
| 4385 | 5353 | |
| 4386 | 5354 | =end original |
| 4387 | 5355 | |
| 4388 | 5356 | exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに |
| 4389 | 不明確で、配列に対する L</delete> の使用と強く | |
| 5357 | 不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く | |
| 4390 | ||
| 5358 | 結びついています。 | |
| 4391 | Perl では削除されるかもしれないことを B<注意してください> 。 | |
| 4392 | 5359 | |
| 5360 | =begin original | |
| 5361 | ||
| 5362 | B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is | |
| 5363 | strongly discouraged. The | |
| 5364 | notion of deleting or checking the existence of Perl array elements is not | |
| 5365 | conceptually coherent, and can lead to surprising behavior. | |
| 5366 | ||
| 5367 | =end original | |
| 5368 | ||
| 5369 | B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く | |
| 5370 | 非推奨です。 | |
| 5371 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
| 5372 | 驚くべき振る舞いを引き起こすことがあります。 | |
| 5373 | ||
| 4393 | 5374 | print "Exists\n" if exists $array[$index]; |
| 4394 | 5375 | print "Defined\n" if defined $array[$index]; |
| 4395 | 5376 | print "True\n" if $array[$index]; |
| 4396 | 5377 | |
| 4397 | 5378 | =begin original |
| 4398 | 5379 | |
| 4399 | 5380 | A hash or array element can be true only if it's defined and defined only if |
| 4400 | 5381 | it exists, but the reverse doesn't necessarily hold true. |
| 4401 | 5382 | |
| 4402 | 5383 | =end original |
| 4403 | 5384 | |
| 4404 | 5385 | ハッシュまたは配列要素は、定義されているときにのみ真となり、 |
| 4405 | 5386 | 存在しているときにのみ定義されますが、逆は必ずしも真ではありません。 |
| 4406 | 5387 | |
| 4407 | 5388 | =begin original |
| 4408 | 5389 | |
| 4409 | 5390 | Given an expression that specifies the name of a subroutine, |
| 4410 | 5391 | returns true if the specified subroutine has ever been declared, even |
| 4411 | 5392 | if it is undefined. Mentioning a subroutine name for exists or defined |
| 4412 | 5393 | does not count as declaring it. Note that a subroutine that does not |
| 4413 | 5394 | exist may still be callable: its package may have an C<AUTOLOAD> |
| 4414 | 5395 | method that makes it spring into existence the first time that it is |
| 4415 | 5396 | called; see L<perlsub>. |
| 4416 | 5397 | |
| 4417 | 5398 | =end original |
| 4418 | 5399 | |
| 4419 | 5400 | 引数としてサブルーチンの名前が指定された場合、 |
| 4420 | 5401 | 指定されたサブルーチンが宣言されていれば(たとえ未定義でも) |
| 4421 | 5402 | 真を返します。 |
| 4422 | 5403 | exists や defined のために言及されているサブルーチン名は |
| 4423 | 5404 | 宣言としてのカウントに入りません。 |
| 4424 | 5405 | 存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください: |
| 4425 | 5406 | パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に |
| 4426 | 5407 | 存在を作り出すかもしれません; L<perlsub> を参照してください。 |
| 4427 | 5408 | |
| 4428 | 5409 | print "Exists\n" if exists &subroutine; |
| 4429 | 5410 | print "Defined\n" if defined &subroutine; |
| 4430 | 5411 | |
| 4431 | 5412 | =begin original |
| 4432 | 5413 | |
| 4433 | 5414 | Note that the EXPR can be arbitrarily complicated as long as the final |
| 4434 | 5415 | operation is a hash or array key lookup or subroutine name: |
| 4435 | 5416 | |
| 4436 | 5417 | =end original |
| 4437 | 5418 | |
| 4438 | 最終的な操作がハッシュや配列の key による検索または | |
| 5419 | 最終的な操作がハッシュや配列の key による検索または | |
| 4439 | EXPR には任意の複雑な式を置くことができます: | |
| 5420 | サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます: | |
| 4440 | 5421 | |
| 4441 | 5422 | if (exists $ref->{A}->{B}->{$key}) { } |
| 4442 | 5423 | if (exists $hash{A}{B}{$key}) { } |
| 4443 | 5424 | |
| 4444 | 5425 | if (exists $ref->{A}->{B}->[$ix]) { } |
| 4445 | 5426 | if (exists $hash{A}{B}[$ix]) { } |
| 4446 | 5427 | |
| 4447 | 5428 | if (exists &{$ref->{A}{B}{$key}}) { } |
| 4448 | 5429 | |
| 4449 | 5430 | =begin original |
| 4450 | 5431 | |
| 4451 | 5432 | Although the most deeply nested array or hash element will not spring into |
| 4452 | 5433 | existence just because its existence was tested, any intervening ones will. |
| 4453 | 5434 | Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring |
| 4454 | into existence due to the existence test for the $key element above. | |
| 5435 | into existence due to the existence test for the C<$key> element above. | |
| 4455 | 5436 | This happens anywhere the arrow operator is used, including even here: |
| 4456 | 5437 | |
| 4457 | 5438 | =end original |
| 4458 | 5439 | |
| 4459 | 5440 | 最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは |
| 4460 | 5441 | 存在するようにはなりませんが、途中のものは存在するようになります。 |
| 4461 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の | |
| 5442 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key> の | |
| 4462 | 5443 | 存在をテストしたことによって存在するようになります。 |
| 4463 | 5444 | これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも |
| 4464 | 5445 | 起こります。 |
| 4465 | 5446 | |
| 4466 | 5447 | undef $ref; |
| 4467 | 5448 | if (exists $ref->{"Some key"}) { } |
| 4468 | 5449 | print $ref; # prints HASH(0x80d3d5c) |
| 4469 | 5450 | |
| 4470 | 5451 | =begin original |
| 4471 | 5452 | |
| 4472 | This surprising autovivification in what does not at first--or even | |
| 4473 | second--glance appear to be an lvalue context may be fixed in a future | |
| 4474 | release. | |
| 4475 | ||
| 4476 | =end original | |
| 4477 | ||
| 4478 | 一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの | |
| 4479 | 自動有効化は将来のリリースでは修正されるでしょう。 | |
| 4480 | ||
| 4481 | =begin original | |
| 4482 | ||
| 4483 | 5453 | Use of a subroutine call, rather than a subroutine name, as an argument |
| 4484 | to exists | |
| 5454 | to L<C<exists>|/exists EXPR> is an error. | |
| 4485 | 5455 | |
| 4486 | 5456 | =end original |
| 4487 | 5457 | |
| 4488 | exists | |
| 5458 | L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン | |
| 4489 | エラーになります。 | |
| 5459 | 呼び出しを使うと、エラーになります。 | |
| 4490 | 5460 | |
| 4491 | 5461 | exists ⊂ # OK |
| 4492 | 5462 | exists &sub(); # Error |
| 4493 | 5463 | |
| 4494 | 5464 | =item exit EXPR |
| 4495 | 5465 | X<exit> X<terminate> X<abort> |
| 4496 | 5466 | |
| 4497 | 5467 | =item exit |
| 4498 | 5468 | |
| 4499 | 5469 | =for Pod::Functions terminate this program |
| 4500 | 5470 | |
| 4501 | 5471 | =begin original |
| 4502 | 5472 | |
| 4503 | 5473 | Evaluates EXPR and exits immediately with that value. Example: |
| 4504 | 5474 | |
| 4505 | 5475 | =end original |
| 4506 | 5476 | |
| 4507 | 5477 | EXPR を評価し、即座にその値を持って終了します。 |
| 4508 | 5478 | 例: |
| 4509 | 5479 | |
| 4510 | $ans = <STDIN>; | |
| 5480 | my $ans = <STDIN>; | |
| 4511 | 5481 | exit 0 if $ans =~ /^[Xx]/; |
| 4512 | 5482 | |
| 4513 | 5483 | =begin original |
| 4514 | 5484 | |
| 4515 | See also C<die>. If EXPR is omitted, exits with C<0> | |
| 5485 | See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0> | |
| 5486 | status. The only | |
| 4516 | 5487 | universally recognized values for EXPR are C<0> for success and C<1> |
| 4517 | 5488 | for error; other values are subject to interpretation depending on the |
| 4518 | 5489 | environment in which the Perl program is running. For example, exiting |
| 4519 | 5490 | 69 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause |
| 4520 | 5491 | the mailer to return the item undelivered, but that's not true everywhere. |
| 4521 | 5492 | |
| 4522 | 5493 | =end original |
| 4523 | 5494 | |
| 4524 | C<die> も参照してください。 | |
| 5495 | L<C<die>|/die LIST> も参照してください。 | |
| 4525 | 5496 | EXPR が省略された場合には、ステータスを C<0> として終了します。 |
| 4526 | 5497 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が |
| 4527 | 5498 | エラーということだけです; その他の値は、 Perl が実行される環境によって異なる |
| 4528 | 5499 | 解釈がされる可能性があります。 |
| 4529 | 5500 | 例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると |
| 4530 | 5501 | メーラーはアイテムを配達せずに差し戻しますが、 |
| 4531 | 5502 | これはいつでも真ではありません。 |
| 4532 | 5503 | |
| 4533 | 5504 | =begin original |
| 4534 | 5505 | |
| 4535 | Don't use C<exit> to abort a subroutine if there's any | |
| 5506 | Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any | |
| 4536 | someone might want to trap whatever error happened. Use | |
| 5507 | chance that someone might want to trap whatever error happened. Use | |
| 4537 | which can be trapped by an | |
| 5508 | L<C<die>|/die LIST> instead, which can be trapped by an | |
| 5509 | L<C<eval>|/eval EXPR>. | |
| 4538 | 5510 | |
| 4539 | 5511 | =end original |
| 4540 | 5512 | |
| 4541 | 5513 | 誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 |
| 4542 | サブルーチンの中断に C<exit> を使わないでください。 | |
| 5514 | サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。 | |
| 4543 | 代わりに C<eval> でトラップできる C<die> を | |
| 5515 | 代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST> を | |
| 5516 | 使ってください。 | |
| 4544 | 5517 | |
| 4545 | 5518 | =begin original |
| 4546 | 5519 | |
| 4547 | The exit | |
| 5520 | The L<C<exit>|/exit EXPR> function does not always exit immediately. It | |
| 4548 | defined C<END> routines first, but these C<END> routines may | |
| 5521 | calls any defined C<END> routines first, but these C<END> routines may | |
| 4549 | themselves abort the exit. Likewise any object destructors that | |
| 5522 | not themselves abort the exit. Likewise any object destructors that | |
| 4550 | be called are called before the real exit. C<END> routines and | |
| 5523 | need to be called are called before the real exit. C<END> routines and | |
| 4551 | can change the exit status by modifying C<$?> | |
| 5524 | destructors can change the exit status by modifying L<C<$?>|perlvar/$?>. | |
| 4552 | ||
| 5525 | If this is a problem, you can call | |
| 4553 | Se | |
| 5526 | L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor | |
| 5527 | processing. See L<perlmod> for details. | |
| 4554 | 5528 | |
| 4555 | 5529 | =end original |
| 4556 | 5530 | |
| 4557 | exit | |
| 5531 | L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。 | |
| 4558 | まず、定義されている END ルーチンを呼び出しますが、 | |
| 5532 | まず、定義されている C<END> ルーチンを呼び出しますが、 | |
| 4559 | 5533 | C<END> ルーチン自身は exit を止められません。 |
| 4560 | 5534 | 同様に、呼び出す必要のあるオブジェクトデストラクタは |
| 4561 | 5535 | すべて、実際の終了前に呼び出されます。 |
| 4562 | C<END> ルーチンとデストラクタは C<$?> を修正することで | |
| 5536 | C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで | |
| 4563 | 変更できます。 | |
| 5537 | 終了コードを変更できます。 | |
| 4564 | これが問題になる場合は、END やデストラクタが実行されることを | |
| 5538 | これが問題になる場合は、C<END> やデストラクタが実行されることを | |
| 4565 | 防ぐために C<POSIX::_exit($status)> を呼び出してください。 | |
| 5539 | 防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。 | |
| 4566 | 5540 | 詳しくは L<perlmod> を参照してください。 |
| 4567 | 5541 | |
| 4568 | 5542 | =begin original |
| 4569 | 5543 | |
| 4570 | 5544 | Portability issues: L<perlport/exit>. |
| 4571 | 5545 | |
| 4572 | 5546 | =end original |
| 4573 | 5547 | |
| 4574 | 5548 | 移植性の問題: L<perlport/exit>。 |
| 4575 | 5549 | |
| 4576 | 5550 | =item exp EXPR |
| 4577 | 5551 | X<exp> X<exponential> X<antilog> X<antilogarithm> X<e> |
| 4578 | 5552 | |
| 4579 | 5553 | =item exp |
| 4580 | 5554 | |
| 4581 | 5555 | =for Pod::Functions raise I<e> to a power |
| 4582 | 5556 | |
| 4583 | 5557 | =begin original |
| 4584 | 5558 | |
| 4585 | 5559 | Returns I<e> (the natural logarithm base) to the power of EXPR. |
| 4586 | 5560 | If EXPR is omitted, gives C<exp($_)>. |
| 4587 | 5561 | |
| 4588 | 5562 | =end original |
| 4589 | 5563 | |
| 4590 | 5564 | I<e> (自然対数の底) の EXPR 乗を返します。 |
| 4591 | 5565 | EXPR を省略した場合には、C<exp($_)> を返します。 |
| 4592 | 5566 | |
| 4593 | 5567 | =item fc EXPR |
| 4594 | 5568 | X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold> |
| 4595 | 5569 | |
| 4596 | 5570 | =item fc |
| 4597 | 5571 | |
| 4598 | 5572 | =for Pod::Functions +fc return casefolded version of a string |
| 4599 | 5573 | |
| 4600 | 5574 | =begin original |
| 4601 | 5575 | |
| 4602 | 5576 | Returns the casefolded version of EXPR. This is the internal function |
| 4603 | 5577 | implementing the C<\F> escape in double-quoted strings. |
| 4604 | 5578 | |
| 4605 | 5579 | =end original |
| 4606 | 5580 | |
| 4607 | 5581 | EXPR の畳み込み版を返します。 |
| 4608 | 5582 | これは、ダブルクォート文字列における、C<\F> エスケープを |
| 4609 | 5583 | 実装する内部関数です。 |
| 4610 | 5584 | |
| 4611 | 5585 | =begin original |
| 4612 | 5586 | |
| 4613 | 5587 | Casefolding is the process of mapping strings to a form where case |
| 4614 | 5588 | differences are erased; comparing two strings in their casefolded |
| 4615 | 5589 | form is effectively a way of asking if two strings are equal, |
| 4616 | 5590 | regardless of case. |
| 4617 | 5591 | |
| 4618 | 5592 | =end original |
| 4619 | 5593 | |
| 4620 | 5594 | 畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です; |
| 4621 | 5595 | 畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に |
| 4622 | 5596 | 関わらず等しいかどうかを比較する効率的な方法です。 |
| 4623 | 5597 | |
| 4624 | 5598 | =begin original |
| 4625 | 5599 | |
| 4626 | 5600 | Roughly, if you ever found yourself writing this |
| 4627 | 5601 | |
| 4628 | 5602 | =end original |
| 4629 | 5603 | |
| 4630 | 5604 | おおよそ、自分自身で以下のように書いていたとしても |
| 4631 | 5605 | |
| 4632 | 5606 | lc($this) eq lc($that) # Wrong! |
| 4633 | 5607 | # or |
| 4634 | 5608 | uc($this) eq uc($that) # Also wrong! |
| 4635 | 5609 | # or |
| 4636 | 5610 | $this =~ /^\Q$that\E\z/i # Right! |
| 4637 | 5611 | |
| 4638 | 5612 | =begin original |
| 4639 | 5613 | |
| 4640 | 5614 | Now you can write |
| 4641 | 5615 | |
| 4642 | 5616 | =end original |
| 4643 | 5617 | |
| 4644 | 5618 | 今では以下のように書けます |
| 4645 | 5619 | |
| 4646 | 5620 | fc($this) eq fc($that) |
| 4647 | 5621 | |
| 4648 | 5622 | =begin original |
| 4649 | 5623 | |
| 4650 | 5624 | And get the correct results. |
| 4651 | 5625 | |
| 4652 | 5626 | =end original |
| 4653 | 5627 | |
| 4654 | 5628 | そして正しい結果を得られます。 |
| 4655 | 5629 | |
| 4656 | 5630 | =begin original |
| 4657 | 5631 | |
| 4658 | Perl only implements the full form of casefolding, | |
| 5632 | Perl only implements the full form of casefolding, but you can access | |
| 4659 | ||
| 5633 | the simple folds using L<Unicode::UCD/B<casefold()>> and | |
| 4660 | L<Unicode::UCD/prop_invmap()>. | |
| 5634 | L<Unicode::UCD/B<prop_invmap()>>. | |
| 4661 | 5635 | For further information on casefolding, refer to |
| 4662 | 5636 | the Unicode Standard, specifically sections 3.13 C<Default Case Operations>, |
| 4663 | 5637 | 4.2 C<Case-Normative>, and 5.18 C<Case Mappings>, |
| 4664 | available at L<http://www.unicode.org/versions/latest/>, as well as the | |
| 5638 | available at L<https://www.unicode.org/versions/latest/>, as well as the | |
| 4665 | Case Charts available at L<http://www.unicode.org/charts/case/>. | |
| 5639 | Case Charts available at L<https://www.unicode.org/charts/case/>. | |
| 4666 | 5640 | |
| 4667 | 5641 | =end original |
| 4668 | 5642 | |
| 4669 | 5643 | Perl は完全な形式の畳み込みのみを実装していますが、 |
| 4670 | L<Unicode::UCD/casefold()> と L<Unicode::UCD/prop_invmap()> を使って | |
| 5644 | L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って | |
| 4671 | 5645 | 単純なたたみ込みにアクセスできます。 |
| 4672 | 5646 | 畳み込みに関するさらなる情報については、 |
| 4673 | L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
| 5647 | L<https://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
| 4674 | 5648 | 3.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18 |
| 4675 | C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で | |
| 5649 | C<Case Mappings> および、L<https://www.unicode.org/charts/case/> で | |
| 4676 | 5650 | 利用可能なケース表を参照してください。 |
| 4677 | 5651 | |
| 4678 | 5652 | =begin original |
| 4679 | 5653 | |
| 4680 | If EXPR is omitted, uses C<$_>. | |
| 5654 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 4681 | 5655 | |
| 4682 | 5656 | =end original |
| 4683 | 5657 | |
| 4684 | EXPR が省略されると、C<$_> を使います。 | |
| 5658 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 4685 | 5659 | |
| 4686 | 5660 | =begin original |
| 4687 | 5661 | |
| 4688 | This function behaves the same way under various pragma, such as in | |
| 5662 | This function behaves the same way under various pragmas, such as within | |
| 4689 | ||
| 5663 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>, | |
| 5664 | as L<C<lc>|/lc EXPR> does, with the single exception of | |
| 5665 | L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the | |
| 5666 | scope of L<S<C<use locale>>|locale>. The foldcase of this character | |
| 5667 | would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR> | |
| 5668 | section, case | |
| 5669 | changes that cross the 255/256 boundary are problematic under locales, | |
| 5670 | and are hence prohibited. Therefore, this function under locale returns | |
| 5671 | instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER | |
| 5672 | LONG S>. Since that character itself folds to C<"s">, the string of two | |
| 5673 | of them together should be equivalent to a single U+1E9E when foldcased. | |
| 4690 | 5674 | |
| 4691 | 5675 | =end original |
| 4692 | 5676 | |
| 4693 | この関数は、 | |
| 5677 | この関数は、 | |
| 4694 | L< | |
| 5678 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature> | |
| 5679 | のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に | |
| 5680 | 振る舞います; | |
| 5681 | 但し、L<S<C<use locale>>|locale> のスコープ内での | |
| 5682 | I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。 | |
| 5683 | この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で | |
| 5684 | 説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は | |
| 5685 | 問題があるので、禁止されています。 | |
| 5686 | 従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である | |
| 5687 | C<"\x{17F}\x{17F}"> を返します。 | |
| 5688 | この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は | |
| 5689 | 畳み込まれた場合は単一の U+1E9E と等価になります。 | |
| 4695 | 5690 | |
| 4696 | 5691 | =begin original |
| 4697 | 5692 | |
| 4698 | 5693 | While the Unicode Standard defines two additional forms of casefolding, |
| 4699 | 5694 | one for Turkic languages and one that never maps one character into multiple |
| 4700 | characters, these are not provided by the Perl core | |
| 5695 | characters, these are not provided by the Perl core. However, the CPAN module | |
| 4701 | C<Unicode::Casing> may be used to provide an implementation. | |
| 5696 | L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation. | |
| 4702 | 5697 | |
| 4703 | 5698 | =end original |
| 4704 | 5699 | |
| 4705 | 5700 | Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して |
| 4706 | 5701 | 一つの文字が複数の文字にマッピングされないもの、を定義していますが、 |
| 4707 | これらは Perl コアでは提供されません | |
| 5702 | これらは Perl コアでは提供されません。 | |
| 4708 | C<Unicode::Casing> が実装を | |
| 5703 | しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を | |
| 5704 | 提供しています。 | |
| 4709 | 5705 | |
| 4710 | 5706 | =begin original |
| 4711 | 5707 | |
| 4712 | ||
| 5708 | L<C<fc>|/fc EXPR> is available only if the | |
| 4713 | ||
| 5709 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is | |
| 4714 | i | |
| 5710 | prefixed with C<CORE::>. The | |
| 5711 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically | |
| 5712 | with a C<use v5.16> (or higher) declaration in the current scope. | |
| 4715 | 5713 | |
| 4716 | 5714 | =end original |
| 4717 | 5715 | |
| 4718 | ||
| 5716 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か | |
| 4719 | 前置されたときにのみ利用可能です | |
| 5717 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 4720 | ||
| 5718 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
| 5719 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 4721 | 5720 | |
| 4722 | 5721 | =item fcntl FILEHANDLE,FUNCTION,SCALAR |
| 4723 | 5722 | X<fcntl> |
| 4724 | 5723 | |
| 4725 | 5724 | =for Pod::Functions file control system call |
| 4726 | 5725 | |
| 4727 | 5726 | =begin original |
| 4728 | 5727 | |
| 4729 | Implements the fcntl(2) function. You'll probably have to say | |
| 5728 | Implements the L<fcntl(2)> function. You'll probably have to say | |
| 4730 | 5729 | |
| 4731 | 5730 | =end original |
| 4732 | 5731 | |
| 4733 | fcntl(2) 関数を実装します。 | |
| 5732 | L<fcntl(2)> 関数を実装します。 | |
| 4734 | 5733 | 正しい定数定義を得るために、まず |
| 4735 | 5734 | |
| 4736 | 5735 | use Fcntl; |
| 4737 | 5736 | |
| 4738 | 5737 | =begin original |
| 4739 | 5738 | |
| 4740 | 5739 | first to get the correct constant definitions. Argument processing and |
| 4741 | value returned work just like C<ioctl> | |
| 5740 | value returned work just like L<C<ioctl>|/ioctl | |
| 4742 | For example: | |
| 5741 | FILEHANDLE,FUNCTION,SCALAR> below. For example: | |
| 4743 | 5742 | |
| 4744 | 5743 | =end original |
| 4745 | 5744 | |
| 4746 | 5745 | と書くことが必要でしょう。 |
| 4747 | 引数の処理と返り値については、下記の | |
| 5746 | 引数の処理と返り値については、下記の | |
| 5747 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。 | |
| 4748 | 5748 | 例えば: |
| 4749 | 5749 | |
| 4750 | 5750 | use Fcntl; |
| 4751 | fcntl($filehandle, F_GETFL, | |
| 5751 | my $flags = fcntl($filehandle, F_GETFL, 0) | |
| 4752 | or die " | |
| 5752 | or die "Can't fcntl F_GETFL: $!"; | |
| 4753 | 5753 | |
| 4754 | 5754 | =begin original |
| 4755 | 5755 | |
| 4756 | You don't have to check for C<defined> on the return | |
| 5756 | You don't have to check for L<C<defined>|/defined EXPR> on the return | |
| 4757 | ||
| 5757 | from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like | |
| 4758 | C< | |
| 5758 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return | |
| 4759 | ||
| 5759 | from the system call into C<"0 but true"> in Perl. This string is true | |
| 4760 | on | |
| 5760 | in boolean context and C<0> in numeric context. It is also exempt from | |
| 5761 | the normal | |
| 5762 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 5763 | L<warnings> on improper numeric conversions. | |
| 4761 | 5764 | |
| 4762 | 5765 | =end original |
| 4763 | 5766 | |
| 4764 | C<fcntl> からの返り値のチェックに | |
| 5767 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに | |
| 4765 | ||
| 5768 | L<C<defined>|/defined EXPR> を使う必要はありません。 | |
| 4766 | C< | |
| 5769 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは | |
| 5770 | システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。 | |
| 4767 | 5771 | この文字列は真偽値コンテキストでは真となり、 |
| 4768 | 5772 | 数値コンテキストでは C<0> になります。 |
| 4769 | これはまた、不適切な数値変換に関する通常の | |
| 5773 | これはまた、不適切な数値変換に関する通常の | |
| 5774 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 5775 | L<warnings> を回避します。 | |
| 4770 | 5776 | |
| 4771 | 5777 | =begin original |
| 4772 | 5778 | |
| 4773 | Note that C<fcntl> raises an | |
| 5779 | Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an | |
| 4774 | doesn't implement fcntl(2). See | |
| 5780 | exception if used on a machine that doesn't implement L<fcntl(2)>. See | |
| 4775 | manpage to learn what functions | |
| 5781 | the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions | |
| 5782 | are available on your system. | |
| 4776 | 5783 | |
| 4777 | 5784 | =end original |
| 4778 | 5785 | |
| 4779 | fcntl(2) が実装されていないマシンでは、 | |
| 5786 | L<fcntl(2)> が実装されていないマシンでは、 | |
| 5787 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を | |
| 4780 | 5788 | 引き起こすことに注意してください。 |
| 4781 | システムでどの関数が利用可能かについては Fcntl モジュールや | |
| 5789 | システムでどの関数が利用可能かについては L<Fcntl> モジュールや | |
| 4782 | fcntl(2) man ページを参照してください。 | |
| 5790 | L<fcntl(2)> man ページを参照してください。 | |
| 4783 | 5791 | |
| 4784 | 5792 | =begin original |
| 4785 | 5793 | |
| 4786 | Here's an example of setting a filehandle named C<REMOTE> to be | |
| 5794 | Here's an example of setting a filehandle named C<$REMOTE> to be | |
| 4787 | non-blocking at the system level. You'll have to negotiate | |
| 5795 | non-blocking at the system level. You'll have to negotiate | |
| 4788 | on your own, though. | |
| 5796 | L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though. | |
| 4789 | 5797 | |
| 4790 | 5798 | =end original |
| 4791 | 5799 | |
| 4792 | これは C<REMOTE> というファイルハンドルをシステムレベルで | |
| 5800 | これは C<$REMOTE> というファイルハンドルをシステムレベルで | |
| 4793 | 5801 | 非ブロックモードにセットする例です。 |
| 4794 | ただし、 C<$|> を自分で管理しなければなりません。 | |
| 5802 | ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。 | |
| 4795 | 5803 | |
| 4796 | 5804 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); |
| 4797 | 5805 | |
| 4798 | $flags = fcntl(REMOTE, F_GETFL, 0) | |
| 5806 | my $flags = fcntl($REMOTE, F_GETFL, 0) | |
| 4799 | | |
| 5807 | or die "Can't get flags for the socket: $!\n"; | |
| 4800 | 5808 | |
| 4801 | | |
| 5809 | fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK) | |
| 4802 | | |
| 5810 | or die "Can't set flags for the socket: $!\n"; | |
| 4803 | 5811 | |
| 4804 | 5812 | =begin original |
| 4805 | 5813 | |
| 4806 | 5814 | Portability issues: L<perlport/fcntl>. |
| 4807 | 5815 | |
| 4808 | 5816 | =end original |
| 4809 | 5817 | |
| 4810 | 5818 | 移植性の問題: L<perlport/fcntl>。 |
| 4811 | 5819 | |
| 4812 | 5820 | =item __FILE__ |
| 4813 | 5821 | X<__FILE__> |
| 4814 | 5822 | |
| 4815 | 5823 | =for Pod::Functions the name of the current source file |
| 4816 | 5824 | |
| 4817 | 5825 | =begin original |
| 4818 | 5826 | |
| 4819 | 5827 | A special token that returns the name of the file in which it occurs. |
| 5828 | It can be altered by the mechanism described at | |
| 5829 | L<perlsyn/"Plain Old Comments (Not!)">. | |
| 4820 | 5830 | |
| 4821 | 5831 | =end original |
| 4822 | 5832 | |
| 4823 | 5833 | これが書いてあるファイルの名前を返す特殊トークン。 |
| 5834 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って | |
| 5835 | 置き換えられます。 | |
| 4824 | 5836 | |
| 5837 | =item field VARNAME | |
| 5838 | X<field> | |
| 5839 | ||
| 5840 | =for Pod::Functions declare a field variable of the current class | |
| 5841 | ||
| 5842 | =begin original | |
| 5843 | ||
| 5844 | Declares a new field variable within the current class. Methods and | |
| 5845 | C<ADJUST> blocks of the class will have access to this variable as if it | |
| 5846 | was a lexical in scope at that point. | |
| 5847 | ||
| 5848 | =end original | |
| 5849 | ||
| 5850 | Declares a new field variable within the current class. Methods and | |
| 5851 | C<ADJUST> blocks of the class will have access to this variable as if it | |
| 5852 | was a lexical in scope at that point. | |
| 5853 | (TBT) | |
| 5854 | ||
| 4825 | 5855 | =item fileno FILEHANDLE |
| 4826 | 5856 | X<fileno> |
| 4827 | 5857 | |
| 5858 | =item fileno DIRHANDLE | |
| 5859 | ||
| 4828 | 5860 | =for Pod::Functions return file descriptor from filehandle |
| 4829 | 5861 | |
| 4830 | 5862 | =begin original |
| 4831 | 5863 | |
| 4832 | Returns the file descriptor for a filehandle | |
| 5864 | Returns the file descriptor for a filehandle or directory handle, | |
| 5865 | or undefined if the | |
| 4833 | 5866 | filehandle is not open. If there is no real file descriptor at the OS |
| 4834 | 5867 | level, as can happen with filehandles connected to memory objects via |
| 4835 | C<open> with a reference for the third | |
| 5868 | L<C<open>|/open FILEHANDLE,MODE,EXPR> with a reference for the third | |
| 5869 | argument, -1 is returned. | |
| 4836 | 5870 | |
| 4837 | 5871 | =end original |
| 4838 | 5872 | |
| 4839 | ファイルハンドルに対するファイル記述子を返します; | |
| 5873 | ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します; | |
| 4840 | オープンしていない場合は未定義値を返します。 | |
| 5874 | ファイルハンドルがオープンしていない場合は未定義値を返します。 | |
| 4841 | OS レベルで実際のファイル記述子がない( | |
| 5875 | OS レベルで実際のファイル記述子がない( | |
| 5876 | L<C<open>|/open FILEHANDLE,MODE,EXPR> の第 3 引数にリファレンスを | |
| 4842 | 5877 | 指定してファイルハンドルがメモリオブジェクトと結びつけられたときに |
| 4843 | 5878 | 起こります)場合、-1 が返されます。 |
| 4844 | 5879 | |
| 4845 | 5880 | =begin original |
| 4846 | 5881 | |
| 4847 | This is mainly useful for constructing | |
| 5882 | This is mainly useful for constructing bitmaps for | |
| 4848 | ||
| 5883 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX | |
| 5884 | tty-handling operations. | |
| 4849 | 5885 | If FILEHANDLE is an expression, the value is taken as an indirect |
| 4850 | 5886 | filehandle, generally its name. |
| 4851 | 5887 | |
| 4852 | 5888 | =end original |
| 4853 | 5889 | |
| 4854 | これは主に C<select> や低レベル | |
| 5890 | これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル | |
| 4855 | 構成するときに便利です。 | |
| 5891 | POSIX tty 操作に対する、ビットマップを構成するときに便利です。 | |
| 4856 | 5892 | FILEHANDLE が式であれば、 |
| 4857 | 5893 | その値が間接ファイルハンドル(普通は名前)として使われます。 |
| 4858 | 5894 | |
| 4859 | 5895 | =begin original |
| 4860 | 5896 | |
| 4861 | 5897 | You can use this to find out whether two handles refer to the |
| 4862 | 5898 | same underlying descriptor: |
| 4863 | 5899 | |
| 4864 | 5900 | =end original |
| 4865 | 5901 | |
| 4866 | 5902 | これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに |
| 4867 | 5903 | 使えます: |
| 4868 | 5904 | |
| 4869 | if (fileno( | |
| 5905 | if (fileno($this) != -1 && fileno($this) == fileno($that)) { | |
| 4870 | print " | |
| 5906 | print "\$this and \$that are dups\n"; | |
| 5907 | } elsif (fileno($this) != -1 && fileno($that) != -1) { | |
| 5908 | print "\$this and \$that have different " . | |
| 5909 | "underlying file descriptors\n"; | |
| 5910 | } else { | |
| 5911 | print "At least one of \$this and \$that does " . | |
| 5912 | "not have a real file descriptor\n"; | |
| 4871 | 5913 | } |
| 4872 | 5914 | |
| 5915 | =begin original | |
| 5916 | ||
| 5917 | The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle | |
| 5918 | depends on the operating system. On a system with L<dirfd(3)> or | |
| 5919 | similar, L<C<fileno>|/fileno FILEHANDLE> on a directory | |
| 5920 | handle returns the underlying file descriptor associated with the | |
| 5921 | handle; on systems with no such support, it returns the undefined value, | |
| 5922 | and sets L<C<$!>|perlvar/$!> (errno). | |
| 5923 | ||
| 5924 | =end original | |
| 5925 | ||
| 5926 | ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは | |
| 5927 | オペレーティングシステムに依存します。 | |
| 5928 | L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する | |
| 5929 | L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる | |
| 5930 | ファイル記述子を返します; | |
| 5931 | そのような対応がないシステムでは、未定義値を返し、 | |
| 5932 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 5933 | ||
| 4873 | 5934 | =item flock FILEHANDLE,OPERATION |
| 4874 | 5935 | X<flock> X<lock> X<locking> |
| 4875 | 5936 | |
| 4876 | 5937 | =for Pod::Functions lock an entire file with an advisory lock |
| 4877 | 5938 | |
| 4878 | 5939 | =begin original |
| 4879 | 5940 | |
| 4880 | Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true | |
| 5941 | Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true | |
| 4881 | 5942 | for success, false on failure. Produces a fatal error if used on a |
| 4882 | machine that doesn't implement flock(2), fcntl(2) locking, or | |
| 5943 | machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or | |
| 4883 | C<flock> is Perl's portable | |
| 5944 | L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable | |
| 4884 | entire files only, not | |
| 5945 | file-locking interface, although it locks entire files only, not | |
| 5946 | records. | |
| 4885 | 5947 | |
| 4886 | 5948 | =end original |
| 4887 | 5949 | |
| 4888 | FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。 | |
| 5950 | FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。 | |
| 4889 | 5951 | 成功時には真を、失敗時には偽を返します。 |
| 4890 | flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない | |
| 5952 | L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない | |
| 4891 | 5953 | マシンで使うと、致命的エラーが発生します。 |
| 4892 | C<flock> は Perl の移植性のある | |
| 5954 | L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある | |
| 5955 | ファイルロックインターフェースです; | |
| 4893 | 5956 | しかしレコードではなく、ファイル全体のみをロックします。 |
| 4894 | 5957 | |
| 4895 | 5958 | =begin original |
| 4896 | 5959 | |
| 4897 | Two potentially non-obvious but traditional C<flock> | |
| 5960 | Two potentially non-obvious but traditional L<C<flock>|/flock | |
| 5961 | FILEHANDLE,OPERATION> semantics are | |
| 4898 | 5962 | that it waits indefinitely until the lock is granted, and that its locks |
| 4899 | 5963 | are B<merely advisory>. Such discretionary locks are more flexible, but |
| 4900 | 5964 | offer fewer guarantees. This means that programs that do not also use |
| 4901 | C<flock> may modify files locked with | |
| 5965 | L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with | |
| 5966 | L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>, | |
| 4902 | 5967 | your port's specific documentation, and your system-specific local manpages |
| 4903 | 5968 | for details. It's best to assume traditional behavior if you're writing |
| 4904 | 5969 | portable programs. (But if you're not, you should as always feel perfectly |
| 4905 | 5970 | free to write for your own system's idiosyncrasies (sometimes called |
| 4906 | 5971 | "features"). Slavish adherence to portability concerns shouldn't get |
| 4907 | 5972 | in the way of your getting your job done.) |
| 4908 | 5973 | |
| 4909 | 5974 | =end original |
| 4910 | 5975 | |
| 4911 | 明白ではないものの、伝統的な C<flock> の | |
| 5976 | 明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION> の | |
| 5977 | 動作としては、ロックが得られるまで | |
| 4912 | 5978 | 無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。 |
| 4913 | 5979 | このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。 |
| 4914 | これは、C<flock> を使わないプログラムが | |
| 5980 | これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが | |
| 5981 | L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを | |
| 4915 | 5982 | 書き換えるかもしれないことを意味します。 |
| 4916 | 5983 | 詳細については、L<perlport>、システム固有のドキュメント、システム固有の |
| 4917 | 5984 | ローカルの man ページを参照してください。 |
| 4918 | 5985 | 移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが |
| 4919 | 5986 | ベストです。 |
| 4920 | 5987 | (しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば |
| 4921 | 5988 | 「仕様」と呼ばれます)に合わせて書くことも完全に自由です。 |
| 4922 | 5989 | 盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは |
| 4923 | 5990 | ありません。) |
| 4924 | 5991 | |
| 4925 | 5992 | =begin original |
| 4926 | 5993 | |
| 4927 | 5994 | OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with |
| 4928 | 5995 | LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but |
| 4929 | 5996 | you can use the symbolic names if you import them from the L<Fcntl> module, |
| 4930 | 5997 | either individually, or as a group using the C<:flock> tag. LOCK_SH |
| 4931 | 5998 | requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN |
| 4932 | 5999 | releases a previously requested lock. If LOCK_NB is bitwise-or'ed with |
| 4933 | LOCK_SH or LOCK_EX, then C<flock> returns | |
| 6000 | LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns | |
| 4934 | waiting for the lock; check the return | |
| 6001 | immediately rather than blocking waiting for the lock; check the return | |
| 6002 | status to see if you got it. | |
| 4935 | 6003 | |
| 4936 | 6004 | =end original |
| 4937 | 6005 | |
| 4938 | 6006 | OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と |
| 4939 | 6007 | 組み合わされることもあります。 |
| 4940 | 6008 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから |
| 4941 | 6009 | シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、 |
| 4942 | 6010 | シンボル名をを使うことができます。 |
| 4943 | 6011 | LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は |
| 4944 | 6012 | 前回要求したロックを開放します。 |
| 4945 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 | |
| 6013 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 | |
| 6014 | L<C<flock>|/flock FILEHANDLE,OPERATION> は | |
| 4946 | 6015 | ロックを取得するまで待つのではなく、すぐに返ります; |
| 4947 | 6016 | ロックが取得できたかどうかは返り値を調べます。 |
| 4948 | 6017 | |
| 4949 | 6018 | =begin original |
| 4950 | 6019 | |
| 4951 | 6020 | To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE |
| 4952 | 6021 | before locking or unlocking it. |
| 4953 | 6022 | |
| 4954 | 6023 | =end original |
| 4955 | 6024 | |
| 4956 | 6025 | 不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に |
| 4957 | 6026 | FILEHANDLE をフラッシュします。 |
| 4958 | 6027 | |
| 4959 | 6028 | =begin original |
| 4960 | 6029 | |
| 4961 | Note that the emulation built with lockf(3) doesn't provide shared | |
| 6030 | Note that the emulation built with L<lockf(3)> doesn't provide shared | |
| 4962 | 6031 | locks, and it requires that FILEHANDLE be open with write intent. These |
| 4963 | are the semantics that lockf(3) implements. Most if not all systems | |
| 6032 | are the semantics that L<lockf(3)> implements. Most if not all systems | |
| 4964 | implement lockf(3) in terms of fcntl(2) locking, though, so the | |
| 6033 | implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the | |
| 4965 | 6034 | differing semantics shouldn't bite too many people. |
| 4966 | 6035 | |
| 4967 | 6036 | =end original |
| 4968 | 6037 | |
| 4969 | lockf(3) で作成されたエミュレーションは共有ロックを提供せず、 | |
| 6038 | L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、 | |
| 4970 | 6039 | FILEHANDLE が書き込みモードで開いていることを必要とすることに |
| 4971 | 6040 | 注意してください。 |
| 4972 | これは lockf(3) が実装している動作です。 | |
| 6041 | これは L<lockf(3)> が実装している動作です。 | |
| 4973 | しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って | |
| 6042 | しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って | |
| 4974 | lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは | |
| 6043 | L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは | |
| 4975 | 6044 | ないはずです。 |
| 4976 | 6045 | |
| 4977 | 6046 | =begin original |
| 4978 | 6047 | |
| 4979 | Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE | |
| 6048 | Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE | |
| 4980 | 6049 | be open with read intent to use LOCK_SH and requires that it be open |
| 4981 | 6050 | with write intent to use LOCK_EX. |
| 4982 | 6051 | |
| 4983 | 6052 | =end original |
| 4984 | 6053 | |
| 4985 | flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには | |
| 6054 | L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには | |
| 4986 | 6055 | FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには |
| 4987 | 6056 | 書き込みで開いている必要があることに注意してください。 |
| 4988 | 6057 | |
| 4989 | 6058 | =begin original |
| 4990 | 6059 | |
| 4991 | Note also that some versions of C<flock> | |
| 6060 | Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION> | |
| 4992 | network; you would need to use the more | |
| 6061 | cannot lock things over the network; you would need to use the more | |
| 4993 | t | |
| 6062 | system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for | |
| 4994 | ||
| 6063 | that. If you like you can force Perl to ignore your system's L<flock(2)> | |
| 6064 | function, and so provide its own L<fcntl(2)>-based emulation, by passing | |
| 4995 | 6065 | the switch C<-Ud_flock> to the F<Configure> program when you configure |
| 4996 | 6066 | and build a new Perl. |
| 4997 | 6067 | |
| 4998 | 6068 | =end original |
| 4999 | 6069 | |
| 5000 | ネットワーク越しにはロックできない C<flock> も | |
| 6070 | ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION> も | |
| 5001 | こ | |
| 6071 | あることに注意してください; | |
| 5002 | ||
| 6072 | このためには、よりシステム依存な | |
| 6073 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。 | |
| 6074 | Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの | |
| 5003 | 6075 | エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに |
| 5004 | 6076 | F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。 |
| 5005 | 6077 | |
| 5006 | 6078 | =begin original |
| 5007 | 6079 | |
| 5008 | 6080 | Here's a mailbox appender for BSD systems. |
| 5009 | 6081 | |
| 5010 | 6082 | =end original |
| 5011 | 6083 | |
| 5012 | 6084 | BSD システムでのメールボックスへの追加処理の例を示します。 |
| 5013 | 6085 | |
| 5014 | 6086 | # import LOCK_* and SEEK_END constants |
| 5015 | 6087 | use Fcntl qw(:flock SEEK_END); |
| 5016 | 6088 | |
| 5017 | 6089 | sub lock { |
| 5018 | 6090 | my ($fh) = @_; |
| 5019 | 6091 | flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n"; |
| 6092 | # and, in case we're running on a very old UNIX | |
| 5021 | # an | |
| 6093 | # variant without the modern O_APPEND semantics... | |
| 5022 | 6094 | seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; |
| 5023 | 6095 | } |
| 5024 | 6096 | |
| 5025 | 6097 | sub unlock { |
| 5026 | 6098 | my ($fh) = @_; |
| 5027 | 6099 | flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; |
| 5028 | 6100 | } |
| 5029 | 6101 | |
| 5030 | 6102 | open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}") |
| 5031 | 6103 | or die "Can't open mailbox: $!"; |
| 5032 | 6104 | |
| 5033 | 6105 | lock($mbox); |
| 5034 | 6106 | print $mbox $msg,"\n\n"; |
| 5035 | 6107 | unlock($mbox); |
| 5036 | 6108 | |
| 5037 | 6109 | =begin original |
| 5038 | 6110 | |
| 5039 | On systems that support a real flock(2), locks are inherited across | |
| 6111 | On systems that support a real L<flock(2)>, locks are inherited across | |
| 5040 | calls, whereas those that must resort to the more | |
| 6112 | L<C<fork>|/fork> calls, whereas those that must resort to the more | |
| 5041 | function lose their locks, making it seriously | |
| 6113 | capricious L<fcntl(2)> function lose their locks, making it seriously | |
| 6114 | harder to write servers. | |
| 5042 | 6115 | |
| 5043 | 6116 | =end original |
| 5044 | 6117 | |
| 5045 | 真の flock(2) に対応しているシステムではロックは fork | |
| 6118 | 真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して | |
| 5046 | 継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、 | |
| 6119 | 継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、 | |
| 5047 | 6120 | サーバを書くのは本当により難しくなります。 |
| 5048 | 6121 | |
| 5049 | 6122 | =begin original |
| 5050 | 6123 | |
| 5051 | See also L<DB_File> for other flock | |
| 6124 | See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION> | |
| 6125 | examples. | |
| 5052 | 6126 | |
| 5053 | 6127 | =end original |
| 5054 | 6128 | |
| 5055 | その他の flock | |
| 6129 | その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も | |
| 6130 | 参照してください。 | |
| 5056 | 6131 | |
| 5057 | 6132 | =begin original |
| 5058 | 6133 | |
| 5059 | 6134 | Portability issues: L<perlport/flock>. |
| 5060 | 6135 | |
| 5061 | 6136 | =end original |
| 5062 | 6137 | |
| 5063 | 6138 | 移植性の問題: L<perlport/flock>。 |
| 5064 | 6139 | |
| 5065 | 6140 | =item fork |
| 5066 | 6141 | X<fork> X<child> X<parent> |
| 5067 | 6142 | |
| 5068 | 6143 | =for Pod::Functions create a new process just like this one |
| 5069 | 6144 | |
| 5070 | 6145 | =begin original |
| 5071 | 6146 | |
| 5072 | Does a fork(2) system call to create a new process running the | |
| 6147 | Does a L<fork(2)> system call to create a new process running the | |
| 5073 | 6148 | same program at the same point. It returns the child pid to the |
| 5074 | parent process, C<0> to the child process, or C<undef> | |
| 6149 | parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if | |
| 6150 | the fork is | |
| 5075 | 6151 | unsuccessful. File descriptors (and sometimes locks on those descriptors) |
| 5076 | 6152 | are shared, while everything else is copied. On most systems supporting |
| 5077 | fork(), great care has gone into making it extremely efficient (for | |
| 6153 | L<fork(2)>, great care has gone into making it extremely efficient (for | |
| 5078 | 6154 | example, using copy-on-write technology on data pages), making it the |
| 5079 | 6155 | dominant paradigm for multitasking over the last few decades. |
| 5080 | 6156 | |
| 5081 | 6157 | =end original |
| 5082 | 6158 | |
| 5083 | 6159 | 同じプログラムの同じ地点から開始する新しいプロセスを作成するために |
| 5084 | システムコール fork(2) を行ないます。 | |
| 6160 | システムコール L<fork(2)> を行ないます。 | |
| 5085 | 6161 | 親プロセスには、チャイルドプロセスの pid を、 |
| 5086 | 6162 | チャイルドプロセスに C<0> を返しますが、 |
| 5087 | fork に失敗したときには、C<undef>を返します。 | |
| 6163 | fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。 | |
| 5088 | 6164 | ファイル記述子(および記述子に関連するロック)は共有され、 |
| 5089 | 6165 | その他の全てはコピーされます。 |
| 5090 | fork() に対応するほとんどのシステムでは、 | |
| 6166 | L<fork(2)> に対応するほとんどのシステムでは、 | |
| 5091 | 6167 | これを極めて効率的にするために多大な努力が払われてきました |
| 5092 | 6168 | (例えば、データページへの copy-on-write テクノロジーなどです); |
| 5093 | 6169 | これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。 |
| 5094 | 6170 | |
| 5095 | 6171 | =begin original |
| 5096 | 6172 | |
| 5097 | Perl attempts to flush all files opened for | |
| 6173 | Perl attempts to flush all files opened for output before forking the | |
| 5098 | ||
| 6174 | child process, but this may not be supported on some platforms (see | |
| 5099 | ||
| 6175 | L<perlport>). To be safe, you may need to set | |
| 5100 | C<$|> ($AUTOFLUSH in English) or | |
| 6176 | L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or | |
| 5101 | C< | |
| 6177 | call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on | |
| 6178 | any open handles to avoid duplicate output. | |
| 5102 | 6179 | |
| 5103 | 6180 | =end original |
| 5104 | 6181 | |
| 5105 | ||
| 6182 | Perl は子プロセスを fork する前に出力用にオープンしている全ての | |
| 5106 | 6183 | ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも |
| 5107 | 6184 | あります(L<perlport> を参照してください)。 |
| 5108 | 6185 | 安全のためには、出力が重複するのを避けるために、 |
| 5109 | 全てのオープンしているハンドルに対して C<$ | |
| 6186 | 全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>> | |
| 5110 | $AUTOFLUSH) を設定するか、 | |
| 6187 | (L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、 | |
| 5111 | C<IO::Handle> モジュールの C<autoflush | |
| 6188 | L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを | |
| 5112 | あるかもしれません。 | |
| 6189 | 呼ぶ必要があるかもしれません。 | |
| 5113 | 6190 | |
| 5114 | 6191 | =begin original |
| 5115 | 6192 | |
| 5116 | If you C<fork> without ever waiting on your children, you will | |
| 6193 | If you L<C<fork>|/fork> without ever waiting on your children, you will | |
| 5117 | 6194 | accumulate zombies. On some systems, you can avoid this by setting |
| 5118 | C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for | |
| 6195 | L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for | |
| 5119 | forking and reaping moribund children. | |
| 6196 | more examples of forking and reaping moribund children. | |
| 5120 | 6197 | |
| 5121 | 6198 | =end original |
| 5122 | 6199 | |
| 5123 | チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、 | |
| 6200 | チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、 | |
| 5124 | 6201 | ゾンビをためこむことになります。 |
| 5125 | C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを | |
| 6202 | L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを | |
| 6203 | 回避できるシステムもあります。 | |
| 5126 | 6204 | fork と消滅しかけている子プロセスを回収するための更なる例については |
| 5127 | 6205 | L<perlipc> も参照してください。 |
| 5128 | 6206 | |
| 5129 | 6207 | =begin original |
| 5130 | 6208 | |
| 5131 | 6209 | Note that if your forked child inherits system file descriptors like |
| 5132 | 6210 | STDIN and STDOUT that are actually connected by a pipe or socket, even |
| 5133 | 6211 | if you exit, then the remote server (such as, say, a CGI script or a |
| 5134 | 6212 | backgrounded job launched from a remote shell) won't think you're done. |
| 5135 | 6213 | You should reopen those to F</dev/null> if it's any issue. |
| 5136 | 6214 | |
| 5137 | 6215 | =end original |
| 5138 | 6216 | |
| 5139 | 6217 | fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を |
| 5140 | 6218 | 継承する場合、(CGI スクリプトやリモートシェルといった |
| 5141 | 6219 | バックグラウンドジョブのような)リモートサーバは考え通りに |
| 5142 | 6220 | 動かないであろうことに注意してください。 |
| 5143 | 6221 | このような場合ではこれらを F</dev/null> として再オープンするべきです。 |
| 5144 | 6222 | |
| 5145 | 6223 | =begin original |
| 5146 | 6224 | |
| 5147 | On some platforms such as Windows, where the fork() system call is | |
| 6225 | On some platforms such as Windows, where the L<fork(2)> system call is | |
| 5148 | Perl can be built to emulate fork | |
| 6226 | not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl | |
| 5149 | The emulation is designed, at the level of the Perl | |
| 6227 | interpreter. The emulation is designed, at the level of the Perl | |
| 5150 | to be as compatible as possible with the "Unix" fork(). | |
| 6228 | program, to be as compatible as possible with the "Unix" L<fork(2)>. | |
| 5151 | However it has limitations that have to be considered in code intended | |
| 6229 | However it has limitations that have to be considered in code intended | |
| 5152 | See L<perlfork> for more details. | |
| 6230 | to be portable. See L<perlfork> for more details. | |
| 5153 | 6231 | |
| 5154 | 6232 | =end original |
| 5155 | 6233 | |
| 5156 | Windows のような fork() が利用不能なシステムでは、Perl は | |
| 6234 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
| 5157 | インタプリタでエミュレートします。 | |
| 6235 | L<C<fork>|/fork> を Perl インタプリタでエミュレートします。 | |
| 5158 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" fork() と | |
| 6236 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と | |
| 5159 | 6237 | 互換性があるように設計されています。 |
| 5160 | 6238 | しかしコードが移植性があると考えられるように制限があります。 |
| 5161 | 6239 | さらなる詳細については L<perlfork> を参照してください。 |
| 5162 | 6240 | |
| 5163 | 6241 | =begin original |
| 5164 | 6242 | |
| 5165 | 6243 | Portability issues: L<perlport/fork>. |
| 5166 | 6244 | |
| 5167 | 6245 | =end original |
| 5168 | 6246 | |
| 5169 | 6247 | 移植性の問題: L<perlport/fork>。 |
| 5170 | 6248 | |
| 5171 | 6249 | =item format |
| 5172 | 6250 | X<format> |
| 5173 | 6251 | |
| 5174 | 6252 | =for Pod::Functions declare a picture format with use by the write() function |
| 5175 | 6253 | |
| 5176 | 6254 | =begin original |
| 5177 | 6255 | |
| 5178 | Declare a picture format for use by the C<write> | |
| 6256 | Declare a picture format for use by the L<C<write>|/write FILEHANDLE> | |
| 5179 | example: | |
| 6257 | function. For example: | |
| 5180 | 6258 | |
| 5181 | 6259 | =end original |
| 5182 | 6260 | |
| 5183 | C<write> 関数で使うピクチャーフォーマットを宣言します。 | |
| 6261 | L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。 | |
| 5184 | 6262 | 例えば: |
| 5185 | 6263 | |
| 5186 | 6264 | format Something = |
| 5187 | 6265 | Test: @<<<<<<<< @||||| @>>>>> |
| 5188 | 6266 | $str, $%, '$' . int($num) |
| 5189 | 6267 | . |
| 5190 | 6268 | |
| 5191 | 6269 | $str = "widget"; |
| 5192 | 6270 | $num = $cost/$quantity; |
| 5193 | 6271 | $~ = 'Something'; |
| 5194 | 6272 | write; |
| 5195 | 6273 | |
| 5196 | 6274 | =begin original |
| 5197 | 6275 | |
| 5198 | 6276 | See L<perlform> for many details and examples. |
| 5199 | 6277 | |
| 5200 | 6278 | =end original |
| 5201 | 6279 | |
| 5202 | 6280 | 詳細と例については L<perlform> を参照してください。 |
| 5203 | 6281 | |
| 5204 | 6282 | =item formline PICTURE,LIST |
| 5205 | 6283 | X<formline> |
| 5206 | 6284 | |
| 5207 | 6285 | =for Pod::Functions internal function used for formats |
| 5208 | 6286 | |
| 5209 | 6287 | =begin original |
| 5210 | 6288 | |
| 5211 | This is an internal function used by C<format>s, though you | |
| 6289 | This is an internal function used by L<C<format>|/format>s, though you | |
| 5212 | too. It formats (see L<perlform>) a list of values | |
| 6290 | may call it, too. It formats (see L<perlform>) a list of values | |
| 5213 | contents of PICTURE, placing the output into the forma | |
| 6291 | according to the contents of PICTURE, placing the output into the format | |
| 5214 | accumulator, C<$^A> (or C<$ACCUMULATOR> in | |
| 6292 | output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in | |
| 5215 | Eventually, when a C<write> is done, | |
| 6293 | L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done, | |
| 5216 | C<$^A> are written to some filehandle. | |
| 6294 | the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle. | |
| 5217 | ||
| 6295 | You could also read L<C<$^A>|perlvar/$^A> and then set | |
| 5218 | ||
| 6296 | L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does | |
| 5219 | ||
| 6297 | one L<C<formline>|/formline PICTURE,LIST> per line of form, but the | |
| 5220 | ||
| 6298 | L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how | |
| 5221 | ||
| 6299 | many newlines are embedded in the PICTURE. This means that the C<~> and | |
| 5222 | ||
| 6300 | C<~~> tokens treat the entire PICTURE as a single line. You may | |
| 6301 | therefore need to use multiple formlines to implement a single record | |
| 6302 | format, just like the L<C<format>|/format> compiler. | |
| 5223 | 6303 | |
| 5224 | 6304 | =end original |
| 5225 | 6305 | |
| 5226 | これは、C<format> が使用する内部関数ですが、直接呼び出すことも | |
| 6306 | これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも | |
| 6307 | できます。 | |
| 5227 | 6308 | これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を |
| 5228 | 参照してください)、結果をフォーマット出力アキュムレータC<$^A> | |
| 6309 | 参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A> | |
| 5229 | (English モジュールでは C<$ACCUMULATOR>) に納めます。 | |
| 6310 | (L<English> モジュールでは C<$ACCUMULATOR>) に納めます。 | |
| 5230 | 最終的に、C<write> が実行されると | |
| 6311 | 最終的に、L<C<write>|/write FILEHANDLE> が実行されると、 | |
| 5231 | 何らかのファイルハンドルに書き出されます。 | |
| 6312 | L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。 | |
| 5232 | また、自分で C<$^A> を読んで、C<$^A> の内容を | |
| 6313 | また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を | |
| 5233 | ||
| 6314 | C<""> に戻してもかまいません。 | |
| 5234 | C<formline> | |
| 6315 | format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST> を | |
| 5235 | ||
| 6316 | 行ないますが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に | |
| 6317 | いくつの改行が入っているかは、関係がありません。 | |
| 5236 | 6318 | これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。 |
| 5237 | 6319 | 従って、1 レコードフォーマットを実装するためには |
| 5238 | ||
| 6320 | L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。 | |
| 5239 | 6321 | |
| 5240 | 6322 | =begin original |
| 5241 | 6323 | |
| 5242 | 6324 | Be careful if you put double quotes around the picture, because an C<@> |
| 5243 | 6325 | character may be taken to mean the beginning of an array name. |
| 5244 | C<formline> always returns true. See | |
| 6326 | L<C<formline>|/formline PICTURE,LIST> always returns true. See | |
| 6327 | L<perlform> for other examples. | |
| 5245 | 6328 | |
| 5246 | 6329 | =end original |
| 5247 | 6330 | |
| 5248 | 6331 | ダブルクォートで PICTURE を囲む場合には、C<@> という文字が |
| 5249 | 6332 | 配列名の始まりと解釈されますので、注意してください。 |
| 5250 | C<formline> は常に真を返します。 | |
| 6333 | L<C<formline>|/formline PICTURE,LIST> は常に真を返します。 | |
| 5251 | 6334 | その他の例については L<perlform> を参照してください。 |
| 5252 | 6335 | |
| 5253 | 6336 | =begin original |
| 5254 | 6337 | |
| 5255 | If you are trying to use this instead of C<write> | |
| 6338 | If you are trying to use this instead of L<C<write>|/write FILEHANDLE> | |
| 5256 | you may find it easier to open a filehandle to a | |
| 6339 | to capture the output, you may find it easier to open a filehandle to a | |
| 5257 | (C<< open $fh, ">", \$output >>) and write to that instead. | |
| 6340 | scalar (C<< open my $fh, ">", \$output >>) and write to that instead. | |
| 5258 | 6341 | |
| 5259 | 6342 | =end original |
| 5260 | 6343 | |
| 5261 | 出力を捕捉するために C<write> の代わりにこれを | |
| 6344 | 出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを | |
| 5262 | スカラにファイルハンドルを開いて | |
| 6345 | 使おうとした場合、スカラにファイルハンドルを開いて | |
| 6346 | (C<< open my $fh, ">", \$output >>)、 | |
| 5263 | 6347 | 代わりにここに出力する方が簡単であることに気付くでしょう。 |
| 5264 | 6348 | |
| 5265 | 6349 | =item getc FILEHANDLE |
| 5266 | 6350 | X<getc> X<getchar> X<character> X<file, read> |
| 5267 | 6351 | |
| 5268 | 6352 | =item getc |
| 5269 | 6353 | |
| 5270 | 6354 | =for Pod::Functions get the next character from the filehandle |
| 5271 | 6355 | |
| 5272 | 6356 | =begin original |
| 5273 | 6357 | |
| 5274 | 6358 | Returns the next character from the input file attached to FILEHANDLE, |
| 5275 | 6359 | or the undefined value at end of file or if there was an error (in |
| 5276 | the latter case C<$!> is set). If FILEHANDLE is omitted, | |
| 6360 | the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted, | |
| 6361 | reads from | |
| 5277 | 6362 | STDIN. This is not particularly efficient. However, it cannot be |
| 5278 | 6363 | used by itself to fetch single characters without waiting for the user |
| 5279 | 6364 | to hit enter. For that, try something more like: |
| 5280 | 6365 | |
| 5281 | 6366 | =end original |
| 5282 | 6367 | |
| 5283 | 6368 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します; |
| 5284 | 6369 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します |
| 5285 | (後者の場合は C<$!> がセットされます)。 | |
| 6370 | (後者の場合は L<C<$!>|perlvar/$!> がセットされます)。 | |
| 5286 | 6371 | FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。 |
| 5287 | 6372 | これは特に効率的ではありません。 |
| 5288 | 6373 | しかし、これはユーザーがリターンキーを押すのを待つことなく |
| 5289 | 6374 | 一文字を読み込む用途には使えません。 |
| 5290 | 6375 | そのような場合には、以下のようなものを試して見てください: |
| 5291 | 6376 | |
| 5292 | 6377 | if ($BSD_STYLE) { |
| 5293 | 6378 | system "stty cbreak </dev/tty >/dev/tty 2>&1"; |
| 5294 | 6379 | } |
| 5295 | 6380 | else { |
| 5296 | 6381 | system "stty", '-icanon', 'eol', "\001"; |
| 5297 | 6382 | } |
| 5298 | 6383 | |
| 5299 | $key = getc(STDIN); | |
| 6384 | my $key = getc(STDIN); | |
| 5300 | 6385 | |
| 5301 | 6386 | if ($BSD_STYLE) { |
| 5302 | 6387 | system "stty -cbreak </dev/tty >/dev/tty 2>&1"; |
| 5303 | 6388 | } |
| 5304 | 6389 | else { |
| 5305 | 6390 | system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL |
| 5306 | 6391 | } |
| 5307 | 6392 | print "\n"; |
| 5308 | 6393 | |
| 5309 | 6394 | =begin original |
| 5310 | 6395 | |
| 5311 | Determination of whether $BSD_STYLE should be set | |
| 6396 | Determination of whether C<$BSD_STYLE> should be set is left as an | |
| 5312 | ||
| 6397 | exercise to the reader. | |
| 5313 | 6398 | |
| 5314 | 6399 | =end original |
| 5315 | 6400 | |
| 5316 | $BSD_STYLE をセットするべきかどうかを決定する方法については | |
| 6401 | C<$BSD_STYLE> をセットするべきかどうかを決定する方法については | |
| 5317 | 6402 | 読者への宿題として残しておきます。 |
| 5318 | 6403 | |
| 5319 | 6404 | =begin original |
| 5320 | 6405 | |
| 5321 | The C<POSIX::getattr> function can do this more | |
| 6406 | The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more | |
| 5322 | systems purporting POSIX compliance. See also the | |
| 6407 | portably on systems purporting POSIX compliance. See also the | |
| 5323 | ||
| 6408 | L<C<Term::ReadKey>|Term::ReadKey> module on CPAN. | |
| 5324 | L<perlmodlib/CPAN>. | |
| 5325 | 6409 | |
| 5326 | 6410 | =end original |
| 5327 | 6411 | |
| 5328 | C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムで | |
| 6412 | L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで | |
| 5329 | より移植性のある形で行います。 | |
| 6413 | これをより移植性のある形で行います。 | |
| 5330 | ||
| 6414 | CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも | |
| 5331 | ||
| 6415 | 参照してください。 | |
| 5332 | 6416 | |
| 5333 | 6417 | =item getlogin |
| 5334 | 6418 | X<getlogin> X<login> |
| 5335 | 6419 | |
| 5336 | 6420 | =for Pod::Functions return who logged in at this tty |
| 5337 | 6421 | |
| 5338 | 6422 | =begin original |
| 5339 | 6423 | |
| 5340 | 6424 | This implements the C library function of the same name, which on most |
| 5341 | 6425 | systems returns the current login from F</etc/utmp>, if any. If it |
| 5342 | returns the empty string, use C<getpwuid>. | |
| 6426 | returns the empty string, use L<C<getpwuid>|/getpwuid UID>. | |
| 5343 | 6427 | |
| 5344 | 6428 | =end original |
| 5345 | 6429 | |
| 5346 | 6430 | これは同じ名前の C ライブラリ関数を実装していて、 |
| 5347 | 多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。 | |
| 6431 | 多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。 | |
| 5348 | もし空文字列が返ってきた場合は、getpwuid | |
| 6432 | もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID> を | |
| 6433 | 使ってください。 | |
| 5349 | 6434 | |
| 5350 | $login = getlogin || getpwuid($<) || "Kilroy"; | |
| 6435 | my $login = getlogin || getpwuid($<) || "Kilroy"; | |
| 5351 | 6436 | |
| 5352 | 6437 | =begin original |
| 5353 | 6438 | |
| 5354 | Do not consider C<getlogin> for authentication: it is not | |
| 6439 | Do not consider L<C<getlogin>|/getlogin> for authentication: it is not | |
| 5355 | secure as C<getpwuid>. | |
| 6440 | as secure as L<C<getpwuid>|/getpwuid UID>. | |
| 5356 | 6441 | |
| 5357 | 6442 | =end original |
| 5358 | 6443 | |
| 5359 | C<getlogin> を認証に使ってはいけません: これは | |
| 6444 | L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは | |
| 5360 | 安全ではありません。 | |
| 6445 | L<C<getpwuid>|/getpwuid UID> のように安全ではありません。 | |
| 5361 | 6446 | |
| 5362 | 6447 | =begin original |
| 5363 | 6448 | |
| 5364 | 6449 | Portability issues: L<perlport/getlogin>. |
| 5365 | 6450 | |
| 5366 | 6451 | =end original |
| 5367 | 6452 | |
| 5368 | 6453 | 移植性の問題: L<perlport/getlogin>。 |
| 5369 | 6454 | |
| 5370 | 6455 | =item getpeername SOCKET |
| 5371 | 6456 | X<getpeername> X<peer> |
| 5372 | 6457 | |
| 5373 | 6458 | =for Pod::Functions find the other end of a socket connection |
| 5374 | 6459 | |
| 5375 | 6460 | =begin original |
| 5376 | 6461 | |
| 5377 | 6462 | Returns the packed sockaddr address of the other end of the SOCKET |
| 5378 | 6463 | connection. |
| 5379 | 6464 | |
| 5380 | 6465 | =end original |
| 5381 | 6466 | |
| 5382 | 6467 | SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。 |
| 5383 | 6468 | |
| 5384 | 6469 | use Socket; |
| 5385 | $hersockaddr = getpeername( | |
| 6470 | my $hersockaddr = getpeername($sock); | |
| 5386 | ($port, $iaddr) = sockaddr_in($hersockaddr); | |
| 6471 | my ($port, $iaddr) = sockaddr_in($hersockaddr); | |
| 5387 | $herhostname = gethostbyaddr($iaddr, AF_INET); | |
| 6472 | my $herhostname = gethostbyaddr($iaddr, AF_INET); | |
| 5388 | $herstraddr = inet_ntoa($iaddr); | |
| 6473 | my $herstraddr = inet_ntoa($iaddr); | |
| 5389 | 6474 | |
| 5390 | 6475 | =item getpgrp PID |
| 5391 | 6476 | X<getpgrp> X<group> |
| 5392 | 6477 | |
| 5393 | 6478 | =for Pod::Functions get process group |
| 5394 | 6479 | |
| 5395 | 6480 | =begin original |
| 5396 | 6481 | |
| 5397 | 6482 | Returns the current process group for the specified PID. Use |
| 5398 | 6483 | a PID of C<0> to get the current process group for the |
| 5399 | 6484 | current process. Will raise an exception if used on a machine that |
| 5400 | doesn't implement getpgrp(2). If PID is omitted, returns the process | |
| 6485 | doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process | |
| 5401 | group of the current process. Note that the POSIX version of | |
| 6486 | group of the current process. Note that the POSIX version of | |
| 5402 | does not accept a PID argument, so only | |
| 6487 | L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only | |
| 6488 | C<PID==0> is truly portable. | |
| 5403 | 6489 | |
| 5404 | 6490 | =end original |
| 5405 | 6491 | |
| 5406 | 6492 | 指定された PID の現在のプロセスグループを返します。 |
| 5407 | 6493 | PID に C<0> を与えるとカレントプロセスの指定となります。 |
| 5408 | getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。 | |
| 6494 | L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。 | |
| 5409 | 6495 | PID を省略するとカレントプロセスのプロセスグループを返します。 |
| 5410 | POSIX 版の C<getpgrp> は PID 引数を受け付けないので、 | |
| 6496 | POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、 | |
| 5411 | 6497 | C<PID==0> のみが完全に移植性があります。 |
| 5412 | 6498 | |
| 5413 | 6499 | =begin original |
| 5414 | 6500 | |
| 5415 | 6501 | Portability issues: L<perlport/getpgrp>. |
| 5416 | 6502 | |
| 5417 | 6503 | =end original |
| 5418 | 6504 | |
| 5419 | 6505 | 移植性の問題: L<perlport/getpgrp>。 |
| 5420 | 6506 | |
| 5421 | 6507 | =item getppid |
| 5422 | 6508 | X<getppid> X<parent> X<pid> |
| 5423 | 6509 | |
| 5424 | 6510 | =for Pod::Functions get parent process ID |
| 5425 | 6511 | |
| 5426 | 6512 | =begin original |
| 5427 | 6513 | |
| 5428 | 6514 | Returns the process id of the parent process. |
| 5429 | 6515 | |
| 5430 | 6516 | =end original |
| 5431 | 6517 | |
| 5432 | 6518 | 親プロセスのプロセス id を返します。 |
| 5433 | 6519 | |
| 5434 | 6520 | =begin original |
| 5435 | 6521 | |
| 5436 | 6522 | Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work |
| 5437 | 6523 | around non-POSIX thread semantics the minority of Linux systems (and |
| 5438 | 6524 | Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation |
| 5439 | has since been removed. See the documentation for L<$$|perlvar/$$> for | |
| 6525 | has since been removed. See the documentation for L<$$|perlvar/$$> for | |
| 5440 | 6526 | details. |
| 5441 | 6527 | |
| 5442 | 6528 | =end original |
| 5443 | 6529 | |
| 5444 | 6530 | Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は |
| 5445 | 6531 | LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな |
| 5446 | 6532 | Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。 |
| 5447 | 6533 | このエミュレーションは削除されました; |
| 5448 | 6534 | 詳しくは L<$$|perlvar/$$> の文書を参照してください。 |
| 5449 | 6535 | |
| 5450 | 6536 | =begin original |
| 5451 | 6537 | |
| 5452 | 6538 | Portability issues: L<perlport/getppid>. |
| 5453 | 6539 | |
| 5454 | 6540 | =end original |
| 5455 | 6541 | |
| 5456 | 6542 | 移植性の問題: L<perlport/getppid>。 |
| 5457 | 6543 | |
| 5458 | 6544 | =item getpriority WHICH,WHO |
| 5459 | 6545 | X<getpriority> X<priority> X<nice> |
| 5460 | 6546 | |
| 5461 | 6547 | =for Pod::Functions get current nice value |
| 5462 | 6548 | |
| 5463 | 6549 | =begin original |
| 5464 | 6550 | |
| 5465 | 6551 | Returns the current priority for a process, a process group, or a user. |
| 5466 | 6552 | (See L<getpriority(2)>.) Will raise a fatal exception if used on a |
| 5467 | machine that doesn't implement getpriority(2). | |
| 6553 | machine that doesn't implement L<getpriority(2)>. | |
| 5468 | 6554 | |
| 5469 | 6555 | =end original |
| 5470 | 6556 | |
| 5471 | 6557 | プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。 |
| 5472 | 6558 | (L<getpriority(2)> を参照してください。) |
| 5473 | getpriority(2) を実装していない | |
| 6559 | L<getpriority(2)> を実装していない | |
| 5474 | 6560 | マシンで実行した場合には、致命的例外が発生します。 |
| 5475 | 6561 | |
| 5476 | 6562 | =begin original |
| 5477 | 6563 | |
| 6564 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
| 6565 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
| 6566 | ||
| 6567 | =end original | |
| 6568 | ||
| 6569 | C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
| 6570 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
| 6571 | ||
| 6572 | =begin original | |
| 6573 | ||
| 5478 | 6574 | Portability issues: L<perlport/getpriority>. |
| 5479 | 6575 | |
| 5480 | 6576 | =end original |
| 5481 | 6577 | |
| 5482 | 6578 | 移植性の問題: L<perlport/getpriority>。 |
| 5483 | 6579 | |
| 5484 | 6580 | =item getpwnam NAME |
| 5485 | 6581 | X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname> |
| 5486 | 6582 | X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr> |
| 5487 | 6583 | X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent> |
| 5488 | 6584 | X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent> |
| 5489 | 6585 | X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent> |
| 5490 | X<endnetent> X<endprotoent> X<endservent> | |
| 6586 | X<endnetent> X<endprotoent> X<endservent> | |
| 5491 | 6587 | |
| 5492 | 6588 | =for Pod::Functions get passwd record given user login name |
| 5493 | 6589 | |
| 5494 | 6590 | =item getgrnam NAME |
| 5495 | 6591 | |
| 5496 | 6592 | =for Pod::Functions get group record given group name |
| 5497 | 6593 | |
| 5498 | 6594 | =item gethostbyname NAME |
| 5499 | 6595 | |
| 5500 | 6596 | =for Pod::Functions get host record given name |
| 5501 | 6597 | |
| 5502 | 6598 | =item getnetbyname NAME |
| 5503 | 6599 | |
| 5504 | 6600 | =for Pod::Functions get networks record given name |
| 5505 | 6601 | |
| 5506 | 6602 | =item getprotobyname NAME |
| 5507 | 6603 | |
| 5508 | 6604 | =for Pod::Functions get protocol record given name |
| 5509 | 6605 | |
| 5510 | 6606 | =item getpwuid UID |
| 5511 | 6607 | |
| 5512 | 6608 | =for Pod::Functions get passwd record given user ID |
| 5513 | 6609 | |
| 5514 | 6610 | =item getgrgid GID |
| 5515 | 6611 | |
| 5516 | 6612 | =for Pod::Functions get group record given group user ID |
| 5517 | 6613 | |
| 5518 | 6614 | =item getservbyname NAME,PROTO |
| 5519 | 6615 | |
| 5520 | 6616 | =for Pod::Functions get services record given its name |
| 5521 | 6617 | |
| 5522 | 6618 | =item gethostbyaddr ADDR,ADDRTYPE |
| 5523 | 6619 | |
| 5524 | 6620 | =for Pod::Functions get host record given its address |
| 5525 | 6621 | |
| 5526 | 6622 | =item getnetbyaddr ADDR,ADDRTYPE |
| 5527 | 6623 | |
| 5528 | 6624 | =for Pod::Functions get network record given its address |
| 5529 | 6625 | |
| 5530 | 6626 | =item getprotobynumber NUMBER |
| 5531 | 6627 | |
| 5532 | 6628 | =for Pod::Functions get protocol record numeric protocol |
| 5533 | 6629 | |
| 5534 | 6630 | =item getservbyport PORT,PROTO |
| 5535 | 6631 | |
| 5536 | 6632 | =for Pod::Functions get services record given numeric port |
| 5537 | 6633 | |
| 5538 | 6634 | =item getpwent |
| 5539 | 6635 | |
| 5540 | 6636 | =for Pod::Functions get next passwd record |
| 5541 | 6637 | |
| 5542 | 6638 | =item getgrent |
| 5543 | 6639 | |
| 5544 | 6640 | =for Pod::Functions get next group record |
| 5545 | 6641 | |
| 5546 | 6642 | =item gethostent |
| 5547 | 6643 | |
| 5548 | 6644 | =for Pod::Functions get next hosts record |
| 5549 | 6645 | |
| 5550 | 6646 | =item getnetent |
| 5551 | 6647 | |
| 5552 | 6648 | =for Pod::Functions get next networks record |
| 5553 | 6649 | |
| 5554 | 6650 | =item getprotoent |
| 5555 | 6651 | |
| 5556 | 6652 | =for Pod::Functions get next protocols record |
| 5557 | 6653 | |
| 5558 | 6654 | =item getservent |
| 5559 | 6655 | |
| 5560 | 6656 | =for Pod::Functions get next services record |
| 5561 | 6657 | |
| 5562 | 6658 | =item setpwent |
| 5563 | 6659 | |
| 5564 | 6660 | =for Pod::Functions prepare passwd file for use |
| 5565 | 6661 | |
| 5566 | 6662 | =item setgrent |
| 5567 | 6663 | |
| 5568 | 6664 | =for Pod::Functions prepare group file for use |
| 5569 | 6665 | |
| 5570 | 6666 | =item sethostent STAYOPEN |
| 5571 | 6667 | |
| 5572 | 6668 | =for Pod::Functions prepare hosts file for use |
| 5573 | 6669 | |
| 5574 | 6670 | =item setnetent STAYOPEN |
| 5575 | 6671 | |
| 5576 | 6672 | =for Pod::Functions prepare networks file for use |
| 5577 | 6673 | |
| 5578 | 6674 | =item setprotoent STAYOPEN |
| 5579 | 6675 | |
| 5580 | 6676 | =for Pod::Functions prepare protocols file for use |
| 5581 | 6677 | |
| 5582 | 6678 | =item setservent STAYOPEN |
| 5583 | 6679 | |
| 5584 | 6680 | =for Pod::Functions prepare services file for use |
| 5585 | 6681 | |
| 5586 | 6682 | =item endpwent |
| 5587 | 6683 | |
| 5588 | 6684 | =for Pod::Functions be done using passwd file |
| 5589 | 6685 | |
| 5590 | 6686 | =item endgrent |
| 5591 | 6687 | |
| 5592 | 6688 | =for Pod::Functions be done using group file |
| 5593 | 6689 | |
| 5594 | 6690 | =item endhostent |
| 5595 | 6691 | |
| 5596 | 6692 | =for Pod::Functions be done using hosts file |
| 5597 | 6693 | |
| 5598 | 6694 | =item endnetent |
| 5599 | 6695 | |
| 5600 | 6696 | =for Pod::Functions be done using networks file |
| 5601 | 6697 | |
| 5602 | 6698 | =item endprotoent |
| 5603 | 6699 | |
| 5604 | 6700 | =for Pod::Functions be done using protocols file |
| 5605 | 6701 | |
| 5606 | 6702 | =item endservent |
| 5607 | 6703 | |
| 5608 | 6704 | =for Pod::Functions be done using services file |
| 5609 | 6705 | |
| 5610 | 6706 | =begin original |
| 5611 | 6707 | |
| 5612 | 6708 | These routines are the same as their counterparts in the |
| 5613 | 6709 | system C library. In list context, the return values from the |
| 5614 | 6710 | various get routines are as follows: |
| 5615 | 6711 | |
| 5616 | 6712 | =end original |
| 5617 | 6713 | |
| 5618 | 6714 | これらのルーチンは、システムの C ライブラリの同名の関数と同じです。 |
| 5619 | 6715 | リストコンテキストでは、さまざまな |
| 5620 | 6716 | get ルーチンからの返り値は、次のようになります: |
| 5621 | 6717 | |
| 5622 | | |
| 6718 | # 0 1 2 3 4 | |
| 5623 | | |
| 6719 | my ( $name, $passwd, $gid, $members ) = getgr* | |
| 5624 | | |
| 6720 | my ( $name, $aliases, $addrtype, $net ) = getnet* | |
| 5625 | | |
| 6721 | my ( $name, $aliases, $port, $proto ) = getserv* | |
| 5626 | | |
| 6722 | my ( $name, $aliases, $proto ) = getproto* | |
| 5627 | | |
| 6723 | my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost* | |
| 5628 | | |
| 6724 | my ( $name, $passwd, $uid, $gid, $quota, | |
| 6725 | $comment, $gcos, $dir, $shell, $expire ) = getpw* | |
| 6726 | # 5 6 7 8 9 | |
| 5629 | 6727 | |
| 5630 | 6728 | =begin original |
| 5631 | 6729 | |
| 5632 | (If the entry doesn't exist | |
| 6730 | (If the entry doesn't exist, the return value is a single meaningless true | |
| 6731 | value.) | |
| 5633 | 6732 | |
| 5634 | 6733 | =end original |
| 5635 | 6734 | |
| 5636 | (エントリが存在しなければ、 | |
| 6735 | (エントリが存在しなければ、返り値は単一の意味のない真の値です。) | |
| 5637 | 6736 | |
| 5638 | 6737 | =begin original |
| 5639 | 6738 | |
| 5640 | 6739 | The exact meaning of the $gcos field varies but it usually contains |
| 5641 | 6740 | the real name of the user (as opposed to the login name) and other |
| 5642 | 6741 | information pertaining to the user. Beware, however, that in many |
| 5643 | 6742 | system users are able to change this information and therefore it |
| 5644 | 6743 | cannot be trusted and therefore the $gcos is tainted (see |
| 5645 | 6744 | L<perlsec>). The $passwd and $shell, user's encrypted password and |
| 5646 | 6745 | login shell, are also tainted, for the same reason. |
| 5647 | 6746 | |
| 5648 | 6747 | =end original |
| 5649 | 6748 | |
| 5650 | 6749 | $gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく) |
| 5651 | 6750 | ユーザーの実際の名前とユーザーに付随する情報を含みます。 |
| 5652 | 6751 | 但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は |
| 5653 | 6752 | 信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。 |
| 5654 | 6753 | ユーザーの暗号化されたパスワードとログインシェルである $passwd と |
| 5655 | 6754 | $shell も、同様の理由で汚染されます。 |
| 5656 | 6755 | |
| 5657 | 6756 | =begin original |
| 5658 | 6757 | |
| 5659 | 6758 | In scalar context, you get the name, unless the function was a |
| 5660 | 6759 | lookup by name, in which case you get the other thing, whatever it is. |
| 5661 | 6760 | (If the entry doesn't exist you get the undefined value.) For example: |
| 5662 | 6761 | |
| 5663 | 6762 | =end original |
| 5664 | 6763 | |
| 5665 | 6764 | スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、 |
| 5666 | 6765 | name を返し、NAME で検索するものは、何か別のものを返します。 |
| 5667 | 6766 | (エントリが存在しなければ、未定義値が返ります。) |
| 5668 | 6767 | 例えば: |
| 5669 | 6768 | |
| 5670 | $uid = getpwnam($name); | |
| 6769 | my $uid = getpwnam($name); | |
| 5671 | $name = getpwuid($num); | |
| 6770 | my $name = getpwuid($num); | |
| 5672 | $name = getpwent(); | |
| 6771 | my $name = getpwent(); | |
| 5673 | $gid = getgrnam($name); | |
| 6772 | my $gid = getgrnam($name); | |
| 5674 | $name = getgrgid($num); | |
| 6773 | my $name = getgrgid($num); | |
| 5675 | $name = getgrent(); | |
| 6774 | my $name = getgrent(); | |
| 5676 | #etc. | |
| 6775 | <#ins> etc. | |
| 5677 | 6776 | |
| 5678 | 6777 | =begin original |
| 5679 | 6778 | |
| 5680 | 6779 | In I<getpw*()> the fields $quota, $comment, and $expire are special |
| 5681 | 6780 | in that they are unsupported on many systems. If the |
| 5682 | 6781 | $quota is unsupported, it is an empty scalar. If it is supported, it |
| 5683 | 6782 | usually encodes the disk quota. If the $comment field is unsupported, |
| 5684 | 6783 | it is an empty scalar. If it is supported it usually encodes some |
| 5685 | 6784 | administrative comment about the user. In some systems the $quota |
| 5686 | 6785 | field may be $change or $age, fields that have to do with password |
| 5687 | 6786 | aging. In some systems the $comment field may be $class. The $expire |
| 5688 | 6787 | field, if present, encodes the expiration period of the account or the |
| 5689 | 6788 | password. For the availability and the exact meaning of these fields |
| 5690 | in your system, please consult getpwnam(3) and your system's | |
| 6789 | in your system, please consult L<getpwnam(3)> and your system's | |
| 5691 | 6790 | F<pwd.h> file. You can also find out from within Perl what your |
| 5692 | 6791 | $quota and $comment fields mean and whether you have the $expire field |
| 5693 | by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>, | |
| 6792 | by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>, | |
| 5694 | 6793 | C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password |
| 5695 | 6794 | files are supported only if your vendor has implemented them in the |
| 5696 | 6795 | intuitive fashion that calling the regular C library routines gets the |
| 5697 | 6796 | shadow versions if you're running under privilege or if there exists |
| 5698 | the shadow(3) functions as found in System V (this includes Solaris | |
| 6797 | the L<shadow(3)> functions as found in System V (this includes Solaris | |
| 5699 | 6798 | and Linux). Those systems that implement a proprietary shadow password |
| 5700 | 6799 | facility are unlikely to be supported. |
| 5701 | 6800 | |
| 5702 | 6801 | =end original |
| 5703 | 6802 | |
| 5704 | 6803 | I<getpw*()> では、$quota, $comment, $expire フィールドは、 |
| 5705 | 6804 | 多くのシステムでは対応していないので特別な処理がされます。 |
| 5706 | 6805 | $quota が非対応の場合、空のスカラになります。 |
| 5707 | 6806 | 対応している場合、通常はディスククォータの値が入ります。 |
| 5708 | 6807 | $comment フィールドが非対応の場合、空のスカラになります。 |
| 5709 | 6808 | 対応している場合、通常はユーザーに関する管理上のコメントが入ります。 |
| 5710 | 6809 | $quota フィールドはパスワードの寿命を示す $change や $age である |
| 5711 | 6810 | システムもあります。 |
| 5712 | 6811 | $comment フィールドは $class であるシステムもあります。 |
| 5713 | 6812 | $expire フィールドがある場合は、アカウントやパスワードが時間切れになる |
| 5714 | 6813 | 期間が入ります。 |
| 5715 | 6814 | 動作させるシステムでのこれらのフィールドの有効性と正確な意味については、 |
| 5716 | getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。 | |
| 6815 | L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。 | |
| 5717 | 6816 | $quota と $comment フィールドが何を意味しているかと、$expire フィールドが |
| 5718 | あるかどうかは、C<Config> モジュールを使って、C<d_pwquota | |
| 6817 | あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>, | |
| 5719 | C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を | |
| 6818 | C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を | |
| 5720 | Perl 自身で調べることも出来ます。 | |
| 6819 | 調べることによって Perl 自身で調べることも出来ます。 | |
| 5721 | 6820 | シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で |
| 5722 | 6821 | 呼び出すことでシャドウ版が取得できるか、System V にあるような |
| 5723 | (Solaris と Linux を含みます) shadow(3) 関数があるといった、 | |
| 6822 | (Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、 | |
| 5724 | 6823 | 直感的な方法で実装されている場合にのみ対応されます。 |
| 5725 | 6824 | 独占的なシャドウパスワード機能を実装しているシステムでは、 |
| 5726 | 6825 | それに対応されることはないでしょう。 |
| 5727 | 6826 | |
| 5728 | 6827 | =begin original |
| 5729 | 6828 | |
| 5730 | 6829 | The $members value returned by I<getgr*()> is a space-separated list of |
| 5731 | 6830 | the login names of the members of the group. |
| 5732 | 6831 | |
| 5733 | 6832 | =end original |
| 5734 | 6833 | |
| 5735 | 6834 | I<getgr*()> によって返る値 $members は、グループのメンバの |
| 5736 | 6835 | ログイン名をスペースで区切ったものです。 |
| 5737 | 6836 | |
| 5738 | 6837 | =begin original |
| 5739 | 6838 | |
| 5740 | 6839 | For the I<gethost*()> functions, if the C<h_errno> variable is supported in |
| 5741 | C, it will be returned to you via C<$?> if the function | |
| 6840 | C, it will be returned to you via L<C<$?>|perlvar/$?> if the function | |
| 6841 | call fails. The | |
| 5742 | 6842 | C<@addrs> value returned by a successful call is a list of raw |
| 5743 | 6843 | addresses returned by the corresponding library call. In the |
| 5744 | 6844 | Internet domain, each address is four bytes long; you can unpack it |
| 5745 | 6845 | by saying something like: |
| 5746 | 6846 | |
| 5747 | 6847 | =end original |
| 5748 | 6848 | |
| 5749 | 6849 | I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、 |
| 5750 | 関数呼出が失敗したときに、C<$?> を通して、その値が返されます。 | |
| 6850 | 関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。 | |
| 5751 | 6851 | 成功時に返される C<@addrs> 値は、対応するシステムコールが返す、 |
| 5752 | 6852 | 生のアドレスのリストです。 |
| 5753 | 6853 | インターネットドメインでは、個々のアドレスは、4 バイト長です; |
| 5754 | 6854 | 以下のようにして unpack することができます: |
| 5755 | 6855 | |
| 5756 | ($ | |
| 6856 | my ($w,$x,$y,$z) = unpack('W4',$addr[0]); | |
| 5757 | 6857 | |
| 5758 | 6858 | =begin original |
| 5759 | 6859 | |
| 5760 | 6860 | The Socket library makes this slightly easier: |
| 5761 | 6861 | |
| 5762 | 6862 | =end original |
| 5763 | 6863 | |
| 5764 | 6864 | Socket ライブラリを使うともう少し簡単になります。 |
| 5765 | 6865 | |
| 5766 | 6866 | use Socket; |
| 5767 | $iaddr = inet_aton("127.1"); # or whatever address | |
| 6867 | my $iaddr = inet_aton("127.1"); # or whatever address | |
| 5768 | $name = gethostbyaddr($iaddr, AF_INET); | |
| 6868 | my $name = gethostbyaddr($iaddr, AF_INET); | |
| 5769 | 6869 | |
| 5770 | 6870 | # or going the other way |
| 5771 | $straddr = inet_ntoa($iaddr); | |
| 6871 | my $straddr = inet_ntoa($iaddr); | |
| 5772 | 6872 | |
| 5773 | 6873 | =begin original |
| 5774 | 6874 | |
| 5775 | 6875 | In the opposite way, to resolve a hostname to the IP address |
| 5776 | 6876 | you can write this: |
| 5777 | 6877 | |
| 5778 | 6878 | =end original |
| 5779 | 6879 | |
| 5780 | 6880 | 逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます: |
| 5781 | 6881 | |
| 5782 | 6882 | use Socket; |
| 5783 | $packed_ip = gethostbyname("www.perl.org"); | |
| 6883 | my $packed_ip = gethostbyname("www.perl.org"); | |
| 6884 | my $ip_address; | |
| 5784 | 6885 | if (defined $packed_ip) { |
| 5785 | 6886 | $ip_address = inet_ntoa($packed_ip); |
| 5786 | 6887 | } |
| 5787 | 6888 | |
| 5788 | 6889 | =begin original |
| 5789 | 6890 | |
| 5790 | Make sure C<gethostbyname | |
| 6891 | Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR | |
| 5791 | its return value is checked for definedness. | |
| 6892 | context and that its return value is checked for definedness. | |
| 5792 | 6893 | |
| 5793 | 6894 | =end original |
| 5794 | 6895 | |
| 5795 | C<gethostbyname | |
| 6896 | L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで | |
| 5796 | 定義されているかを必ずチェックしてください。 | |
| 6897 | 呼び出すようにして、返り値が定義されているかを必ずチェックしてください。 | |
| 5797 | 6898 | |
| 5798 | 6899 | =begin original |
| 5799 | 6900 | |
| 5800 | The C<getprotobynumber> function, even | |
| 6901 | The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even | |
| 5801 | has the precedence of a list | |
| 6902 | though it only takes one argument, has the precedence of a list | |
| 6903 | operator, so beware: | |
| 5802 | 6904 | |
| 5803 | 6905 | =end original |
| 5804 | 6906 | |
| 5805 | C<getprotobynumber> 関数は、一つの引数しか | |
| 6907 | L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか | |
| 5806 | 演算子の優先順位を持ちます; 従って | |
| 6908 | 取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って | |
| 6909 | 注意してください: | |
| 5807 | 6910 | |
| 5808 | 6911 | getprotobynumber $number eq 'icmp' # WRONG |
| 5809 | 6912 | getprotobynumber($number eq 'icmp') # actually means this |
| 5810 | 6913 | getprotobynumber($number) eq 'icmp' # better this way |
| 5811 | 6914 | |
| 5812 | 6915 | =begin original |
| 5813 | 6916 | |
| 5814 | 6917 | If you get tired of remembering which element of the return list |
| 5815 | contains which return value, by-name interfaces are provided | |
| 6918 | contains which return value, by-name interfaces are provided in standard | |
| 5816 | ||
| 6919 | modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, | |
| 5817 | C<Net:: | |
| 6920 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, | |
| 5818 | ||
| 6921 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, | |
| 5819 | ||
| 6922 | L<C<Time::localtime>|Time::localtime>, and | |
| 5820 | ||
| 6923 | L<C<User::grent>|User::grent>. These override the normal built-ins, | |
| 6924 | supplying versions that return objects with the appropriate names for | |
| 6925 | each field. For example: | |
| 5821 | 6926 | |
| 5822 | 6927 | =end original |
| 5823 | 6928 | |
| 5824 | 6929 | 返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、 |
| 5825 | 6930 | 名前ベースのインターフェースが標準モジュールで提供されています: |
| 5826 | C<File::stat>, C<Net::hostent> | |
| 6931 | L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>, | |
| 5827 | C<Net:: | |
| 6932 | L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>, | |
| 5828 | C< | |
| 6933 | L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>, | |
| 6934 | L<C<Time::localtime>|Time::localtime>, | |
| 6935 | L<C<User::grent>|User::grent> です。 | |
| 5829 | 6936 | これらは通常の組み込みを上書きし、 |
| 5830 | 6937 | それぞれのフィールドに適切な名前をつけたオブジェクトを返します。 |
| 5831 | 6938 | 例えば: |
| 5832 | 6939 | |
| 5833 | 6940 | use File::stat; |
| 5834 | 6941 | use User::pwent; |
| 5835 | $is_his = (stat($filename)->uid == pwent($whoever)->uid); | |
| 6942 | my $is_his = (stat($filename)->uid == pwent($whoever)->uid); | |
| 5836 | 6943 | |
| 5837 | 6944 | =begin original |
| 5838 | 6945 | |
| 5839 | 6946 | Even though it looks as though they're the same method calls (uid), |
| 5840 | 6947 | they aren't, because a C<File::stat> object is different from |
| 5841 | 6948 | a C<User::pwent> object. |
| 5842 | 6949 | |
| 5843 | 6950 | =end original |
| 5844 | 6951 | |
| 5845 | 6952 | 同じメソッド(uid)を呼び出しているように見えますが、違います; |
| 5846 | 6953 | なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは |
| 5847 | 6954 | 異なるからです。 |
| 5848 | 6955 | |
| 5849 | 6956 | =begin original |
| 5850 | 6957 | |
| 6958 | Many of these functions are not safe in a multi-threaded environment | |
| 6959 | where more than one thread can be using them. In particular, functions | |
| 6960 | like C<getpwent()> iterate per-process and not per-thread, so if two | |
| 6961 | threads are simultaneously iterating, neither will get all the records. | |
| 6962 | ||
| 6963 | =end original | |
| 6964 | ||
| 6965 | これらの関数の多くは、複数のスレッドがこれらを使うような | |
| 6966 | マルチスレッド環境では安全ではありません。 | |
| 6967 | 特に、 | |
| 6968 | C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で | |
| 6969 | 反復するので、二つのスレッドが同時に反復すると、 | |
| 6970 | どちらも全てのレコードを得られません。 | |
| 6971 | ||
| 6972 | =begin original | |
| 6973 | ||
| 6974 | Some systems have thread-safe versions of some of the functions, such as | |
| 6975 | C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and | |
| 6976 | invisibly substitutes the thread-safe version, without notice. This | |
| 6977 | means that code that safely runs on some systems can fail on others that | |
| 6978 | lack the thread-safe versions. | |
| 6979 | ||
| 6980 | =end original | |
| 6981 | ||
| 6982 | 一部のシステムは、 | |
| 6983 | C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について | |
| 6984 | スレッドセーフ版を持っています。 | |
| 6985 | その場合、Perl は自動的かつ目に見えないように、通知なしで | |
| 6986 | スレッドセーフ版に置き換えます。 | |
| 6987 | つまり、一部のシステムで安全に実行できるコードが | |
| 6988 | スレッドセーフ版のないその他のシステムでは失敗することがあるということです。 | |
| 6989 | ||
| 6990 | =begin original | |
| 6991 | ||
| 5851 | 6992 | Portability issues: L<perlport/getpwnam> to L<perlport/endservent>. |
| 5852 | 6993 | |
| 5853 | 6994 | =end original |
| 5854 | 6995 | |
| 5855 | 6996 | 移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。 |
| 5856 | 6997 | |
| 5857 | 6998 | =item getsockname SOCKET |
| 5858 | 6999 | X<getsockname> |
| 5859 | 7000 | |
| 5860 | 7001 | =for Pod::Functions retrieve the sockaddr for a given socket |
| 5861 | 7002 | |
| 5862 | 7003 | =begin original |
| 5863 | 7004 | |
| 5864 | 7005 | Returns the packed sockaddr address of this end of the SOCKET connection, |
| 5865 | 7006 | in case you don't know the address because you have several different |
| 5866 | 7007 | IPs that the connection might have come in on. |
| 5867 | 7008 | |
| 5868 | 7009 | =end original |
| 5869 | 7010 | |
| 5870 | 7011 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します; |
| 5871 | 7012 | 複数の異なる IP から接続されるためにアドレスがわからない場合に使います。 |
| 5872 | 7013 | |
| 5873 | 7014 | use Socket; |
| 5874 | $mysockaddr = getsockname( | |
| 7015 | my $mysockaddr = getsockname($sock); | |
| 5875 | ($port, $myaddr) = sockaddr_in($mysockaddr); | |
| 7016 | my ($port, $myaddr) = sockaddr_in($mysockaddr); | |
| 5876 | 7017 | printf "Connect to %s [%s]\n", |
| 5877 | 7018 | scalar gethostbyaddr($myaddr, AF_INET), |
| 5878 | 7019 | inet_ntoa($myaddr); |
| 5879 | 7020 | |
| 5880 | 7021 | =item getsockopt SOCKET,LEVEL,OPTNAME |
| 5881 | 7022 | X<getsockopt> |
| 5882 | 7023 | |
| 5883 | 7024 | =for Pod::Functions get socket options on a given socket |
| 5884 | 7025 | |
| 5885 | 7026 | =begin original |
| 5886 | 7027 | |
| 5887 | 7028 | Queries the option named OPTNAME associated with SOCKET at a given LEVEL. |
| 5888 | 7029 | Options may exist at multiple protocol levels depending on the socket |
| 5889 | 7030 | type, but at least the uppermost socket level SOL_SOCKET (defined in the |
| 5890 | C<Socket> module) will exist. To query options at another | |
| 7031 | L<C<Socket>|Socket> module) will exist. To query options at another | |
| 5891 | protocol number of the appropriate protocol controlling the | |
| 7032 | level the protocol number of the appropriate protocol controlling the | |
| 5892 | should be supplied. For example, to indicate that an option is | |
| 7033 | option should be supplied. For example, to indicate that an option is | |
| 5893 | interpreted by the TCP protocol, LEVEL should be set to the | |
| 7034 | to be interpreted by the TCP protocol, LEVEL should be set to the | |
| 5894 | number of TCP, which you can get using | |
| 7035 | protocol number of TCP, which you can get using | |
| 7036 | L<C<getprotobyname>|/getprotobyname NAME>. | |
| 5895 | 7037 | |
| 5896 | 7038 | =end original |
| 5897 | 7039 | |
| 5898 | 7040 | 与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを |
| 5899 | 7041 | 問い合わせます。 |
| 5900 | 7042 | オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも |
| 5901 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET | |
| 7043 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET | |
| 5902 | 定義されています)は存在します。 | |
| 7044 | (L<C<Socket>|Socket> モジュールで定義されています)は存在します。 | |
| 5903 | 7045 | その他のレベルのオプションを問い合わせるには、そのオプションを制御する |
| 5904 | 7046 | 適切なプロトコルのプロトコル番号を指定します。 |
| 5905 | 7047 | 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 |
| 5906 | LEVEL は C<getprotobyname> で得られる TCP の | |
| 7048 | LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の | |
| 7049 | プロトコル番号を設定します。 | |
| 5907 | 7050 | |
| 5908 | 7051 | =begin original |
| 5909 | 7052 | |
| 5910 | 7053 | The function returns a packed string representing the requested socket |
| 5911 | option, or C<undef> on error, with the reason for the | |
| 7054 | option, or L<C<undef>|/undef EXPR> on error, with the reason for the | |
| 5912 | C<$!>. Just what is in the packed string | |
| 7055 | error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string | |
| 5913 | consult getsockopt(2) for details. A | |
| 7056 | depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A | |
| 5914 | ||
| 7057 | common case is that the option is an integer, in which case the result | |
| 5915 | ||
| 7058 | is a packed integer, which you can decode using | |
| 7059 | L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format. | |
| 5916 | 7060 | |
| 5917 | 7061 | =end original |
| 5918 | 7062 | |
| 5919 | 7063 | この関数は、要求されたソケットオプションの pack された文字列表現か、 |
| 5920 | あるいはエラーの場合は C<undef> を返し、エラーの理由は | |
| 7064 | あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は | |
| 7065 | L<C<$!>|perlvar/$!> にあります。 | |
| 5921 | 7066 | pack された文字列の中身は LEVEL と OPTNAME に依存します; |
| 5922 | 詳細については getsockopt(2) を確認してください。 | |
| 7067 | 詳細については L<getsockopt(2)> を確認してください。 | |
| 5923 | 一般的な場合はオプションが整数の場合で、この場合結果は | |
| 7068 | 一般的な場合はオプションが整数の場合で、この場合結果は | |
| 7069 | L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i> | |
| 5924 | 7070 | (あるいは C<I>)フォーマットでデコードできる pack された整数です。 |
| 5925 | 7071 | |
| 5926 | 7072 | =begin original |
| 5927 | 7073 | |
| 5928 | 7074 | Here's an example to test whether Nagle's algorithm is enabled on a socket: |
| 5929 | 7075 | |
| 5930 | 7076 | =end original |
| 5931 | 7077 | |
| 5932 | 7078 | あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です: |
| 5933 | 7079 | |
| 5934 | 7080 | use Socket qw(:all); |
| 5935 | 7081 | |
| 5936 | 7082 | defined(my $tcp = getprotobyname("tcp")) |
| 5937 | 7083 | or die "Could not determine the protocol number for tcp"; |
| 5938 | 7084 | # my $tcp = IPPROTO_TCP; # Alternative |
| 5939 | 7085 | my $packed = getsockopt($socket, $tcp, TCP_NODELAY) |
| 5940 | 7086 | or die "getsockopt TCP_NODELAY: $!"; |
| 5941 | 7087 | my $nodelay = unpack("I", $packed); |
| 5942 | 7088 | print "Nagle's algorithm is turned ", |
| 5943 | 7089 | $nodelay ? "off\n" : "on\n"; |
| 5944 | 7090 | |
| 5945 | 7091 | =begin original |
| 5946 | 7092 | |
| 5947 | 7093 | Portability issues: L<perlport/getsockopt>. |
| 5948 | 7094 | |
| 5949 | 7095 | =end original |
| 5950 | 7096 | |
| 5951 | 7097 | 移植性の問題: L<perlport/getsockopt>。 |
| 5952 | 7098 | |
| 5953 | 7099 | =item glob EXPR |
| 5954 | 7100 | X<glob> X<wildcard> X<filename, expansion> X<expand> |
| 5955 | 7101 | |
| 5956 | 7102 | =item glob |
| 5957 | 7103 | |
| 5958 | 7104 | =for Pod::Functions expand filenames using wildcards |
| 5959 | 7105 | |
| 5960 | 7106 | =begin original |
| 5961 | 7107 | |
| 5962 | 7108 | In list context, returns a (possibly empty) list of filename expansions on |
| 5963 | the value of EXPR such as the | |
| 7109 | the value of EXPR such as the Unix shell Bash would do. In | |
| 5964 | 7110 | scalar context, glob iterates through such filename expansions, returning |
| 5965 | undef when the list is exhausted. | |
| 7111 | L<C<undef>|/undef EXPR> when the list is exhausted. If EXPR is omitted, | |
| 5966 | ||
| 7112 | L<C<$_>|perlvar/$_> is used. | |
| 5967 | EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in | |
| 5968 | more detail in L<perlop/"I/O Operators">. | |
| 5969 | 7113 | |
| 5970 | 7114 | =end original |
| 5971 | 7115 | |
| 5972 | 7116 | リストコンテキストでは、 |
| 5973 | EXPR の値を、 | |
| 7117 | EXPR の値を、Unix シェルの Bash が行なうように | |
| 5974 | 7118 | ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 |
| 5975 | 7119 | スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 |
| 5976 | リストがなくなったら undef を返します。 | |
| 7120 | リストがなくなったら L<C<undef>|/undef EXPR> を返します。 | |
| 5977 | ||
| 7121 | EXPR が省略されると、L<C<$_>|perlvar/$_> が使われます。 | |
| 5978 | 直接使用することもできます。 | |
| 5979 | EXPR が省略されると、C<$_> が使われます。 | |
| 5980 | C<< <*.c> >>演算子については | |
| 5981 | L<perlop/"I/O Operators"> でより詳細に議論しています。 | |
| 5982 | 7122 | |
| 7123 | # List context | |
| 7124 | my @txt_files = glob("*.txt"); | |
| 7125 | my @perl_files = glob("*.pl *.pm"); | |
| 7126 | ||
| 7127 | # Scalar context | |
| 7128 | while (my $file = glob("*.mp3")) { | |
| 7129 | # Do stuff | |
| 7130 | } | |
| 7131 | ||
| 5983 | 7132 | =begin original |
| 5984 | 7133 | |
| 5985 | ||
| 7134 | Glob also supports an alternate syntax using C<< < >> C<< > >> as | |
| 5986 | e | |
| 7135 | delimiters. While this syntax is supported, it is recommended that you | |
| 7136 | use C<glob> instead as it is more readable and searchable. | |
| 7137 | ||
| 7138 | =end original | |
| 7139 | ||
| 7140 | glob はまた区切り文字として C<< < >> C<< > >> を使うもう一つの文法に | |
| 7141 | 対応しています。 | |
| 7142 | この文法は対応していますが、可読性と検索性がより高いので、代わりに | |
| 7143 | C<glob> を使うことを勧めます。 | |
| 7144 | ||
| 7145 | my @txt_files = <"*.txt">; | |
| 7146 | ||
| 7147 | =begin original | |
| 7148 | ||
| 7149 | If you need case insensitive file globbing that can be achieved using the | |
| 7150 | C<:nocase> parameter of the L<C<bsd_glob>|File::Glob/C<bsd_glob>> module. | |
| 7151 | ||
| 7152 | =end original | |
| 7153 | ||
| 7154 | 大文字小文字を区別するファイルグロブが必要な場合、 | |
| 7155 | L<C<bsd_glob>|File::Glob/C<bsd_glob>> モジュールの C<:nocase> 引数を | |
| 7156 | 使うことで達成できます: | |
| 7157 | ||
| 7158 | use File::Glob qw(:globally :nocase); | |
| 7159 | ||
| 7160 | my @txt = glob("readme*"); # README readme.txt Readme.md | |
| 7161 | ||
| 7162 | =begin original | |
| 7163 | ||
| 7164 | Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and | |
| 7165 | treats | |
| 7166 | each segment as separate pattern. As such, C<glob("*.c *.h")> | |
| 5987 | 7167 | matches all files with a F<.c> or F<.h> extension. The expression |
| 5988 | 7168 | C<glob(".* *")> matches all files in the current working directory. |
| 5989 | 7169 | If you want to glob filenames that might contain whitespace, you'll |
| 5990 | 7170 | have to use extra quotes around the spacey filename to protect it. |
| 5991 | 7171 | For example, to glob filenames that have an C<e> followed by a space |
| 5992 | followed by an C<f>, use e | |
| 7172 | followed by an C<f>, use one of: | |
| 5993 | 7173 | |
| 5994 | 7174 | =end original |
| 5995 | 7175 | |
| 5996 | C<glob> は引数を空白で分割して、それぞれを分割された | |
| 7176 | L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された | |
| 7177 | パターンとして扱います。 | |
| 5997 | 7178 | 従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに |
| 5998 | 7179 | マッチングします。 |
| 5999 | 7180 | 式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに |
| 6000 | 7181 | マッチングします。 |
| 6001 | 7182 | 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために |
| 6002 | 7183 | 空白入りファイル名の周りに追加のクォートを使う必要があります。 |
| 6003 | 7184 | 例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには |
| 6004 | 以下の | |
| 7185 | 以下の一つを使います: | |
| 6005 | 7186 | |
| 6006 | @spacies = <"*e f*">; | |
| 7187 | my @spacies = <"*e f*">; | |
| 6007 | @spacies = glob | |
| 7188 | my @spacies = glob('"*e f*"'); | |
| 6008 | @spacies = glob | |
| 7189 | my @spacies = glob(q("*e f*")); | |
| 6009 | 7190 | |
| 6010 | 7191 | =begin original |
| 6011 | 7192 | |
| 6012 | 7193 | If you had to get a variable through, you could do this: |
| 6013 | 7194 | |
| 6014 | 7195 | =end original |
| 6015 | 7196 | |
| 6016 | 7197 | 変数を通す必要があった場合、以下のようにできました: |
| 6017 | 7198 | |
| 6018 | @spacies = glob | |
| 7199 | my @spacies = glob("'*${var}e f*'"); | |
| 6019 | @spacies = glob | |
| 7200 | my @spacies = glob(qq("*${var}e f*")); | |
| 6020 | 7201 | |
| 6021 | 7202 | =begin original |
| 6022 | 7203 | |
| 6023 | 7204 | If non-empty braces are the only wildcard characters used in the |
| 6024 | C<glob>, no filenames are matched, but potentially many | |
| 7205 | L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many | |
| 6025 | are returned. For example, this produces nine strings, one for | |
| 7206 | strings are returned. For example, this produces nine strings, one for | |
| 6026 | 7207 | each pairing of fruits and colors: |
| 6027 | 7208 | |
| 6028 | 7209 | =end original |
| 6029 | 7210 | |
| 6030 | 空でない中かっこが C<glob> で使われている唯一 | |
| 7211 | 空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の | |
| 6031 | 場合、ファイル名とはマッチングせず、 | |
| 7212 | ワイルドカード文字列の場合、ファイル名とはマッチングせず、 | |
| 7213 | 可能性のある文字列が返されます。 | |
| 6032 | 7214 | 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに |
| 6033 | 7215 | なります: |
| 6034 | 7216 | |
| 6035 | @many = | |
| 7217 | my @many = glob("{apple,tomato,cherry}={green,yellow,red}"); | |
| 6036 | 7218 | |
| 6037 | 7219 | =begin original |
| 6038 | 7220 | |
| 6039 | This operator is implemented using the standard | |
| 7221 | This operator is implemented using the standard C<File::Glob> extension. | |
| 6040 | ||
| 7222 | See L<C<bsd_glob>|File::Glob/C<bsd_glob>> for details, including | |
| 6041 | C<bsd_glob> which does not treat whitespace | |
| 7223 | L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace | |
| 7224 | as a pattern separator. | |
| 6042 | 7225 | |
| 6043 | 7226 | =end original |
| 6044 | 7227 | |
| 6045 | ||
| 7228 | この演算子は標準の C<File::Glob> 拡張を使って | |
| 6046 | 7229 | 実装されています。 |
| 6047 | 空白をパターンのセパレータとして扱わない | |
| 7230 | 空白をパターンのセパレータとして扱わない | |
| 6048 | ||
| 7231 | L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた | |
| 7232 | 詳細は L<C<bsd_glob>|File::Glob/C<bsd_glob>> を参照してください。 | |
| 6049 | 7233 | |
| 6050 | 7234 | =begin original |
| 6051 | 7235 | |
| 7236 | If a C<glob> expression is used as the condition of a C<while> or C<for> | |
| 7237 | loop, then it will be implicitly assigned to C<$_>. If either a C<glob> | |
| 7238 | expression or an explicit assignment of a C<glob> expression to a scalar | |
| 7239 | is used as a C<while>/C<for> condition, then the condition actually | |
| 7240 | tests for definedness of the expression's value, not for its regular | |
| 7241 | truth value. | |
| 7242 | ||
| 7243 | =end original | |
| 7244 | ||
| 7245 | C<glob> 式が C<while> や C<for> ループの条件として使われた場合、 | |
| 7246 | これは暗黙に C<$_> に代入されます。 | |
| 7247 | C<glob> 式または C<glob> 式からスカラへの明示的な代入が | |
| 7248 | C<while>/C<for> の条件部として使われた場合、 | |
| 7249 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 7250 | テストします。 | |
| 7251 | ||
| 7252 | =begin original | |
| 7253 | ||
| 7254 | Internal implemenation details: | |
| 7255 | ||
| 7256 | =end original | |
| 7257 | ||
| 7258 | 内部実装の詳細: | |
| 7259 | ||
| 7260 | =begin original | |
| 7261 | ||
| 7262 | This is the internal function implementing the C<< <*.c> >> operator, | |
| 7263 | but you can use it directly. The C<< <*.c> >> operator is discussed in | |
| 7264 | more detail in L<perlop/"I/O Operators">. | |
| 7265 | ||
| 7266 | =end original | |
| 7267 | ||
| 7268 | これは、C<< <*.c> >> 演算子を実装する内部関数ですが、 | |
| 7269 | 直接使用することもできます。 | |
| 7270 | C<< <*.c> >>演算子については | |
| 7271 | L<perlop/"I/O Operators"> でより詳細に議論しています。 | |
| 7272 | ||
| 7273 | =begin original | |
| 7274 | ||
| 6052 | 7275 | Portability issues: L<perlport/glob>. |
| 6053 | 7276 | |
| 6054 | 7277 | =end original |
| 6055 | 7278 | |
| 6056 | 7279 | 移植性の問題: L<perlport/glob>。 |
| 6057 | 7280 | |
| 6058 | 7281 | =item gmtime EXPR |
| 6059 | 7282 | X<gmtime> X<UTC> X<Greenwich> |
| 6060 | 7283 | |
| 6061 | 7284 | =item gmtime |
| 6062 | 7285 | |
| 6063 | 7286 | =for Pod::Functions convert UNIX time into record or string using Greenwich time |
| 6064 | 7287 | |
| 6065 | 7288 | =begin original |
| 6066 | 7289 | |
| 6067 | Works just like L</localtime> but the returned values | |
| 7290 | Works just like L<C<localtime>|/localtime EXPR>, but the returned values | |
| 6068 | localized for the standard Greenwich time zone. | |
| 7291 | are localized for the standard Greenwich time zone. | |
| 6069 | 7292 | |
| 6070 | 7293 | =end original |
| 6071 | 7294 | |
| 6072 | L</localtime> と同様に働きますが、返り値はグリニッジ標準時に | |
| 7295 | L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に | |
| 6073 | 7296 | ローカライズされています。 |
| 6074 | 7297 | |
| 6075 | 7298 | =begin original |
| 6076 | 7299 | |
| 6077 | 7300 | Note: When called in list context, $isdst, the last value |
| 6078 | 7301 | returned by gmtime, is always C<0>. There is no |
| 6079 | 7302 | Daylight Saving Time in GMT. |
| 6080 | 7303 | |
| 6081 | 7304 | =end original |
| 6082 | 7305 | |
| 6083 | 7306 | 注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である |
| 6084 | 7307 | $isdst は常に C<0> です。 |
| 6085 | 7308 | GMT には夏時間はありません。 |
| 6086 | 7309 | |
| 6087 | 7310 | =begin original |
| 6088 | 7311 | |
| 6089 | 7312 | Portability issues: L<perlport/gmtime>. |
| 6090 | 7313 | |
| 6091 | 7314 | =end original |
| 6092 | 7315 | |
| 6093 | 7316 | 移植性の問題: L<perlport/gmtime>。 |
| 6094 | 7317 | |
| 6095 | 7318 | =item goto LABEL |
| 6096 | 7319 | X<goto> X<jump> X<jmp> |
| 6097 | 7320 | |
| 6098 | 7321 | =item goto EXPR |
| 6099 | 7322 | |
| 6100 | 7323 | =item goto &NAME |
| 6101 | 7324 | |
| 6102 | 7325 | =for Pod::Functions create spaghetti code |
| 6103 | 7326 | |
| 6104 | 7327 | =begin original |
| 6105 | 7328 | |
| 6106 | The C<goto | |
| 7329 | The C<goto LABEL> form finds the statement labeled with LABEL and | |
| 6107 | 7330 | resumes execution there. It can't be used to get out of a block or |
| 6108 | subroutine given to C<sort>. It can be used to go | |
| 7331 | subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go | |
| 6109 | else within the dynamic scope, including out of | |
| 7332 | almost anywhere else within the dynamic scope, including out of | |
| 6110 | usually better to use some other construct such as | |
| 7333 | subroutines, but it's usually better to use some other construct such as | |
| 6111 | ||
| 7334 | L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has | |
| 6112 | ||
| 7335 | never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl, | |
| 6113 | ||
| 7336 | that is; C is another matter). (The difference is that C does not offer | |
| 6114 | ||
| 7337 | named loops combined with loop control. Perl does, and this replaces | |
| 7338 | most structured uses of L<C<goto>|/goto LABEL> in other languages.) | |
| 6115 | 7339 | |
| 6116 | 7340 | =end original |
| 6117 | 7341 | |
| 6118 | C<goto | |
| 7342 | C<goto LABEL> の形式は、LABEL というラベルの付いた文を | |
| 6119 | 7343 | 探して、そこへ実行を移すものです。 |
| 6120 | C<sort> で与えられたブロックやサブルーチンから外へ | |
| 7344 | L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ | |
| 7345 | 出ることはできません。 | |
| 6121 | 7346 | これ以外は、サブルーチンの外を含む、動的スコープ内の |
| 6122 | 7347 | ほとんどすべての場所へ行くために使用できますが、普通は、 |
| 6123 | C<last> や C<die> といった別の構造を使った方が | |
| 7348 | L<C<last>|/last LABEL> や L<C<die>|/die LIST> といった別の構造を使った方が | |
| 6124 | ||
| 7349 | 良いでしょう。 | |
| 7350 | Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、 | |
| 6125 | 7351 | 1 度もありません (Perl では; C は別のお話です)。 |
| 6126 | 7352 | (違いは、C にはループ制御と結びついた名前つきのループがないことです。 |
| 6127 | Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の | |
| 7353 | Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の | |
| 6128 | 置き換えます。) | |
| 7354 | 使用法を置き換えます。) | |
| 6129 | 7355 | |
| 6130 | 7356 | =begin original |
| 6131 | 7357 | |
| 6132 | The C<goto | |
| 7358 | The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or | |
| 6133 | ||
| 7359 | a label name. If it evaluates to a code reference, it will be handled | |
| 6134 | ||
| 7360 | like C<goto &NAME>, below. This is especially useful for implementing | |
| 7361 | tail recursion via C<goto __SUB__>. | |
| 6135 | 7362 | |
| 6136 | 7363 | =end original |
| 6137 | 7364 | |
| 6138 | C<goto | |
| 7365 | C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として | |
| 6139 | こ | |
| 7366 | 評価することを想定します。 | |
| 7367 | コードリファレンスとして評価する場合、後述する C<goto &NAME> のように | |
| 7368 | 扱います。 | |
| 7369 | これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。 | |
| 7370 | ||
| 7371 | =begin original | |
| 7372 | ||
| 7373 | If the expression evaluates to a label name, its scope will be resolved | |
| 7374 | dynamically. This allows for computed L<C<goto>|/goto LABEL>s per | |
| 7375 | FORTRAN, but isn't necessarily recommended if you're optimizing for | |
| 7376 | maintainability: | |
| 7377 | ||
| 7378 | =end original | |
| 7379 | ||
| 7380 | 式がラベル名に評価される場合、このスコープは動的に解決されます。 | |
| 7381 | これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、 | |
| 6140 | 7382 | 保守性を重視するならお勧めしません。 |
| 6141 | 7383 | |
| 6142 | 7384 | goto ("FOO", "BAR", "GLARCH")[$i]; |
| 6143 | 7385 | |
| 6144 | 7386 | =begin original |
| 6145 | 7387 | |
| 6146 | As shown in this example, C<goto | |
| 7388 | As shown in this example, C<goto EXPR> is exempt from the "looks like a | |
| 6147 | 7389 | function" rule. A pair of parentheses following it does not (necessarily) |
| 6148 | 7390 | delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>. |
| 6149 | 7391 | Also, unlike most named operators, this has the same precedence as |
| 6150 | 7392 | assignment. |
| 6151 | 7393 | |
| 6152 | 7394 | =end original |
| 6153 | 7395 | |
| 6154 | この例で示したように、C<goto | |
| 7396 | この例で示したように、C<goto EXPR> は「関数のように見える」ルールから | |
| 6155 | 7397 | 除外されます。 |
| 6156 | 7398 | これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 |
| 6157 | 7399 | C<goto("NE")."XT"> は C<goto NEXT> と等価です。 |
| 6158 | 7400 | また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
| 6159 | 7401 | |
| 6160 | 7402 | =begin original |
| 6161 | 7403 | |
| 6162 | Use of C<goto | |
| 7404 | Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is | |
| 6163 | 7405 | deprecated and will issue a warning. Even then, it may not be used to |
| 6164 | 7406 | go into any construct that requires initialization, such as a |
| 6165 | subroutine | |
| 7407 | subroutine, a C<foreach> loop, or a C<given> | |
| 7408 | block. In general, it may not be used to jump into the parameter | |
| 7409 | of a binary or list operator, but it may be used to jump into the | |
| 7410 | I<first> parameter of a binary operator. (The C<=> | |
| 7411 | assignment operator's "first" operand is its right-hand | |
| 7412 | operand.) It also can't be used to go into a | |
| 6166 | 7413 | construct that is optimized away. |
| 6167 | 7414 | |
| 6168 | 7415 | =end original |
| 6169 | 7416 | |
| 6170 | 構造の中に飛び込むために C<goto | |
| 7417 | 構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは | |
| 6171 | 7418 | 非推奨で、警告が発生します。 |
| 6172 | それでも、サブルーチンや C<foreach> ループのような、 | |
| 7419 | それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、 | |
| 7420 | 初期化が必要な | |
| 6173 | 7421 | 構造の中に入るために使うことは出来ません。 |
| 7422 | 一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、 | |
| 7423 | 2 項演算子の I<最初の> 引数に飛び込むために使われていました。 | |
| 7424 | (C<=> 代入演算子の「最初の」オペランドはその右オペランドです。) | |
| 6174 | 7425 | また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。 |
| 6175 | 7426 | |
| 6176 | 7427 | =begin original |
| 6177 | 7428 | |
| 6178 | The C<goto | |
| 7429 | The C<goto &NAME> form is quite different from the other forms of | |
| 6179 | C<goto>. In fact, it isn't a goto in the normal sense at | |
| 7430 | L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at | |
| 6180 | doesn't have the stigma associated with other gotos. Instead, | |
| 7431 | all, and doesn't have the stigma associated with other gotos. Instead, | |
| 6181 | exits the current subroutine (losing any changes set by | |
| 7432 | it exits the current subroutine (losing any changes set by | |
| 6182 | immediately calls in its place the named | |
| 7433 | L<C<local>|/local EXPR>) and immediately calls in its place the named | |
| 6183 | value of @_. This is used | |
| 7434 | subroutine using the current value of L<C<@_>|perlvar/@_>. This is used | |
| 6184 | ||
| 7435 | by C<AUTOLOAD> subroutines that wish to load another subroutine and then | |
| 6185 | been called in the first place | |
| 7436 | pretend that the other subroutine had been called in the first place | |
| 6186 | ||
| 7437 | (except that any modifications to L<C<@_>|perlvar/@_> in the current | |
| 6187 | ||
| 7438 | subroutine are propagated to the other subroutine.) After the | |
| 6188 | ||
| 7439 | L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able | |
| 7440 | to tell that this routine was called first. | |
| 6189 | 7441 | |
| 6190 | 7442 | =end original |
| 6191 | 7443 | |
| 6192 | C<goto | |
| 7444 | C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり | |
| 6193 | 7445 | 異なったものです。 |
| 6194 | 7446 | 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 |
| 6195 | 7447 | 他の goto が持つ不名誉を持っていません。 |
| 6196 | 現在のサブルーチンを終了し (local | |
| 7448 | 現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、 | |
| 6197 | 直ちに現在の @_ の値を使って指定された名前のサブルーチンを | |
| 7449 | 直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを | |
| 7450 | 呼び出します。 | |
| 6198 | 7451 | これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、 |
| 6199 | 7452 | その別のサブルーチンが最初に呼ばれたようにするために使われます |
| 6200 | (ただし、現在のサブルーチンで C<@_> を修正した場合には、 | |
| 7453 | (ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、 | |
| 6201 | 7454 | その別のサブルーチンに伝えられます)。 |
| 6202 | C<goto> のあとは、C<caller> でさえも、現在の | |
| 7455 | L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の | |
| 6203 | 最初に呼び出されたと言うことができません。 | |
| 7456 | サブルーチンが最初に呼び出されたと言うことができません。 | |
| 6204 | 7457 | |
| 6205 | 7458 | =begin original |
| 6206 | 7459 | |
| 6207 | 7460 | NAME needn't be the name of a subroutine; it can be a scalar variable |
| 6208 | 7461 | containing a code reference or a block that evaluates to a code |
| 6209 | 7462 | reference. |
| 6210 | 7463 | |
| 6211 | 7464 | =end original |
| 6212 | 7465 | |
| 6213 | 7466 | NAME はサブルーチンの名前である必要はありません; コードリファレンスを |
| 6214 | 7467 | 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。 |
| 6215 | 7468 | |
| 6216 | 7469 | =item grep BLOCK LIST |
| 6217 | 7470 | X<grep> |
| 6218 | 7471 | |
| 6219 | 7472 | =item grep EXPR,LIST |
| 6220 | 7473 | |
| 6221 | 7474 | =for Pod::Functions locate elements in a list test true against a given criterion |
| 6222 | 7475 | |
| 6223 | 7476 | =begin original |
| 6224 | 7477 | |
| 6225 | This is similar in spirit to, but not the same as, grep(1) and its | |
| 7478 | This is similar in spirit to, but not the same as, L<grep(1)> and its | |
| 6226 | 7479 | relatives. In particular, it is not limited to using regular expressions. |
| 6227 | 7480 | |
| 6228 | 7481 | =end original |
| 6229 | 7482 | |
| 6230 | これは grep(1) とその親類と同じようなものですが、同じではありません。 | |
| 7483 | これは L<grep(1)> とその親類と同じようなものですが、同じではありません。 | |
| 6231 | 7484 | 特に、正規表現の使用に制限されません。 |
| 6232 | 7485 | |
| 6233 | 7486 | =begin original |
| 6234 | 7487 | |
| 6235 | 7488 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
| 6236 | C<$_> to each element) and returns the list valu | |
| 7489 | L<C<$_>|perlvar/$_> to each element) and returns the list value | |
| 7490 | consisting of those | |
| 6237 | 7491 | elements for which the expression evaluated to true. In scalar |
| 6238 | 7492 | context, returns the number of times the expression was true. |
| 6239 | 7493 | |
| 6240 | 7494 | =end original |
| 6241 | 7495 | |
| 6242 | 7496 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
| 6243 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
| 7497 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 | |
| 6244 | 7498 | その要素のうち、評価した式が真となったものからなるリスト値が返されます。 |
| 6245 | 7499 | スカラコンテキストでは、式が真となった回数を返します。 |
| 6246 | 7500 | |
| 6247 | @foo = grep(!/^#/, @bar); # weed out comments | |
| 7501 | my @foo = grep(!/^#/, @bar); # weed out comments | |
| 6248 | 7502 | |
| 6249 | 7503 | =begin original |
| 6250 | 7504 | |
| 6251 | 7505 | or equivalently, |
| 6252 | 7506 | |
| 6253 | 7507 | =end original |
| 6254 | 7508 | |
| 6255 | 7509 | あるいは等価な例として: |
| 6256 | 7510 | |
| 6257 | @foo = grep {!/^#/} @bar; # weed out comments | |
| 7511 | my @foo = grep {!/^#/} @bar; # weed out comments | |
| 6258 | 7512 | |
| 6259 | 7513 | =begin original |
| 6260 | 7514 | |
| 6261 | Note that C<$_> is an alias to the list value, so it can | |
| 7515 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can | |
| 7516 | be used to | |
| 6262 | 7517 | modify the elements of the LIST. While this is useful and supported, |
| 6263 | 7518 | it can cause bizarre results if the elements of LIST are not variables. |
| 6264 | 7519 | Similarly, grep returns aliases into the original list, much as a for |
| 6265 | 7520 | loop's index variable aliases the list elements. That is, modifying an |
| 6266 | element of a list returned by grep (for example, in a C<foreach>, | |
| 7521 | element of a list returned by grep (for example, in a C<foreach>, | |
| 6267 | or another C<grep> | |
| 7522 | L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>) | |
| 7523 | actually modifies the element in the original list. | |
| 6268 | 7524 | This is usually something to be avoided when writing clear code. |
| 6269 | 7525 | |
| 6270 | 7526 | =end original |
| 6271 | 7527 | |
| 6272 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 7528 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 6273 | 7529 | 変更するために使うことができます。 |
| 6274 | 7530 | これは、便利でサポートされていますが、 |
| 6275 | 7531 | LIST の要素が変数でないと、おかしな結果になります。 |
| 6276 | 7532 | 同様に、grep は元のリストへのエイリアスを返します; for ループの |
| 6277 | 7533 | インデックス変数がリスト要素のエイリアスであるのと同様です。 |
| 6278 | 7534 | つまり、grep で返されたリストの要素を |
| 6279 | (C<foreach>, C<map>, または他の | |
| 7535 | (C<foreach>, L<C<map>|/map BLOCK LIST>, または他の | |
| 6280 | 元のリストの要素が変更されます。 | |
| 7536 | L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。 | |
| 6281 | 7537 | これはきれいなコードを書くときには普通は回避されます。 |
| 6282 | 7538 | |
| 6283 | 7539 | =begin original |
| 6284 | 7540 | |
| 6285 | ||
| 7541 | See also L<C<map>|/map BLOCK LIST> for a list composed of the results of | |
| 6286 | ||
| 7542 | the BLOCK or EXPR. | |
| 6287 | then, in addition to being locally aliased to | |
| 6288 | the list elements, C<$_> keeps being lexical inside the block; i.e., it | |
| 6289 | can't be seen from the outside, avoiding any potential side-effects. | |
| 6290 | 7543 | |
| 6291 | 7544 | =end original |
| 6292 | 7545 | |
| 6293 | ||
| 7546 | BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を | |
| 6294 | ||
| 7547 | 参照してください。 | |
| 6295 | エイリアスであることに加えて、C<$_> はブロック内でレキシカルで | |
| 6296 | ありつづけます; つまり、外側からは見えず、起こりうる副作用を回避します。 | |
| 6297 | 7548 | |
| 6298 | =begin original | |
| 6299 | ||
| 6300 | See also L</map> for a list composed of the results of the BLOCK or EXPR. | |
| 6301 | ||
| 6302 | =end original | |
| 6303 | ||
| 6304 | BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。 | |
| 6305 | ||
| 6306 | 7549 | =item hex EXPR |
| 6307 | 7550 | X<hex> X<hexadecimal> |
| 6308 | 7551 | |
| 6309 | 7552 | =item hex |
| 6310 | 7553 | |
| 6311 | =for Pod::Functions convert a | |
| 7554 | =for Pod::Functions convert a hexadecimal string to a number | |
| 6312 | 7555 | |
| 6313 | 7556 | =begin original |
| 6314 | 7557 | |
| 6315 | Interprets EXPR as a hex string and returns the corresponding value. | |
| 7558 | Interprets EXPR as a hex string and returns the corresponding numeric value. | |
| 6316 | ||
| 7559 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 6317 | L</oct>.) If EXPR is omitted, uses C<$_>. | |
| 6318 | 7560 | |
| 6319 | 7561 | =end original |
| 6320 | 7562 | |
| 6321 | EXPR を 16 進数の文字列と解釈して、対応する値を返します。 | |
| 7563 | EXPR を 16 進数の文字列と解釈して、対応する数値を返します。 | |
| 6322 | ||
| 7564 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 6323 | 参照してください。) | |
| 6324 | EXPR が省略されると、C<$_> を使います。 | |
| 6325 | 7565 | |
| 6326 | 7566 | print hex '0xAf'; # prints '175' |
| 6327 | 7567 | print hex 'aF'; # same |
| 7568 | $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/ | |
| 6328 | 7569 | |
| 6329 | 7570 | =begin original |
| 6330 | 7571 | |
| 6331 | ||
| 7572 | A hex string consists of hex digits and an optional C<0x> or C<x> prefix. | |
| 6332 | ||
| 7573 | Each hex digit may be preceded by a single underscore, which will be ignored. | |
| 6333 | ||
| 7574 | Any other character triggers a warning and causes the rest of the string | |
| 6334 | ||
| 7575 | to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>). | |
| 7576 | Only integers can be represented, and integer overflow triggers a warning. | |
| 6335 | 7577 | |
| 6336 | 7578 | =end original |
| 6337 | 7579 | |
| 6338 | 16 進文字列は | |
| 7580 | 16 進文字列は 16 進数と、オプションの C<0x> または C<x> 接頭辞からなります。 | |
| 6339 | ||
| 7581 | それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。 | |
| 6340 | ||
| 7582 | その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と | |
| 6341 | ||
| 7583 | 異なり)文字列の残りの部分は無視されます。 | |
| 7584 | 整数のみを表現でき、整数オーバーフローは警告を引き起こします。 | |
| 7585 | ||
| 7586 | =begin original | |
| 7587 | ||
| 7588 | To convert strings that might start with any of C<0>, C<0x>, or C<0b>, | |
| 7589 | see L<C<oct>|/oct EXPR>. To present something as hex, look into | |
| 7590 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 7591 | L<C<sprintf>|/sprintf FORMAT, LIST>, and | |
| 7592 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
| 7593 | ||
| 7594 | =end original | |
| 7595 | ||
| 7596 | C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、 | |
| 7597 | L<C<oct>|/oct EXPR> を参照してください。 | |
| 7598 | 何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 7599 | L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を | |
| 6342 | 7600 | 参照してください。 |
| 6343 | 7601 | |
| 6344 | 7602 | =item import LIST |
| 6345 | 7603 | X<import> |
| 6346 | 7604 | |
| 6347 | 7605 | =for Pod::Functions patch a module's namespace into your own |
| 6348 | 7606 | |
| 6349 | 7607 | =begin original |
| 6350 | 7608 | |
| 6351 | There is no builtin C<import> function. It is just an | |
| 7609 | There is no builtin L<C<import>|/import LIST> function. It is just an | |
| 6352 | method (subroutine) defined (or inherited) by modules that wish | |
| 7610 | ordinary method (subroutine) defined (or inherited) by modules that wish | |
| 6353 | names to another module. The | |
| 7611 | to export names to another module. The | |
| 6354 | ||
| 7612 | L<C<use>|/use Module VERSION LIST> function calls the | |
| 7613 | L<C<import>|/import LIST> method for the package used. See also | |
| 7614 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>. | |
| 6355 | 7615 | |
| 6356 | 7616 | =end original |
| 6357 | 7617 | |
| 6358 | 組み込みの C<import> 関数というものはありません。 | |
| 7618 | 組み込みの L<C<import>|/import LIST> 関数というものはありません。 | |
| 6359 | 7619 | これは単に、別のモジュールに名前をエクスポートしたいモジュールが |
| 6360 | 7620 | 定義した(または継承した)、通常のメソッド(サブルーチン)です。 |
| 6361 | C<use> 関数はパッケージを使う時に | |
| 7621 | L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に | |
| 6362 | L< | |
| 7622 | L<C<import>|/import LIST> メソッドを呼び出します。 | |
| 7623 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も | |
| 7624 | 参照してください。 | |
| 6363 | 7625 | |
| 6364 | 7626 | =item index STR,SUBSTR,POSITION |
| 6365 | 7627 | X<index> X<indexOf> X<InStr> |
| 6366 | 7628 | |
| 6367 | 7629 | =item index STR,SUBSTR |
| 6368 | 7630 | |
| 6369 | 7631 | =for Pod::Functions find a substring within a string |
| 6370 | 7632 | |
| 6371 | 7633 | =begin original |
| 6372 | 7634 | |
| 6373 | 7635 | The index function searches for one string within another, but without |
| 6374 | 7636 | the wildcard-like behavior of a full regular-expression pattern match. |
| 6375 | 7637 | It returns the position of the first occurrence of SUBSTR in STR at |
| 6376 | 7638 | or after POSITION. If POSITION is omitted, starts searching from the |
| 6377 | 7639 | beginning of the string. POSITION before the beginning of the string |
| 6378 | 7640 | or after its end is treated as if it were the beginning or the end, |
| 6379 | 7641 | respectively. POSITION and the return value are based at zero. |
| 6380 | If the substring is not found, C<index> | |
| 7642 | If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION> | |
| 7643 | returns -1. | |
| 6381 | 7644 | |
| 6382 | 7645 | =end original |
| 6383 | 7646 | |
| 6384 | 7647 | index 関数は ある文字列をもうひとつの文字列から検索しますが、 |
| 6385 | 7648 | 完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。 |
| 6386 | 7649 | STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。 |
| 6387 | 7650 | POSITION が省略された場合には、STR の最初から探し始めます。 |
| 6388 | 7651 | POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、 |
| 6389 | 7652 | それぞれ先頭と末尾を指定されたものとして扱われます。 |
| 6390 | 7653 | POSITION と返り値のベースは、0 です。 |
| 6391 | SUBSTR が見つからなかった場合には、C<index> | |
| 7654 | SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION> は | |
| 7655 | -1 が返されます。 | |
| 6392 | 7656 | |
| 7657 | =begin original | |
| 7658 | ||
| 7659 | Find characters or strings: | |
| 7660 | ||
| 7661 | =end original | |
| 7662 | ||
| 7663 | 文字や文字列を探すには: | |
| 7664 | ||
| 7665 | index("Perl is great", "P"); # Returns 0 | |
| 7666 | index("Perl is great", "g"); # Returns 8 | |
| 7667 | index("Perl is great", "great"); # Also returns 8 | |
| 7668 | ||
| 7669 | =begin original | |
| 7670 | ||
| 7671 | Attempting to find something not there: | |
| 7672 | ||
| 7673 | =end original | |
| 7674 | ||
| 7675 | ないものを探そうとすると: | |
| 7676 | ||
| 7677 | index("Perl is great", "Z"); # Returns -1 (not found) | |
| 7678 | ||
| 7679 | =begin original | |
| 7680 | ||
| 7681 | Using an offset to find the I<second> occurrence: | |
| 7682 | ||
| 7683 | =end original | |
| 7684 | ||
| 7685 | I<2 番目> の出現位置を探すためにオフセットを使うと: | |
| 7686 | ||
| 7687 | index("Perl is great", "e", 5); # Returns 10 | |
| 7688 | ||
| 6393 | 7689 | =item int EXPR |
| 6394 | 7690 | X<int> X<integer> X<truncate> X<trunc> X<floor> |
| 6395 | 7691 | |
| 6396 | 7692 | =item int |
| 6397 | 7693 | |
| 6398 | 7694 | =for Pod::Functions get the integer portion of a number |
| 6399 | 7695 | |
| 6400 | 7696 | =begin original |
| 6401 | 7697 | |
| 6402 | Returns the integer portion of EXPR. If EXPR is omitted, uses | |
| 7698 | Returns the integer portion of EXPR. If EXPR is omitted, uses | |
| 7699 | L<C<$_>|perlvar/$_>. | |
| 6403 | 7700 | You should not use this function for rounding: one because it truncates |
| 6404 | 7701 | towards C<0>, and two because machine representations of floating-point |
| 6405 | 7702 | numbers can sometimes produce counterintuitive results. For example, |
| 6406 | 7703 | C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's |
| 6407 | 7704 | because it's really more like -268.99999999999994315658 instead. Usually, |
| 6408 | the C<sprintf> | |
| 7705 | the L<C<sprintf>|/sprintf FORMAT, LIST>, | |
| 6409 | ||
| 7706 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the | |
| 7707 | L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>> | |
| 7708 | functions will serve you better than will L<C<int>|/int EXPR>. | |
| 6410 | 7709 | |
| 6411 | 7710 | =end original |
| 6412 | 7711 | |
| 6413 | 7712 | EXPR の整数部を返します。 |
| 6414 | EXPR が省略されると、C<$_> を使います。 | |
| 7713 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 6415 | 7714 | この関数を丸めのために使うべきではありません: 第一の理由として C<0> の |
| 6416 | 7715 | 方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に |
| 6417 | 7716 | 反した結果を生み出すからです。 |
| 6418 | 7717 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を |
| 6419 | 7718 | 返します: これは実際には -268.99999999999994315658 というような値に |
| 6420 | 7719 | なっているからです。 |
| 6421 | 通常、C<sprintf> | |
| 7720 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST>, | |
| 6422 | int | |
| 7721 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 7722 | L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が | |
| 7723 | L<C<int>|/int EXPR> より便利です。 | |
| 6423 | 7724 | |
| 6424 | 7725 | =item ioctl FILEHANDLE,FUNCTION,SCALAR |
| 6425 | 7726 | X<ioctl> |
| 6426 | 7727 | |
| 6427 | 7728 | =for Pod::Functions system-dependent device control system call |
| 6428 | 7729 | |
| 6429 | 7730 | =begin original |
| 6430 | 7731 | |
| 6431 | Implements the ioctl(2) function. You'll probably first have to say | |
| 7732 | Implements the L<ioctl(2)> function. You'll probably first have to say | |
| 6432 | 7733 | |
| 6433 | 7734 | =end original |
| 6434 | 7735 | |
| 6435 | ioctl(2) 関数を実装します。 | |
| 7736 | L<ioctl(2)> 関数を実装します。 | |
| 6436 | 7737 | 正しい関数の定義を得るために、おそらく最初に |
| 6437 | 7738 | |
| 6438 | 7739 | require "sys/ioctl.ph"; # probably in |
| 6439 | 7740 | # $Config{archlib}/sys/ioctl.ph |
| 6440 | 7741 | |
| 6441 | 7742 | =begin original |
| 6442 | 7743 | |
| 6443 | 7744 | to get the correct function definitions. If F<sys/ioctl.ph> doesn't |
| 6444 | 7745 | exist or doesn't have the correct definitions you'll have to roll your |
| 6445 | 7746 | own, based on your C header files such as F<< <sys/ioctl.h> >>. |
| 6446 | 7747 | (There is a Perl script called B<h2ph> that comes with the Perl kit that |
| 6447 | 7748 | may help you in this, but it's nontrivial.) SCALAR will be read and/or |
| 6448 | 7749 | written depending on the FUNCTION; a C pointer to the string value of SCALAR |
| 6449 | will be passed as the third argument of the actual | |
| 7750 | will be passed as the third argument of the actual | |
| 7751 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR | |
| 6450 | 7752 | has no string value but does have a numeric value, that value will be |
| 6451 | 7753 | passed rather than a pointer to the string value. To guarantee this to be |
| 6452 | true, add a C<0> to the scalar before using it.) The | |
| 7754 | true, add a C<0> to the scalar before using it.) The | |
| 7755 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 6453 | 7756 | functions may be needed to manipulate the values of structures used by |
| 6454 | C<ioctl>. | |
| 7757 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>. | |
| 6455 | 7758 | |
| 6456 | 7759 | =end original |
| 6457 | 7760 | |
| 6458 | 7761 | としなくてはならないでしょう。 |
| 6459 | 7762 | F<sys/ioctl.ph> がないか、間違った定義をしている場合には、 |
| 6460 | 7763 | F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、 |
| 6461 | 7764 | 自分で作らなければなりません。 |
| 6462 | 7765 | (Perl の配布キットに入っている B<h2ph> という Perl スクリプトが |
| 6463 | 7766 | これを手助けしてくれるでしょうが、これは自明ではありません。) |
| 6464 | 7767 | FOUNCTION に応じて SCALAR が読み書きされます; |
| 6465 | SCALAR の文字列値へのポインタが、実際の | |
| 7768 | SCALAR の文字列値へのポインタが、実際の | |
| 7769 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの | |
| 6466 | 7770 | 3 番目の引数として渡されます。 |
| 6467 | 7771 | (SCALAR が文字列値を持っておらず、数値を持っている場合には、 |
| 6468 | 7772 | 文字列値へのポインタの代わりに、その値が渡されます。 |
| 6469 | 7773 | このことを保証するためには、使用する前に SCALAR にC<0> を足してください。) |
| 6470 | C<ioctl> で使われる構造体の値を | |
| 7774 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を | |
| 6471 | C<pack> | |
| 7775 | 操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と | |
| 7776 | L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。 | |
| 6472 | 7777 | |
| 6473 | 7778 | =begin original |
| 6474 | 7779 | |
| 6475 | The return value of C<ioctl> | |
| 7780 | The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and | |
| 7781 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows: | |
| 6476 | 7782 | |
| 6477 | 7783 | =end original |
| 6478 | 7784 | |
| 6479 | C<ioctl> | |
| 7785 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> | |
| 7786 | (と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、 | |
| 7787 | 以下のようになります: | |
| 6480 | 7788 | |
| 6481 | 7789 | =begin original |
| 6482 | 7790 | |
| 6483 | 7791 | if OS returns: then Perl returns: |
| 6484 | 7792 | -1 undefined value |
| 6485 | 7793 | 0 string "0 but true" |
| 6486 | 7794 | anything else that number |
| 6487 | 7795 | |
| 6488 | 7796 | =end original |
| 6489 | 7797 | |
| 6490 | 7798 | OS が返した値: Perl が返す値: |
| 6491 | 7799 | -1 未定義値 |
| 6492 | 7800 | 0 「0 だが真」の文字列 |
| 6493 | 7801 | その他 その値そのもの |
| 6494 | 7802 | |
| 6495 | 7803 | =begin original |
| 6496 | 7804 | |
| 6497 | 7805 | Thus Perl returns true on success and false on failure, yet you can |
| 6498 | 7806 | still easily determine the actual value returned by the operating |
| 6499 | 7807 | system: |
| 6500 | 7808 | |
| 6501 | 7809 | =end original |
| 6502 | 7810 | |
| 6503 | 7811 | つまり Perl は、成功時に「真」、失敗時に「偽」を返す |
| 6504 | 7812 | ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。 |
| 6505 | 7813 | |
| 6506 | $retval = ioctl(...) || -1; | |
| 7814 | my $retval = ioctl(...) || -1; | |
| 6507 | 7815 | printf "System returned %d\n", $retval; |
| 6508 | 7816 | |
| 6509 | 7817 | =begin original |
| 6510 | 7818 | |
| 6511 | The special string C<"0 but true"> is exempt from | |
| 7819 | The special string C<"0 but true"> is exempt from | |
| 6512 | ||
| 7820 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 7821 | L<warnings> on improper numeric conversions. | |
| 6513 | 7822 | |
| 6514 | 7823 | =end original |
| 6515 | 7824 | |
| 6516 | 7825 | 特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する |
| 6517 | ||
| 7826 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 7827 | L<warnings> 警告を回避します。 | |
| 6518 | 7828 | |
| 6519 | 7829 | =begin original |
| 6520 | 7830 | |
| 6521 | 7831 | Portability issues: L<perlport/ioctl>. |
| 6522 | 7832 | |
| 6523 | 7833 | =end original |
| 6524 | 7834 | |
| 6525 | 7835 | 移植性の問題: L<perlport/ioctl>。 |
| 6526 | 7836 | |
| 6527 | 7837 | =item join EXPR,LIST |
| 6528 | 7838 | X<join> |
| 6529 | 7839 | |
| 6530 | 7840 | =for Pod::Functions join a list into a string using a separator |
| 6531 | 7841 | |
| 6532 | 7842 | =begin original |
| 6533 | 7843 | |
| 6534 | 7844 | Joins the separate strings of LIST into a single string with fields |
| 6535 | 7845 | separated by the value of EXPR, and returns that new string. Example: |
| 6536 | 7846 | |
| 6537 | 7847 | =end original |
| 6538 | 7848 | |
| 6539 | 7849 | LIST の個別の文字列を、EXPR の値で区切って |
| 6540 | 7850 | 1 つの文字列につなげ、その文字列を返します。 |
| 6541 | 7851 | 例: |
| 6542 | 7852 | |
| 6543 | $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); | |
| 7853 | my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); | |
| 6544 | 7854 | |
| 6545 | 7855 | =begin original |
| 6546 | 7856 | |
| 6547 | Beware that unlike C<split> | |
| 7857 | Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
| 6548 | ||
| 7858 | L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument. | |
| 7859 | Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>. | |
| 6549 | 7860 | |
| 6550 | 7861 | =end original |
| 6551 | 7862 | |
| 6552 | C<split> | |
| 7863 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、 | |
| 7864 | L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに | |
| 6553 | 7865 | 注意してください。 |
| 6554 | L</split> と比較してください。 | |
| 7866 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。 | |
| 6555 | 7867 | |
| 6556 | 7868 | =item keys HASH |
| 6557 | 7869 | X<keys> X<key> |
| 6558 | 7870 | |
| 6559 | 7871 | =item keys ARRAY |
| 6560 | 7872 | |
| 6561 | =item keys EXPR | |
| 6562 | ||
| 6563 | 7873 | =for Pod::Functions retrieve list of indices from a hash |
| 6564 | 7874 | |
| 6565 | 7875 | =begin original |
| 6566 | 7876 | |
| 6567 | 7877 | Called in list context, returns a list consisting of all the keys of the |
| 6568 | 7878 | named hash, or in Perl 5.12 or later only, the indices of an array. Perl |
| 6569 | 7879 | releases prior to 5.12 will produce a syntax error if you try to use an |
| 6570 | 7880 | array argument. In scalar context, returns the number of keys or indices. |
| 6571 | 7881 | |
| 6572 | 7882 | =end original |
| 6573 | 7883 | |
| 6574 | 7884 | リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは |
| 6575 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを | |
| 7885 | Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。 | |
| 6576 | 返します。 | |
| 6577 | 7886 | 5.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。 |
| 6578 | 7887 | スカラコンテキストでは、キーやインデックスの数を返します。 |
| 6579 | 7888 | |
| 6580 | 7889 | =begin original |
| 6581 | 7890 | |
| 6582 | 7891 | Hash entries are returned in an apparently random order. The actual random |
| 6583 | 7892 | order is specific to a given hash; the exact same series of operations |
| 6584 | on two hashes may result in a different order for each hash. Any insertion | |
| 7893 | on two hashes may result in a different order for each hash. Any insertion | |
| 6585 | 7894 | into the hash may change the order, as will any deletion, with the exception |
| 6586 | that the most recent key returned by C<each> | |
| 7895 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 6587 | without changing the order. So | |
| 7896 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 6588 | ||
| 7897 | long as a given hash is unmodified you may rely on | |
| 6589 | ||
| 7898 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each | |
| 6590 | ||
| 7899 | HASH> to repeatedly return the same order | |
| 7900 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 7901 | details on why hash order is randomized. Aside from the guarantees | |
| 6591 | 7902 | provided here the exact details of Perl's hash algorithm and the hash |
| 6592 | traversal order are subject to change in any release of Perl. | |
| 7903 | traversal order are subject to change in any release of Perl. Tied hashes | |
| 7904 | may behave differently to Perl's hashes with respect to changes in order on | |
| 7905 | insertion and deletion of items. | |
| 6593 | 7906 | |
| 6594 | 7907 | =end original |
| 6595 | 7908 | |
| 6596 | 7909 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
| 6597 | 7910 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
| 6598 | 7911 | 操作を行っても、ハッシュによって異なった順序になります。 |
| 6599 | 7912 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
| 6600 | C<each> または C<keys> によって返されたもっとも | |
| 7913 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 6601 | 変えることなく削除できます。 | |
| 7914 | 最近のキーは順序を変えることなく削除できます。 | |
| 6602 | ハッシュが変更されない限り、C<keys>, C<values> | |
| 7915 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 6603 | 返すことに依存してもかまいません。 | |
| 7916 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 | |
| 6604 | 7917 | なぜハッシュの順序がランダム化されているかの詳細については |
| 6605 | 7918 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
| 6606 | 7919 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
| 6607 | 7920 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
| 7921 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
| 7922 | 異なった振る舞いをします。 | |
| 6608 | 7923 | |
| 6609 | 7924 | =begin original |
| 6610 | 7925 | |
| 6611 | As a side effect, calling keys | |
| 7926 | As a side effect, calling L<C<keys>|/keys HASH> resets the internal | |
| 6612 | ARRAY (see L< | |
| 7927 | iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before | |
| 6613 | ||
| 7928 | yielding the keys. In | |
| 7929 | particular, calling L<C<keys>|/keys HASH> in void context resets the | |
| 7930 | iterator with no other overhead. | |
| 6614 | 7931 | |
| 6615 | 7932 | =end original |
| 6616 | 7933 | |
| 6617 | 副作用として、HASH | |
| 7934 | 副作用として、L<C<keys>|/keys HASH> の呼び出しは、 | |
| 6618 | ||
| 7935 | キーを取り出す前に HASH や ARRAY の反復子を | |
| 6619 | ||
| 7936 | 初期化します (L<C<each>|/each HASH> を参照してください)。 | |
| 7937 | 特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと | |
| 6620 | 7938 | オーバーヘッドなしで反復子を初期化します。 |
| 6621 | 7939 | |
| 6622 | 7940 | =begin original |
| 6623 | 7941 | |
| 6624 | 7942 | Here is yet another way to print your environment: |
| 6625 | 7943 | |
| 6626 | 7944 | =end original |
| 6627 | 7945 | |
| 6628 | 7946 | 環境変数を表示する別の例です: |
| 6629 | 7947 | |
| 6630 | @keys = keys %ENV; | |
| 7948 | my @keys = keys %ENV; | |
| 6631 | @values = values %ENV; | |
| 7949 | my @values = values %ENV; | |
| 6632 | 7950 | while (@keys) { |
| 6633 | 7951 | print pop(@keys), '=', pop(@values), "\n"; |
| 6634 | 7952 | } |
| 6635 | 7953 | |
| 6636 | 7954 | =begin original |
| 6637 | 7955 | |
| 6638 | 7956 | or how about sorted by key: |
| 6639 | 7957 | |
| 6640 | 7958 | =end original |
| 6641 | 7959 | |
| 6642 | 7960 | key でソートしてもいいでしょう: |
| 6643 | 7961 | |
| 6644 | foreach $key (sort(keys %ENV)) { | |
| 7962 | foreach my $key (sort(keys %ENV)) { | |
| 6645 | 7963 | print $key, '=', $ENV{$key}, "\n"; |
| 6646 | 7964 | } |
| 6647 | 7965 | |
| 6648 | 7966 | =begin original |
| 6649 | 7967 | |
| 6650 | 7968 | The returned values are copies of the original keys in the hash, so |
| 6651 | modifying them will not affect the original hash. Compare | |
| 7969 | modifying them will not affect the original hash. Compare | |
| 7970 | L<C<values>|/values HASH>. | |
| 6652 | 7971 | |
| 6653 | 7972 | =end original |
| 6654 | 7973 | |
| 6655 | 7974 | 返される値はハッシュにある元のキーのコピーなので、 |
| 6656 | 7975 | これを変更しても元のハッシュには影響を与えません。 |
| 6657 | L</values> と比較してください。 | |
| 7976 | L<C<values>|/values HASH> と比較してください。 | |
| 6658 | 7977 | |
| 6659 | 7978 | =begin original |
| 6660 | 7979 | |
| 6661 | To sort a hash by value, you'll need to use a | |
| 7980 | To sort a hash by value, you'll need to use a | |
| 6662 | Here's a descending numeric | |
| 7981 | L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric | |
| 7982 | sort of a hash by its values: | |
| 6663 | 7983 | |
| 6664 | 7984 | =end original |
| 6665 | 7985 | |
| 6666 | ハッシュを値でソートするためには、C<sort> 関数を使う | |
| 7986 | ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う | |
| 7987 | 必要があります。 | |
| 6667 | 7988 | 以下ではハッシュの値を数値の降順でソートしています: |
| 6668 | 7989 | |
| 6669 | foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { | |
| 7990 | foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { | |
| 6670 | 7991 | printf "%4d %s\n", $hash{$key}, $key; |
| 6671 | 7992 | } |
| 6672 | 7993 | |
| 6673 | 7994 | =begin original |
| 6674 | 7995 | |
| 6675 | Used as an lvalue, C<keys> allows you to increase the | |
| 7996 | Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the | |
| 7997 | number of hash buckets | |
| 6676 | 7998 | allocated for the given hash. This can gain you a measure of efficiency if |
| 6677 | 7999 | you know the hash is going to get big. (This is similar to pre-extending |
| 6678 | 8000 | an array by assigning a larger number to $#array.) If you say |
| 6679 | 8001 | |
| 6680 | 8002 | =end original |
| 6681 | 8003 | |
| 6682 | 左辺値として使うことで、C<keys> を使うことで与えられたハッシュに | |
| 8004 | 左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに | |
| 6683 | ハッシュ表の大きさを増やすことができます。 | |
| 8005 | 割り当てられたハッシュ表の大きさを増やすことができます。 | |
| 6684 | 8006 | これによって、ハッシュが大きくなっていくなっていくときの |
| 6685 | 8007 | 効率の測定ができます。 |
| 6686 | 8008 | (これは大きい値を $#array に代入することで配列を予め拡張することに |
| 6687 | 8009 | 似ています。) |
| 6688 | 8010 | 以下のようにすると: |
| 6689 | 8011 | |
| 6690 | 8012 | keys %hash = 200; |
| 6691 | 8013 | |
| 6692 | 8014 | =begin original |
| 6693 | 8015 | |
| 6694 | 8016 | then C<%hash> will have at least 200 buckets allocated for it--256 of them, |
| 6695 | 8017 | in fact, since it rounds up to the next power of two. These |
| 6696 | 8018 | buckets will be retained even if you do C<%hash = ()>, use C<undef |
| 6697 | 8019 | %hash> if you want to free the storage while C<%hash> is still in scope. |
| 6698 | 8020 | You can't shrink the number of buckets allocated for the hash using |
| 6699 | C<keys> in this way (but you needn't worry about doing | |
| 8021 | L<C<keys>|/keys HASH> in this way (but you needn't worry about doing | |
| 6700 | as trying has no effect). C<keys @array> in an lvalue | |
| 8022 | this by accident, as trying has no effect). C<keys @array> in an lvalue | |
| 6701 | error. | |
| 8023 | context is a syntax error. | |
| 6702 | 8024 | |
| 6703 | 8025 | =end original |
| 6704 | 8026 | |
| 6705 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
| 8027 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
| 6706 | 8028 | 実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。 |
| 6707 | 8029 | この表はたとえ C<%hash = ()> としても残るので、 |
| 6708 | 8030 | もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は |
| 6709 | 8031 | C<undef %hash> を使います。 |
| 6710 | この方法で C<keys> を使うことで、表の大きさを小さくすることは | |
| 8032 | この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは | |
| 8033 | できません | |
| 6711 | 8034 | (間違えてそのようなことをしても何も起きないので気にすることはありません)。 |
| 6712 | 8035 | 左辺値コンテキストでの C<keys @array> は文法エラーとなります。 |
| 6713 | 8036 | |
| 6714 | 8037 | =begin original |
| 6715 | 8038 | |
| 6716 | Starting with Perl 5.14, | |
| 8039 | Starting with Perl 5.14, an experimental feature allowed | |
| 6717 | ||
| 8040 | L<C<keys>|/keys HASH> to take a scalar expression. This experiment has | |
| 6718 | ||
| 8041 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
| 6719 | experimental. The exact behaviour may change in a future version of Perl. | |
| 6720 | 8042 | |
| 6721 | 8043 | =end original |
| 6722 | 8044 | |
| 6723 | Perl 5.14 から、C<keys> | |
| 8045 | Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来るという | |
| 6724 | ||
| 8046 | 実験的機能がありました。 | |
| 6725 | ||
| 8047 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 6726 | C<keys> のこの動作は高度に実験的であると考えられています。 | |
| 6727 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 6728 | 8048 | |
| 6729 | for (keys $hashref) { ... } | |
| 6730 | for (keys $obj->get_arrayref) { ... } | |
| 6731 | ||
| 6732 | 8049 | =begin original |
| 6733 | 8050 | |
| 6734 | 8051 | To avoid confusing would-be users of your code who are running earlier |
| 6735 | 8052 | versions of Perl with mysterious syntax errors, put this sort of thing at |
| 6736 | 8053 | the top of your file to signal that your code will work I<only> on Perls of |
| 6737 | 8054 | a recent vintage: |
| 6738 | 8055 | |
| 6739 | 8056 | =end original |
| 6740 | 8057 | |
| 6741 | 8058 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
| 6742 | 8059 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
| 6743 | 8060 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
| 6744 | 8061 | 書いてください: |
| 6745 | 8062 | |
| 6746 | use 5. | |
| 8063 | use v5.12; # so keys/values/each work on arrays | |
| 6747 | use 5.014; # so keys/values/each work on scalars (experimental) | |
| 6748 | 8064 | |
| 6749 | 8065 | =begin original |
| 6750 | 8066 | |
| 6751 | See also C<each>, C<values>, and | |
| 8067 | See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and | |
| 8068 | L<C<sort>|/sort SUBNAME LIST>. | |
| 6752 | 8069 | |
| 6753 | 8070 | =end original |
| 6754 | 8071 | |
| 6755 | C<each>, C<values> | |
| 8072 | L<C<each>|/each HASH>, L<C<values>|/values HASH>, | |
| 8073 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
| 6756 | 8074 | |
| 6757 | 8075 | =item kill SIGNAL, LIST |
| 6758 | 8076 | |
| 6759 | 8077 | =item kill SIGNAL |
| 6760 | 8078 | X<kill> X<signal> |
| 6761 | 8079 | |
| 6762 | 8080 | =for Pod::Functions send a signal to a process or process group |
| 6763 | 8081 | |
| 6764 | 8082 | =begin original |
| 6765 | 8083 | |
| 6766 | Sends a signal to a list of processes. Returns the number of | |
| 8084 | Sends a signal to a list of processes. Returns the number of arguments | |
| 6767 | ||
| 8085 | that were successfully used to signal (which is not necessarily the same | |
| 6768 | ||
| 8086 | as the number of processes actually killed, e.g. where a process group is | |
| 8087 | killed). | |
| 6769 | 8088 | |
| 6770 | 8089 | =end original |
| 6771 | 8090 | |
| 6772 | 8091 | プロセスのリストにシグナルを送ります。 |
| 6773 | シグナル送信に | |
| 8092 | シグナル送信に使われた引数の数を返します | |
| 6774 | (実際に kill | |
| 8093 | (例えばプロセスグループが kill された場合のように、実際に kill された | |
| 8094 | プロセスの数と同じとは限りません)。 | |
| 6775 | 8095 | |
| 6776 | $cnt = kill 'HUP', $child1, $child2; | |
| 8096 | my $cnt = kill 'HUP', $child1, $child2; | |
| 6777 | 8097 | kill 'KILL', @goners; |
| 6778 | 8098 | |
| 6779 | 8099 | =begin original |
| 6780 | 8100 | |
| 6781 | 8101 | SIGNAL may be either a signal name (a string) or a signal number. A signal |
| 6782 | 8102 | name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the |
| 6783 | 8103 | same signal. The string form of SIGNAL is recommended for portability because |
| 6784 | 8104 | the same signal may have different numbers in different operating systems. |
| 6785 | 8105 | |
| 6786 | 8106 | =end original |
| 6787 | 8107 | |
| 6788 | 8108 | SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。 |
| 6789 | 8109 | シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ |
| 6790 | 8110 | シグナルを意味します。 |
| 6791 | 8111 | 移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった |
| 6792 | 8112 | オペレーティングシステムでは異なった番号になることがあるからです。 |
| 6793 | 8113 | |
| 6794 | 8114 | =begin original |
| 6795 | 8115 | |
| 6796 | 8116 | A list of signal names supported by the current platform can be found in |
| 6797 | C<$Config{sig_name}>, which is provided by the C<Config> | |
| 8117 | C<$Config{sig_name}>, which is provided by the L<C<Config>|Config> | |
| 6798 | for more details. | |
| 8118 | module. See L<Config> for more details. | |
| 6799 | 8119 | |
| 6800 | 8120 | =end original |
| 6801 | 8121 | |
| 6802 | 現在のプラットフォームが対応しているシグナル名の一覧は、C<Config> | |
| 8122 | 現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config> | |
| 6803 | 8123 | モジュールによって提供される C<$Config{sig_name}> にあります。 |
| 6804 | 8124 | さらなる詳細については L<Config> を参照してください。 |
| 6805 | 8125 | |
| 6806 | 8126 | =begin original |
| 6807 | 8127 | |
| 6808 | 8128 | A negative signal name is the same as a negative signal number, killing process |
| 6809 | 8129 | groups instead of processes. For example, C<kill '-KILL', $pgrp> and |
| 6810 | C<kill -9, $pgrp> will send C<SIGKILL> to | |
| 8130 | C<kill -9, $pgrp> will send C<SIGKILL> to | |
| 8131 | the entire process group specified. That | |
| 6811 | 8132 | means you usually want to use positive not negative signals. |
| 6812 | 8133 | |
| 6813 | 8134 | =end original |
| 6814 | 8135 | |
| 6815 | 8136 | 負のシグナル名は負のシグナル番号と同じで、 |
| 6816 | 8137 | プロセスではなくプロセスグループに対して kill を行ないます。 |
| 6817 | 8138 | たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された |
| 6818 | 8139 | プロセスグループ全体に C<SIGKILL> を送ります。 |
| 6819 | 8140 | すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。 |
| 6820 | 8141 | |
| 6821 | 8142 | =begin original |
| 6822 | 8143 | |
| 6823 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZ | |
| 8144 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>), | |
| 6824 | no signal is sent to | |
| 8145 | no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST> | |
| 6825 | ||
| 8146 | checks whether it's I<possible> to send a signal to it | |
| 6826 | 8147 | (that means, to be brief, that the process is owned by the same user, or we are |
| 6827 | 8148 | the super-user). This is useful to check that a child process is still |
| 6828 | 8149 | alive (even if only as a zombie) and hasn't changed its UID. See |
| 6829 | 8150 | L<perlport> for notes on the portability of this construct. |
| 6830 | 8151 | |
| 6831 | 8152 | =end original |
| 6832 | 8153 | |
| 6833 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZ | |
| 8154 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに | |
| 6834 | シグナルは送られませんが、C<kill> | |
| 8155 | シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、 | |
| 6835 | 調べます (これは、簡単に言うと | |
| 8156 | シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、 | |
| 6836 | 自分がスーパーユーザーであることを | |
| 8157 | プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを | |
| 8158 | 意味します)。 | |
| 6837 | 8159 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が |
| 6838 | 8160 | 変わっていないことを調べる時に有用です。 |
| 6839 | 8161 | この構成の移植性に関する注意については L<perlport> を参照してください。 |
| 6840 | 8162 | |
| 6841 | 8163 | =begin original |
| 6842 | 8164 | |
| 6843 | 8165 | The behavior of kill when a I<PROCESS> number is zero or negative depends on |
| 6844 | 8166 | the operating system. For example, on POSIX-conforming systems, zero will |
| 6845 | 8167 | signal the current process group, -1 will signal all processes, and any |
| 6846 | 8168 | other negative PROCESS number will act as a negative signal number and |
| 6847 | 8169 | kill the entire process group specified. |
| 6848 | 8170 | |
| 6849 | 8171 | =end original |
| 6850 | 8172 | |
| 6851 | 8173 | I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは |
| 6852 | 8174 | オペレーティングシステムに依存します。 |
| 6853 | 8175 | 例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、 |
| 6854 | 8176 | -1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は |
| 6855 | 8177 | 負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。 |
| 6856 | 8178 | |
| 6857 | 8179 | =begin original |
| 6858 | 8180 | |
| 6859 | 8181 | If both the SIGNAL and the PROCESS are negative, the results are undefined. |
| 6860 | 8182 | A warning may be produced in a future version. |
| 6861 | 8183 | |
| 6862 | 8184 | =end original |
| 6863 | 8185 | |
| 6864 | 8186 | SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。 |
| 6865 | 8187 | 将来のバージョンでは警告が出るかも知れません。 |
| 6866 | 8188 | |
| 6867 | 8189 | =begin original |
| 6868 | 8190 | |
| 6869 | 8191 | See L<perlipc/"Signals"> for more details. |
| 6870 | 8192 | |
| 6871 | 8193 | =end original |
| 6872 | 8194 | |
| 6873 | 8195 | 詳細は L<perlipc/"Signals"> を参照してください。 |
| 6874 | 8196 | |
| 6875 | 8197 | =begin original |
| 6876 | 8198 | |
| 6877 | On some platforms such as Windows where the fork() system call is not | |
| 8199 | On some platforms such as Windows where the L<fork(2)> system call is not | |
| 6878 | Perl can be built to emulate fork | |
| 8200 | available, Perl can be built to emulate L<C<fork>|/fork> at the | |
| 8201 | interpreter level. | |
| 6879 | 8202 | This emulation has limitations related to kill that have to be considered, |
| 6880 | 8203 | for code running on Windows and in code intended to be portable. |
| 6881 | 8204 | |
| 6882 | 8205 | =end original |
| 6883 | 8206 | |
| 6884 | Windows のような fork() が利用不能なシステムでは、Perl は | |
| 8207 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
| 6885 | インタプリタレベルでエミュレートします。 | |
| 8208 | L<C<fork>|/fork> をインタプリタレベルでエミュレートします。 | |
| 6886 | 8209 | エミュレーションは kill に関連して、コードが Windows で実行されて |
| 6887 | 8210 | しかしコードが移植性があると考えられるように制限があります。 |
| 6888 | 8211 | |
| 6889 | 8212 | =begin original |
| 6890 | 8213 | |
| 6891 | 8214 | See L<perlfork> for more details. |
| 6892 | 8215 | |
| 6893 | 8216 | =end original |
| 6894 | 8217 | |
| 6895 | 8218 | さらなる詳細については L<perlfork> を参照してください。 |
| 6896 | 8219 | |
| 6897 | 8220 | =begin original |
| 6898 | 8221 | |
| 6899 | 8222 | If there is no I<LIST> of processes, no signal is sent, and the return |
| 6900 | 8223 | value is 0. This form is sometimes used, however, because it causes |
| 6901 | tainting checks to be run. But see | |
| 8224 | tainting checks to be run, if your perl support taint checks. But see | |
| 6902 | 8225 | L<perlsec/Laundering and Detecting Tainted Data>. |
| 6903 | 8226 | |
| 6904 | 8227 | =end original |
| 6905 | 8228 | |
| 6906 | 8229 | 処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。 |
| 6907 | しかし、この形式は時々使われます; | |
| 8230 | しかし、この形式は時々使われます; perl が汚染チェックに対応している場合、 | |
| 6908 | 引き起こすからです。 | |
| 8231 | 実行するために汚染チェックを引き起こすからです。 | |
| 6909 | 8232 | しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。 |
| 6910 | 8233 | |
| 6911 | 8234 | =begin original |
| 6912 | 8235 | |
| 6913 | 8236 | Portability issues: L<perlport/kill>. |
| 6914 | 8237 | |
| 6915 | 8238 | =end original |
| 6916 | 8239 | |
| 6917 | 8240 | 移植性の問題: L<perlport/kill>。 |
| 6918 | 8241 | |
| 6919 | 8242 | =item last LABEL |
| 6920 | 8243 | X<last> X<break> |
| 6921 | 8244 | |
| 6922 | 8245 | =item last EXPR |
| 6923 | 8246 | |
| 6924 | 8247 | =item last |
| 6925 | 8248 | |
| 6926 | 8249 | =for Pod::Functions exit a block prematurely |
| 6927 | 8250 | |
| 6928 | 8251 | =begin original |
| 6929 | 8252 | |
| 6930 | The C<last> command is like the C<break> statement in C | |
| 8253 | The L<C<last>|/last LABEL> command is like the C<break> statement in C | |
| 8254 | (as used in | |
| 6931 | 8255 | loops); it immediately exits the loop in question. If the LABEL is |
| 6932 | 8256 | omitted, the command refers to the innermost enclosing |
| 6933 | 8257 | loop. The C<last EXPR> form, available starting in Perl |
| 6934 | 8258 | 5.18.0, allows a label name to be computed at run time, |
| 6935 | 8259 | and is otherwise identical to C<last LABEL>. The |
| 6936 | C<continue> block, if any, is not executed: | |
| 8260 | L<C<continue>|/continue BLOCK> block, if any, is not executed: | |
| 6937 | 8261 | |
| 6938 | 8262 | =end original |
| 6939 | 8263 | |
| 6940 | C<last> コマンドは、(ループ内で使った) C の C<break> 文と | |
| 8264 | L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と | |
| 6941 | 8265 | 同じようなもので、LABEL で指定されるループを即座に抜けます。 |
| 6942 | 8266 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
| 6943 | 8267 | Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される |
| 6944 | 8268 | ラベル名を使えます; それ以外は C<last LABEL> と同一です。 |
| 6945 | C<continue> ブロックがあっても実行されません: | |
| 8269 | L<C<continue>|/continue BLOCK> ブロックがあっても実行されません: | |
| 6946 | 8270 | |
| 6947 | 8271 | LINE: while (<STDIN>) { |
| 6948 | 8272 | last LINE if /^$/; # exit when done with header |
| 6949 | 8273 | #... |
| 6950 | 8274 | } |
| 6951 | 8275 | |
| 6952 | 8276 | =begin original |
| 6953 | 8277 | |
| 6954 | C<last> cannot | |
| 8278 | L<C<last>|/last LABEL> cannot return a value from a block that typically | |
| 6955 | C<eval {}>, C<sub {}>, or C<do {}> | |
| 8279 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
| 6956 | ||
| 8280 | its flow control behavior, which precludes any return value. It should not be | |
| 8281 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 8282 | operation. | |
| 6957 | 8283 | |
| 6958 | 8284 | =end original |
| 6959 | 8285 | |
| 6960 | C<last> は C<eval {}>, C<sub {}>, C<do {}> といった | |
| 8286 | L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
| 6961 | 値を返すブロックを | |
| 8287 | 典型的には値を返すブロックから値を返せません。 | |
| 6962 | ||
| 8288 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
| 8289 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 8290 | 使うべきではありません。 | |
| 6963 | 8291 | |
| 6964 | 8292 | =begin original |
| 6965 | 8293 | |
| 6966 | 8294 | Note that a block by itself is semantically identical to a loop |
| 6967 | that executes once. Thus C<last> can be used to effect | |
| 8295 | that executes once. Thus L<C<last>|/last LABEL> can be used to effect | |
| 6968 | exit out of such a block. | |
| 8296 | an early exit out of such a block. | |
| 6969 | 8297 | |
| 6970 | 8298 | =end original |
| 6971 | 8299 | |
| 6972 | 8300 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
| 6973 | 8301 | 注意してください。 |
| 6974 | 従って、C<last> でそのようなブロックを途中で | |
| 8302 | 従って、L<C<last>|/last LABEL> でそのようなブロックを途中で | |
| 8303 | 抜け出すことができます。 | |
| 6975 | 8304 | |
| 6976 | 8305 | =begin original |
| 6977 | 8306 | |
| 6978 | See also L</continue> for an illustration of how | |
| 8307 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
| 6979 | C< | |
| 8308 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
| 8309 | L<C<redo>|/redo LABEL> work. | |
| 6980 | 8310 | |
| 6981 | 8311 | =end original |
| 6982 | 8312 | |
| 6983 | C<last>, C<next>, C<redo> が | |
| 8313 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
| 6984 | L</continue> も参照してください。 | |
| 8314 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
| 6985 | 8315 | |
| 6986 | 8316 | =begin original |
| 6987 | 8317 | |
| 6988 | 8318 | Unlike most named operators, this has the same precedence as assignment. |
| 6989 | 8319 | It is also exempt from the looks-like-a-function rule, so |
| 6990 | 8320 | C<last ("foo")."bar"> will cause "bar" to be part of the argument to |
| 6991 | C<last>. | |
| 8321 | L<C<last>|/last LABEL>. | |
| 6992 | 8322 | |
| 6993 | 8323 | =end original |
| 6994 | 8324 | |
| 6995 | 8325 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
| 6996 | 8326 | また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と |
| 6997 | すると "bar" は C<last> への引数の一部となります。 | |
| 8327 | すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。 | |
| 6998 | 8328 | |
| 6999 | 8329 | =item lc EXPR |
| 7000 | 8330 | X<lc> X<lowercase> |
| 7001 | 8331 | |
| 7002 | 8332 | =item lc |
| 7003 | 8333 | |
| 7004 | 8334 | =for Pod::Functions return lower-case version of a string |
| 7005 | 8335 | |
| 7006 | 8336 | =begin original |
| 7007 | 8337 | |
| 7008 | Returns a lowercased version of EXPR. | |
| 8338 | Returns a lowercased version of EXPR. If EXPR is omitted, uses | |
| 7009 | ||
| 8339 | L<C<$_>|perlvar/$_>. | |
| 7010 | 8340 | |
| 7011 | 8341 | =end original |
| 7012 | 8342 | |
| 7013 | 8343 | EXPR を小文字に変換したものを返します。 |
| 7014 | ||
| 8344 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 7015 | C<\L> エスケープを実装する内部関数です。 | |
| 7016 | 8345 | |
| 7017 | = | |
| 8346 | my $str = lc("Perl is GREAT"); # "perl is great" | |
| 7018 | 8347 | |
| 7019 | If EXPR is omitted, uses C<$_>. | |
| 7020 | ||
| 7021 | =end original | |
| 7022 | ||
| 7023 | EXPR が省略されると、C<$_> を使います。 | |
| 7024 | ||
| 7025 | 8348 | =begin original |
| 7026 | 8349 | |
| 7027 | 8350 | What gets returned depends on several factors: |
| 7028 | 8351 | |
| 7029 | 8352 | =end original |
| 7030 | 8353 | |
| 7031 | 8354 | 返り値として得られるものは色々な要素に依存します: |
| 7032 | 8355 | |
| 7033 | 8356 | =over |
| 7034 | 8357 | |
| 7035 | 8358 | =item If C<use bytes> is in effect: |
| 7036 | 8359 | |
| 7037 | 8360 | (C<use bytes> が有効の場合) |
| 7038 | 8361 | |
| 7039 | 8362 | =begin original |
| 7040 | 8363 | |
| 7041 | The results follow ASCII | |
| 8364 | The results follow ASCII rules. Only the characters C<A-Z> change, | |
| 7042 | respectively. | |
| 8365 | to C<a-z> respectively. | |
| 7043 | 8366 | |
| 7044 | 8367 | =end original |
| 7045 | 8368 | |
| 7046 | 結果は ASCII の | |
| 8369 | 結果は ASCII の規則に従います。 | |
| 7047 | 8370 | C<A-Z> のみが変換され、それぞれ C<a-z> になります。 |
| 7048 | 8371 | |
| 7049 | =item Otherwise, if C<use locale> | |
| 8372 | =item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect: | |
| 7050 | 8373 | |
| 7051 | (それ以外の場合で、C< | |
| 8374 | (それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合) | |
| 7052 | 8375 | |
| 7053 | 8376 | =begin original |
| 7054 | 8377 | |
| 7055 | Respects current LC_CTYPE locale for code points < 256; and uses Unicode | |
| 8378 | Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode | |
| 7056 | ||
| 8379 | rules for the remaining code points (this last can only happen if | |
| 7057 | 8380 | the UTF8 flag is also set). See L<perllocale>. |
| 7058 | 8381 | |
| 7059 | 8382 | =end original |
| 7060 | 8383 | |
| 7061 | 符号位置 < 256 に対しては現在の LC_CTYPE ロケールに従います; そして | |
| 8384 | 符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして | |
| 7062 | 残りの符号位置に付いては Unicode の | |
| 8385 | 残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも | |
| 7063 | 8386 | 設定されている場合にのみ起こります)。 |
| 7064 | 8387 | L<perllocale> を参照してください。 |
| 7065 | 8388 | |
| 7066 | 8389 | =begin original |
| 7067 | 8390 | |
| 7068 | ||
| 8391 | Starting in v5.20, Perl uses full Unicode rules if the locale is | |
| 8392 | UTF-8. Otherwise, there is a deficiency in this scheme, which is that | |
| 8393 | case changes that cross the 255/256 | |
| 7069 | 8394 | boundary are not well-defined. For example, the lower case of LATIN CAPITAL |
| 7070 | LETTER SHARP S (U+1E9E) in Unicode | |
| 8395 | LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII | |
| 7071 | platforms). But under C<use locale> | |
| 8396 | platforms). But under C<use locale> (prior to v5.20 or not a UTF-8 | |
| 8397 | locale), the lower case of U+1E9E is | |
| 7072 | 8398 | itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the |
| 7073 | 8399 | current locale, and Perl has no way of knowing if that character even |
| 7074 | 8400 | exists in the locale, much less what code point it is. Perl returns |
| 7075 | the input character unchanged, | |
| 8401 | a result that is above 255 (almost always the input character unchanged), | |
| 7076 | many) where the 255/256 boundary | |
| 8402 | for all instances (and there aren't many) where the 255/256 boundary | |
| 8403 | would otherwise be crossed; and starting in v5.22, it raises a | |
| 8404 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning. | |
| 7077 | 8405 | |
| 7078 | 8406 | =end original |
| 7079 | 8407 | |
| 7080 | ||
| 8408 | v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。 | |
| 7081 | ||
| 8409 | さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は | |
| 8410 | 未定義であるという欠点があります。 | |
| 7082 | 8411 | 例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は |
| 7083 | 8412 | (ASCII プラットフォームでは) U+00DF です。 |
| 7084 | しかし C<use locale> が有効なら、U+1E9E の | |
| 8413 | しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の | |
| 7085 | 0xDF は現在のロケールで | |
| 8414 | 小文字は自分自身です; なぜなら 0xDF は現在のロケールでは | |
| 7086 | 例えこのロケールに文字が | |
| 8415 | LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が | |
| 7087 | どの符号位置かを知る方法が | |
| 8416 | 存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が | |
| 8417 | ないからです。 | |
| 7088 | 8418 | Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については |
| 7089 | 入力文字を変更せずに返します | |
| 8419 | (ほとんど常に入力文字を変更せずに)256 以上の値を返します; | |
| 8420 | そして v5.22 から | |
| 8421 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> | |
| 8422 | 警告を出力します。 | |
| 7090 | 8423 | |
| 7091 | 8424 | =item Otherwise, If EXPR has the UTF8 flag set: |
| 7092 | 8425 | |
| 7093 | 8426 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) |
| 7094 | 8427 | |
| 7095 | 8428 | =begin original |
| 7096 | 8429 | |
| 7097 | Unicode | |
| 8430 | Unicode rules are used for the case change. | |
| 7098 | 8431 | |
| 7099 | 8432 | =end original |
| 7100 | 8433 | |
| 7101 | 大文字小文字変換には Unicode の | |
| 8434 | 大文字小文字変換には Unicode の規則が使われます。 | |
| 7102 | 8435 | |
| 7103 | 8436 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect: |
| 7104 | 8437 | |
| 7105 | 8438 | (それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合) |
| 7106 | 8439 | |
| 7107 | 8440 | =begin original |
| 7108 | 8441 | |
| 7109 | Unicode | |
| 8442 | Unicode rules are used for the case change. | |
| 7110 | 8443 | |
| 7111 | 8444 | =end original |
| 7112 | 8445 | |
| 7113 | 大文字小文字変換には Unicode の | |
| 8446 | 大文字小文字変換には Unicode の規則が使われます。 | |
| 7114 | 8447 | |
| 7115 | 8448 | =item Otherwise: |
| 7116 | 8449 | |
| 7117 | 8450 | (それ以外の場合) |
| 7118 | 8451 | |
| 7119 | 8452 | =begin original |
| 7120 | 8453 | |
| 7121 | ASCII | |
| 8454 | ASCII rules are used for the case change. The lowercase of any character | |
| 7122 | 8455 | outside the ASCII range is the character itself. |
| 7123 | 8456 | |
| 7124 | 8457 | =end original |
| 7125 | 8458 | |
| 7126 | 大文字小文字変換には ASCII の | |
| 8459 | 大文字小文字変換には ASCII の規則が使われます。 | |
| 7127 | 8460 | ASCII の範囲外の文字の「小文字」はその文字自身です。 |
| 7128 | 8461 | |
| 7129 | 8462 | =back |
| 7130 | 8463 | |
| 8464 | =begin original | |
| 8465 | ||
| 8466 | B<Note:> This is the internal function implementing the | |
| 8467 | L<C<\L>|perlop/"Quote and Quote-like Operators"> escape in double-quoted | |
| 8468 | strings. | |
| 8469 | ||
| 8470 | =end original | |
| 8471 | ||
| 8472 | B<注意:> これは、ダブルクォート文字列における、 | |
| 8473 | L<C<\L>|perlop/"Quote and Quote-like Operators"> エスケープを実装する | |
| 8474 | 内部関数です。 | |
| 8475 | ||
| 8476 | my $str = "Perl is \LGREAT\E"; # "Perl is great" | |
| 8477 | ||
| 7131 | 8478 | =item lcfirst EXPR |
| 7132 | 8479 | X<lcfirst> X<lowercase> |
| 7133 | 8480 | |
| 7134 | 8481 | =item lcfirst |
| 7135 | 8482 | |
| 7136 | 8483 | =for Pod::Functions return a string with just the next letter in lower case |
| 7137 | 8484 | |
| 7138 | 8485 | =begin original |
| 7139 | 8486 | |
| 7140 | 8487 | Returns the value of EXPR with the first character lowercased. This |
| 7141 | 8488 | is the internal function implementing the C<\l> escape in |
| 7142 | 8489 | double-quoted strings. |
| 7143 | 8490 | |
| 7144 | 8491 | =end original |
| 7145 | 8492 | |
| 7146 | 8493 | 最初の文字だけを小文字にした、EXPR を返します。 |
| 7147 | 8494 | これは、ダブルクォート文字列における、C<\l> エスケープを |
| 7148 | 8495 | 実装する内部関数です。 |
| 7149 | 8496 | |
| 7150 | 8497 | =begin original |
| 7151 | 8498 | |
| 7152 | If EXPR is omitted, uses C<$_>. | |
| 8499 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 7153 | 8500 | |
| 7154 | 8501 | =end original |
| 7155 | 8502 | |
| 7156 | EXPR が省略されると、C<$_> を使います。 | |
| 8503 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 7157 | 8504 | |
| 7158 | 8505 | =begin original |
| 7159 | 8506 | |
| 7160 | This function behaves the same way under various pragma | |
| 8507 | This function behaves the same way under various pragmas, such as in a locale, | |
| 7161 | as L</lc> does. | |
| 8508 | as L<C<lc>|/lc EXPR> does. | |
| 7162 | 8509 | |
| 7163 | 8510 | =end original |
| 7164 | 8511 | |
| 7165 | 8512 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 |
| 7166 | L</lc> と同様に振る舞います。 | |
| 8513 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 7167 | 8514 | |
| 7168 | 8515 | =item length EXPR |
| 7169 | 8516 | X<length> X<size> |
| 7170 | 8517 | |
| 7171 | 8518 | =item length |
| 7172 | 8519 | |
| 7173 | 8520 | =for Pod::Functions return the number of characters in a string |
| 7174 | 8521 | |
| 7175 | 8522 | =begin original |
| 7176 | 8523 | |
| 7177 | 8524 | Returns the length in I<characters> of the value of EXPR. If EXPR is |
| 7178 | omitted, returns the length of C<$_>. If EXPR i | |
| 8525 | omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is | |
| 7179 | C<undef>. | |
| 8526 | undefined, returns L<C<undef>|/undef EXPR>. | |
| 7180 | 8527 | |
| 7181 | 8528 | =end original |
| 7182 | 8529 | |
| 7183 | 8530 | EXPR の値の I<文字> の長さを返します。 |
| 7184 | EXPR が省略されたときには、C<$_> の長さを返します。 | |
| 8531 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。 | |
| 7185 | EXPR が未定義値の場合、C<undef> を返します。 | |
| 8532 | EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。 | |
| 7186 | 8533 | |
| 7187 | 8534 | =begin original |
| 7188 | 8535 | |
| 7189 | 8536 | This function cannot be used on an entire array or hash to find out how |
| 7190 | 8537 | many elements these have. For that, use C<scalar @array> and C<scalar keys |
| 7191 | 8538 | %hash>, respectively. |
| 7192 | 8539 | |
| 7193 | 8540 | =end original |
| 7194 | 8541 | |
| 7195 | 8542 | この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを |
| 7196 | 8543 | 調べるためには使えません。 |
| 7197 | 8544 | そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を |
| 7198 | 8545 | 利用してください。 |
| 7199 | 8546 | |
| 7200 | 8547 | =begin original |
| 7201 | 8548 | |
| 7202 | Like all Perl character operations, length | |
| 8549 | Like all Perl character operations, L<C<length>|/length EXPR> normally | |
| 8550 | deals in logical | |
| 7203 | 8551 | characters, not physical bytes. For how many bytes a string encoded as |
| 7204 | UTF-8 would take up, use C<length(Encode::encode | |
| 8552 | UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))> | |
| 7205 | to C<use Encode> first). See L<Encode> and L<perlunicode>. | |
| 8553 | (you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>. | |
| 7206 | 8554 | |
| 7207 | 8555 | =end original |
| 7208 | 8556 | |
| 7209 | 全ての Perl の文字操作と同様、length | |
| 8557 | 全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な | |
| 7210 | 論理文字を扱います。 | |
| 8558 | バイトではなく論理文字を扱います。 | |
| 7211 | 8559 | UTF-8 でエンコードされた文字列が何バイトかを知るには、 |
| 7212 | C<length(Encode::encode | |
| 8560 | C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に | |
| 7213 | 8561 | C<use Encode> する必要があります)。 |
| 7214 | 8562 | L<Encode> と L<perlunicode> を参照してください。 |
| 7215 | 8563 | |
| 7216 | 8564 | =item __LINE__ |
| 7217 | 8565 | X<__LINE__> |
| 7218 | 8566 | |
| 7219 | 8567 | =for Pod::Functions the current source line number |
| 7220 | 8568 | |
| 7221 | 8569 | =begin original |
| 7222 | 8570 | |
| 7223 | 8571 | A special token that compiles to the current line number. |
| 8572 | It can be altered by the mechanism described at | |
| 8573 | L<perlsyn/"Plain Old Comments (Not!)">. | |
| 7224 | 8574 | |
| 7225 | 8575 | =end original |
| 7226 | 8576 | |
| 7227 | 8577 | 現在の行番号にコンパイルされる特殊トークン。 |
| 8578 | L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って | |
| 8579 | 置き換えられます。 | |
| 7228 | 8580 | |
| 7229 | 8581 | =item link OLDFILE,NEWFILE |
| 7230 | 8582 | X<link> |
| 7231 | 8583 | |
| 7232 | 8584 | =for Pod::Functions create a hard link in the filesystem |
| 7233 | 8585 | |
| 7234 | 8586 | =begin original |
| 7235 | 8587 | |
| 7236 | 8588 | Creates a new filename linked to the old filename. Returns true for |
| 7237 | 8589 | success, false otherwise. |
| 7238 | 8590 | |
| 7239 | 8591 | =end original |
| 7240 | 8592 | |
| 7241 | 8593 | OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。 |
| 7242 | 8594 | 成功時には真を、さもなければ偽を返します。 |
| 7243 | 8595 | |
| 7244 | 8596 | =begin original |
| 7245 | 8597 | |
| 7246 | 8598 | Portability issues: L<perlport/link>. |
| 7247 | 8599 | |
| 7248 | 8600 | =end original |
| 7249 | 8601 | |
| 7250 | 8602 | 移植性の問題: L<perlport/link>。 |
| 7251 | 8603 | |
| 7252 | 8604 | =item listen SOCKET,QUEUESIZE |
| 7253 | 8605 | X<listen> |
| 7254 | 8606 | |
| 7255 | 8607 | =for Pod::Functions register your socket as a server |
| 7256 | 8608 | |
| 7257 | 8609 | =begin original |
| 7258 | 8610 | |
| 7259 | Does the same thing that the listen(2) system call does. Returns true if | |
| 8611 | Does the same thing that the L<listen(2)> system call does. Returns true if | |
| 7260 | 8612 | it succeeded, false otherwise. See the example in |
| 7261 | 8613 | L<perlipc/"Sockets: Client/Server Communication">. |
| 7262 | 8614 | |
| 7263 | 8615 | =end original |
| 7264 | 8616 | |
| 7265 | listen(2) システムコールと同じことをします。 | |
| 8617 | L<listen(2)> システムコールと同じことをします。 | |
| 7266 | 8618 | 成功時には真を、さもなければ偽を返します。 |
| 7267 | 8619 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 7268 | 8620 | |
| 7269 | 8621 | =item local EXPR |
| 7270 | 8622 | X<local> |
| 7271 | 8623 | |
| 7272 | 8624 | =for Pod::Functions create a temporary value for a global variable (dynamic scoping) |
| 7273 | 8625 | |
| 7274 | 8626 | =begin original |
| 7275 | 8627 | |
| 7276 | You really probably want to be using C<my> instead, | |
| 8628 | You really probably want to be using L<C<my>|/my VARLIST> instead, | |
| 7277 | what most people think of as | |
| 8629 | because L<C<local>|/local EXPR> isn't what most people think of as | |
| 7278 | L<perlsub/"Private Variables via my()"> for details. | |
| 8630 | "local". See L<perlsub/"Private Variables via my()"> for details. | |
| 7279 | 8631 | |
| 7280 | 8632 | =end original |
| 7281 | 8633 | |
| 7282 | あなたはが本当に望んでいるのは C<my> の方でしょう; | |
| 8634 | あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう; | |
| 7283 | 人々が「ローカル」と考えるものと | |
| 8635 | L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと | |
| 7284 | ||
| 8636 | 違うからです。 | |
| 8637 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
| 7285 | 8638 | |
| 7286 | 8639 | =begin original |
| 7287 | 8640 | |
| 7288 | 8641 | A local modifies the listed variables to be local to the enclosing |
| 7289 | 8642 | block, file, or eval. If more than one value is listed, the list must |
| 7290 | 8643 | be placed in parentheses. See L<perlsub/"Temporary Values via local()"> |
| 7291 | 8644 | for details, including issues with tied arrays and hashes. |
| 7292 | 8645 | |
| 7293 | 8646 | =end original |
| 7294 | 8647 | |
| 7295 | 8648 | "local" はリストアップされた変数を、囲っているブロック、 |
| 7296 | 8649 | ファイル、eval の中で、ローカルなものにします。 |
| 7297 | 複数の値を指定する場合は、リストはかっこで | |
| 8650 | 複数の値を指定する場合は、リストはかっこで囲まなければなりません。 | |
| 7298 | 8651 | tie した配列とハッシュに関する事項を含む詳細については |
| 7299 | 8652 | L<perlsub/"Temporary Values via local()"> を参照してください。 |
| 7300 | 8653 | |
| 7301 | 8654 | =begin original |
| 7302 | 8655 | |
| 7303 | 8656 | The C<delete local EXPR> construct can also be used to localize the deletion |
| 7304 | 8657 | of array/hash elements to the current block. |
| 7305 | 8658 | See L<perlsub/"Localized deletion of elements of composite types">. |
| 7306 | 8659 | |
| 7307 | 8660 | =end original |
| 7308 | 8661 | |
| 7309 | 8662 | C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の |
| 7310 | 8663 | ブロックにローカル化するためにも使われていました。 |
| 7311 | 8664 | L<perlsub/"Localized deletion of elements of composite types"> を |
| 7312 | 8665 | 参照してください。 |
| 7313 | 8666 | |
| 7314 | 8667 | =item localtime EXPR |
| 7315 | 8668 | X<localtime> X<ctime> |
| 7316 | 8669 | |
| 7317 | 8670 | =item localtime |
| 7318 | 8671 | |
| 7319 | 8672 | =for Pod::Functions convert UNIX time into record or string using local time |
| 7320 | 8673 | |
| 7321 | 8674 | =begin original |
| 7322 | 8675 | |
| 7323 | 8676 | Converts a time as returned by the time function to a 9-element list |
| 7324 | 8677 | with the time analyzed for the local time zone. Typically used as |
| 7325 | 8678 | follows: |
| 7326 | 8679 | |
| 7327 | 8680 | =end original |
| 7328 | 8681 | |
| 7329 | 8682 | time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、 |
| 7330 | 8683 | 9 要素の配列に変換します。 |
| 7331 | 8684 | 普通は、以下のようにして使います: |
| 7332 | 8685 | |
| 7333 | # 0 1 2 3 4 5 6 7 8 | |
| 8686 | # 0 1 2 3 4 5 6 7 8 | |
| 7334 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
| 8687 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
| 7335 | 8688 | localtime(time); |
| 7336 | 8689 | |
| 7337 | 8690 | =begin original |
| 7338 | 8691 | |
| 7339 | 8692 | All list elements are numeric and come straight out of the C `struct |
| 7340 | 8693 | tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours |
| 7341 | 8694 | of the specified time. |
| 7342 | 8695 | |
| 7343 | 8696 | =end original |
| 7344 | 8697 | |
| 7345 | 8698 | すべてのリスト要素は数値で、C の `struct tm' 構造体から |
| 7346 | 8699 | 直接持ってきます。 |
| 7347 | 8700 | C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。 |
| 7348 | 8701 | |
| 7349 | 8702 | =begin original |
| 7350 | 8703 | |
| 7351 | 8704 | C<$mday> is the day of the month and C<$mon> the month in |
| 7352 | 8705 | the range C<0..11>, with 0 indicating January and 11 indicating December. |
| 7353 | 8706 | This makes it easy to get a month name from a list: |
| 7354 | 8707 | |
| 7355 | 8708 | =end original |
| 7356 | 8709 | |
| 7357 | 8710 | C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が |
| 7358 | 8711 | 1 月、11 が 12 月です。 |
| 7359 | 8712 | これにより、リストから月の名前を得るのが簡単になります: |
| 7360 | 8713 | |
| 7361 | 8714 | my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
| 7362 | 8715 | print "$abbr[$mon] $mday"; |
| 7363 | 8716 | # $mon=9, $mday=18 gives "Oct 18" |
| 7364 | 8717 | |
| 7365 | 8718 | =begin original |
| 7366 | 8719 | |
| 7367 | C<$year> contains the number of years since 1900. To get | |
| 8720 | C<$year> contains the number of years since 1900. To get the full | |
| 7368 | 8721 | year write: |
| 7369 | 8722 | |
| 7370 | 8723 | =end original |
| 7371 | 8724 | |
| 7372 | 8725 | C<$year> は 1900 年からの年数を持ちます。 |
| 7373 | ||
| 8726 | 完全な年を得るには以下のようにします: | |
| 7374 | 8727 | |
| 7375 | 8728 | $year += 1900; |
| 7376 | 8729 | |
| 7377 | 8730 | =begin original |
| 7378 | 8731 | |
| 7379 | 8732 | To get the last two digits of the year (e.g., "01" in 2001) do: |
| 7380 | 8733 | |
| 7381 | 8734 | =end original |
| 7382 | 8735 | |
| 7383 | 8736 | 西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします: |
| 7384 | 8737 | |
| 7385 | 8738 | $year = sprintf("%02d", $year % 100); |
| 7386 | 8739 | |
| 7387 | 8740 | =begin original |
| 7388 | 8741 | |
| 7389 | 8742 | C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating |
| 7390 | 8743 | Wednesday. C<$yday> is the day of the year, in the range C<0..364> |
| 7391 | 8744 | (or C<0..365> in leap years.) |
| 7392 | 8745 | |
| 7393 | 8746 | =end original |
| 7394 | 8747 | |
| 7395 | 8748 | C<$wday> は曜日で、0 が日曜日、3 が水曜日です。 |
| 7396 | 8749 | C<$yday> はその年の何日目かで、C<0..364> の値を取ります |
| 7397 | 8750 | (うるう年は C<0..365> です。) |
| 7398 | 8751 | |
| 7399 | 8752 | =begin original |
| 7400 | 8753 | |
| 7401 | C<$isdst> is true if the specified time occurs | |
| 8754 | C<$isdst> is true if the specified time occurs when Daylight Saving | |
| 7402 | Time, false otherwise. | |
| 8755 | Time is in effect, false otherwise. | |
| 7403 | 8756 | |
| 7404 | 8757 | =end original |
| 7405 | 8758 | |
| 7406 | C<$isdst> は指定された時刻 | |
| 8759 | C<$isdst> は指定された時刻で夏時間が有効の場合は真、そうでなければ偽です。 | |
| 7407 | 8760 | |
| 7408 | 8761 | =begin original |
| 7409 | 8762 | |
| 7410 | If EXPR is omitted, C<localtime | |
| 8763 | If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current | |
| 7411 | by time | |
| 8764 | time (as returned by L<C<time>|/time>). | |
| 7412 | 8765 | |
| 7413 | 8766 | =end original |
| 7414 | 8767 | |
| 7415 | EXPR が省略されると、C<localtime | |
| 8768 | EXPR が省略されると、L<C<localtime>|/localtime EXPR> は | |
| 7416 | 現在時刻を使います。 | |
| 8769 | (L<C<time>|/time> によって返される) 現在時刻を使います。 | |
| 7417 | 8770 | |
| 7418 | 8771 | =begin original |
| 7419 | 8772 | |
| 7420 | In scalar context, C<localtime | |
| 8773 | In scalar context, L<C<localtime>|/localtime EXPR> returns the | |
| 8774 | L<ctime(3)> value: | |
| 7421 | 8775 | |
| 7422 | 8776 | =end original |
| 7423 | 8777 | |
| 7424 | スカラコンテキストでは、C<localtime | |
| 8778 | スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値を | |
| 8779 | 返します: | |
| 7425 | 8780 | |
| 7426 | | |
| 8781 | my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" | |
| 7427 | 8782 | |
| 7428 | 8783 | =begin original |
| 7429 | 8784 | |
| 7430 | Th | |
| 8785 | This scalar value is always in English, and is B<not> locale-dependent. | |
| 7431 | ||
| 8786 | To get similar but locale-dependent date strings, try for example: | |
| 7432 | time use the L</gmtime> builtin. See also the | |
| 7433 | C<Time::Local> module (for converting seconds, minutes, hours, and such back to | |
| 7434 | the integer value returned by time()), and the L<POSIX> module's strftime(3) | |
| 7435 | and mktime(3) functions. | |
| 7436 | 8787 | |
| 7437 | 8788 | =end original |
| 7438 | 8789 | |
| 7439 | このスカラ値 | |
| 8790 | このスカラ値は常に英語で、ロケール依存では B<ありません>。 | |
| 7440 | ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を | |
| 7441 | 使ってください。 | |
| 7442 | また、(秒、分、時などの形から、time() が返す値である | |
| 7443 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール | |
| 7444 | 及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も | |
| 7445 | 参照してください。 | |
| 7446 | ||
| 7447 | =begin original | |
| 7448 | ||
| 7449 | To get somewhat similar but locale-dependent date strings, set up your | |
| 7450 | locale environment variables appropriately (please see L<perllocale>) and | |
| 7451 | try for example: | |
| 7452 | ||
| 7453 | =end original | |
| 7454 | ||
| 7455 | 8791 | 似たような、しかしロケール依存の日付文字列がほしい場合は、 |
| 7456 | ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、 | |
| 7457 | 8792 | 以下の例を試してください: |
| 7458 | 8793 | |
| 7459 | | |
| 8794 | use POSIX qw(strftime); | |
| 7460 | | |
| 8795 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; | |
| 7461 | | |
| 8796 | # or for GMT formatted appropriately for your locale: | |
| 7462 | | |
| 8797 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; | |
| 7463 | 8798 | |
| 7464 | 8799 | =begin original |
| 7465 | 8800 | |
| 7466 | ||
| 8801 | C$now_string> will be formatted according to the current LC_TIME locale | |
| 7467 | ||
| 8802 | the program or thread is running in. See L<perllocale> for how to set | |
| 8803 | up and change that locale. Note that C<%a> and C<%b>, the short forms | |
| 8804 | of the day of the week and the month of the year, may not necessarily be | |
| 8805 | three characters wide. | |
| 7468 | 8806 | |
| 7469 | 8807 | =end original |
| 7470 | 8808 | |
| 8809 | C$now_string> はプログラムやスレッドが実行されている現在の LC_TIME ロケールに | |
| 8810 | 従ってフォーマットされます。 | |
| 8811 | このロケールの設定と変更の方法については L<perllocale> を参照してください。 | |
| 7471 | 8812 | 曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに |
| 7472 | 8813 | 注意してください。 |
| 7473 | 8814 | |
| 7474 | 8815 | =begin original |
| 7475 | 8816 | |
| 7476 | 8817 | The L<Time::gmtime> and L<Time::localtime> modules provide a convenient, |
| 7477 | by-name access mechanism to the gmtime | |
| 8818 | by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and | |
| 7478 | respectively. | |
| 8819 | L<C<localtime>|/localtime EXPR> functions, respectively. | |
| 7479 | 8820 | |
| 7480 | 8821 | =end original |
| 7481 | 8822 | |
| 7482 | 8823 | L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ |
| 7483 | gmtime | |
| 8824 | L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、 | |
| 7484 | 便利なモジュールです。 | |
| 8825 | 名前でアクセスする機構を提供する便利なモジュールです。 | |
| 7485 | 8826 | |
| 7486 | 8827 | =begin original |
| 7487 | 8828 | |
| 7488 | 8829 | For a comprehensive date and time representation look at the |
| 7489 | 8830 | L<DateTime> module on CPAN. |
| 7490 | 8831 | |
| 7491 | 8832 | =end original |
| 7492 | 8833 | |
| 7493 | 8834 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
| 7494 | 8835 | 参照してください。 |
| 7495 | 8836 | |
| 7496 | 8837 | =begin original |
| 7497 | 8838 | |
| 8839 | For GMT instead of local time use the L<C<gmtime>|/gmtime EXPR> builtin. | |
| 8840 | ||
| 8841 | =end original | |
| 8842 | ||
| 8843 | ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み | |
| 8844 | 関数を使ってください。 | |
| 8845 | ||
| 8846 | =begin original | |
| 8847 | ||
| 8848 | See also the L<C<Time::Local>|Time::Local> module (for converting | |
| 8849 | seconds, minutes, hours, and such back to the integer value returned by | |
| 8850 | L<C<time>|/time>), and the L<POSIX> module's | |
| 8851 | L<C<mktime>|POSIX/C<mktime>> function. | |
| 8852 | ||
| 8853 | =end original | |
| 8854 | ||
| 8855 | また、(秒、分、時などの形から、L<C<time>|/time> が返す値である | |
| 8856 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) | |
| 8857 | L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される | |
| 8858 | L<C<mktime>|POSIX/C<mktime>> 関数も参照してください。 | |
| 8859 | ||
| 8860 | =begin original | |
| 8861 | ||
| 7498 | 8862 | Portability issues: L<perlport/localtime>. |
| 7499 | 8863 | |
| 7500 | 8864 | =end original |
| 7501 | 8865 | |
| 7502 | 8866 | 移植性の問題: L<perlport/localtime>。 |
| 7503 | 8867 | |
| 7504 | 8868 | =item lock THING |
| 7505 | 8869 | X<lock> |
| 7506 | 8870 | |
| 7507 | 8871 | =for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method |
| 7508 | 8872 | |
| 7509 | 8873 | =begin original |
| 7510 | 8874 | |
| 7511 | 8875 | This function places an advisory lock on a shared variable or referenced |
| 7512 | 8876 | object contained in I<THING> until the lock goes out of scope. |
| 7513 | 8877 | |
| 7514 | 8878 | =end original |
| 7515 | 8879 | |
| 7516 | 8880 | この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、 |
| 7517 | 8881 | スコープから出るまでアドバイサリロックを掛けます. |
| 7518 | 8882 | |
| 7519 | 8883 | =begin original |
| 7520 | 8884 | |
| 7521 | 8885 | The value returned is the scalar itself, if the argument is a scalar, or a |
| 7522 | 8886 | reference, if the argument is a hash, array or subroutine. |
| 7523 | 8887 | |
| 7524 | 8888 | =end original |
| 7525 | 8889 | |
| 7526 | 8890 | 返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、 |
| 7527 | 8891 | サブルーチンならリファレンスです。 |
| 7528 | 8892 | |
| 7529 | 8893 | =begin original |
| 7530 | 8894 | |
| 7531 | lock | |
| 8895 | L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've | |
| 8896 | defined a function | |
| 7532 | 8897 | by this name (before any calls to it), that function will be called |
| 7533 | 8898 | instead. If you are not under C<use threads::shared> this does nothing. |
| 7534 | 8899 | See L<threads::shared>. |
| 7535 | 8900 | |
| 7536 | 8901 | =end original |
| 7537 | 8902 | |
| 7538 | lock | |
| 8903 | L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に) | |
| 7539 | 8904 | この名前で関数を定義すると、定義された関数の方が呼び出されます。 |
| 7540 | 8905 | C<use threads::shared> の影響下でない場合は、これは何もしません。 |
| 7541 | 8906 | L<threads::shared> を参照してください。 |
| 7542 | 8907 | |
| 7543 | 8908 | =item log EXPR |
| 7544 | 8909 | X<log> X<logarithm> X<e> X<ln> X<base> |
| 7545 | 8910 | |
| 7546 | 8911 | =item log |
| 7547 | 8912 | |
| 7548 | 8913 | =for Pod::Functions retrieve the natural logarithm for a number |
| 7549 | 8914 | |
| 7550 | 8915 | =begin original |
| 7551 | 8916 | |
| 7552 | 8917 | Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted, |
| 7553 | returns the log of C<$_>. To get the | |
| 8918 | returns the log of L<C<$_>|perlvar/$_>. To get the | |
| 7554 | 8919 | log of another base, use basic algebra: |
| 7555 | 8920 | The base-N log of a number is equal to the natural log of that number |
| 7556 | 8921 | divided by the natural log of N. For example: |
| 7557 | 8922 | |
| 7558 | 8923 | =end original |
| 7559 | 8924 | |
| 7560 | 8925 | EXPR の (I<e> を底とする) 自然対数を返します。 |
| 7561 | EXPR が省略されると、C<$_> の対数を返します。 | |
| 8926 | EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。 | |
| 7562 | 8927 | 底の異なる対数を求めるためには、基礎代数を利用してください: |
| 7563 | 8928 | ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。 |
| 7564 | 8929 | 例えば: |
| 7565 | 8930 | |
| 7566 | 8931 | sub log10 { |
| 7567 | 8932 | my $n = shift; |
| 7568 | 8933 | return log($n)/log(10); |
| 7569 | 8934 | } |
| 7570 | 8935 | |
| 7571 | 8936 | =begin original |
| 7572 | 8937 | |
| 7573 | See also L</exp> for the inverse operation. | |
| 8938 | See also L<C<exp>|/exp EXPR> for the inverse operation. | |
| 7574 | 8939 | |
| 7575 | 8940 | =end original |
| 7576 | 8941 | |
| 7577 | 逆操作については L</exp> を参照してください。 | |
| 8942 | 逆操作については L<C<exp>|/exp EXPR> を参照してください。 | |
| 7578 | 8943 | |
| 7579 | 8944 | =item lstat FILEHANDLE |
| 7580 | 8945 | X<lstat> |
| 7581 | 8946 | |
| 7582 | 8947 | =item lstat EXPR |
| 7583 | 8948 | |
| 7584 | 8949 | =item lstat DIRHANDLE |
| 7585 | 8950 | |
| 7586 | 8951 | =item lstat |
| 7587 | 8952 | |
| 7588 | 8953 | =for Pod::Functions stat a symbolic link |
| 7589 | 8954 | |
| 7590 | 8955 | =begin original |
| 7591 | 8956 | |
| 7592 | Does the same thing as the C<stat> function | |
| 8957 | Does the same thing as the L<C<stat>|/stat FILEHANDLE> function | |
| 7593 | special C<_> filehandle) but stats a symbolic | |
| 8958 | (including setting the special C<_> filehandle) but stats a symbolic | |
| 7594 | the symbolic link points to. If symbolic links | |
| 8959 | link instead of the file the symbolic link points to. If symbolic links | |
| 7595 | your system, a normal C<stat> | |
| 8960 | are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE> | |
| 7596 | information, please see the | |
| 8961 | is done. For much more detailed information, please see the | |
| 8962 | documentation for L<C<stat>|/stat FILEHANDLE>. | |
| 7597 | 8963 | |
| 7598 | 8964 | =end original |
| 7599 | 8965 | |
| 7600 | 8966 | (特別なファイルハンドルである C<_> の設定を含めて) |
| 7601 | C<stat> 関数と同じことをしますが、シンボリックリンクが | |
| 8967 | L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが | |
| 7602 | 8968 | 指しているファイルではなく、シンボリックリンク自体の stat をとります。 |
| 7603 | シンボリックリンクがシステムに実装されていないと、通常の | |
| 8969 | シンボリックリンクがシステムに実装されていないと、通常の | |
| 7604 | ||
| 8970 | L<C<stat>|/stat FILEHANDLE> が行なわれます。 | |
| 8971 | さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を | |
| 8972 | 参照してください。 | |
| 7605 | 8973 | |
| 7606 | 8974 | =begin original |
| 7607 | 8975 | |
| 7608 | If EXPR is omitted, stats C<$_>. | |
| 8976 | If EXPR is omitted, stats L<C<$_>|perlvar/$_>. | |
| 7609 | 8977 | |
| 7610 | 8978 | =end original |
| 7611 | 8979 | |
| 7612 | EXPR が省略されると、C<$_> の stat をとります。 | |
| 8980 | EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。 | |
| 7613 | 8981 | |
| 7614 | 8982 | =begin original |
| 7615 | 8983 | |
| 7616 | 8984 | Portability issues: L<perlport/lstat>. |
| 7617 | 8985 | |
| 7618 | 8986 | =end original |
| 7619 | 8987 | |
| 7620 | 8988 | 移植性の問題: L<perlport/lstat>。 |
| 7621 | 8989 | |
| 7622 | 8990 | =item m// |
| 7623 | 8991 | |
| 7624 | 8992 | =for Pod::Functions match a string with a regular expression pattern |
| 7625 | 8993 | |
| 7626 | 8994 | =begin original |
| 7627 | 8995 | |
| 7628 | 8996 | The match operator. See L<perlop/"Regexp Quote-Like Operators">. |
| 7629 | 8997 | |
| 7630 | 8998 | =end original |
| 7631 | 8999 | |
| 7632 | 9000 | マッチ演算子です。 |
| 7633 | 9001 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
| 7634 | 9002 | |
| 7635 | 9003 | =item map BLOCK LIST |
| 7636 | 9004 | X<map> |
| 7637 | 9005 | |
| 7638 | 9006 | =item map EXPR,LIST |
| 7639 | 9007 | |
| 7640 | 9008 | =for Pod::Functions apply a change to a list to get back a new list with the changes |
| 7641 | 9009 | |
| 7642 | 9010 | =begin original |
| 7643 | 9011 | |
| 7644 | 9012 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
| 7645 | C<$_> to each element) and | |
| 9013 | L<C<$_>|perlvar/$_> to each element) and composes a list of the results of | |
| 7646 | ||
| 9014 | each such evaluation. Each element of LIST may produce zero, one, or more | |
| 7647 | t | |
| 9015 | elements in the generated list, so the number of elements in the generated | |
| 7648 | list | |
| 9016 | list may differ from that in LIST. In scalar context, returns the total | |
| 7649 | m | |
| 9017 | number of elements so generated. In list context, returns the generated list. | |
| 7650 | 9018 | |
| 7651 | 9019 | =end original |
| 7652 | 9020 | |
| 7653 | 9021 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
| 7654 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
| 9022 | (L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、 | |
| 7655 | それぞれの評価結果からなるリスト | |
| 9023 | それぞれの評価結果からなるリストを作ります。 | |
| 9024 | LIST の個々の要素によって作られる、生成されたリストの要素数は、 | |
| 9025 | 0 個の場合もあれば、複数の場合もあるので、 | |
| 9026 | 生成されたリストの要素数は LIST の要素数と異なるかも知れません。 | |
| 7656 | 9027 | スカラコンテキストでは、生成された要素の数を返します。 |
| 7657 | ||
| 9028 | リストコンテキストでは、生成されたリストを返します。 | |
| 7658 | 個々の要素によって作られる、返り値であるリストの要素数は、 | |
| 7659 | 0 個の場合もあれば、複数の場合もあります。 | |
| 7660 | 9029 | |
| 7661 | @chars = map(chr, @numbers); | |
| 9030 | my @chars = map(chr, @numbers); | |
| 7662 | 9031 | |
| 7663 | 9032 | =begin original |
| 7664 | 9033 | |
| 7665 | 9034 | translates a list of numbers to the corresponding characters. |
| 7666 | 9035 | |
| 7667 | 9036 | =end original |
| 7668 | 9037 | |
| 7669 | 9038 | は、数のリストを対応する文字に変換します。 |
| 7670 | 9039 | |
| 7671 | 9040 | my @squares = map { $_ * $_ } @numbers; |
| 7672 | 9041 | |
| 7673 | 9042 | =begin original |
| 7674 | 9043 | |
| 7675 | 9044 | translates a list of numbers to their squared values. |
| 7676 | 9045 | |
| 7677 | 9046 | =end original |
| 7678 | 9047 | |
| 7679 | 9048 | これは数値のリストを、その 2 乗に変換します。 |
| 7680 | 9049 | |
| 7681 | 9050 | my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; |
| 7682 | 9051 | |
| 7683 | 9052 | =begin original |
| 7684 | 9053 | |
| 7685 | 9054 | shows that number of returned elements can differ from the number of |
| 7686 | 9055 | input elements. To omit an element, return an empty list (). |
| 7687 | 9056 | This could also be achieved by writing |
| 7688 | 9057 | |
| 7689 | 9058 | =end original |
| 7690 | 9059 | |
| 7691 | 9060 | のように、返された要素の数が入力要素の数と異なる場合もあります。 |
| 7692 | 9061 | 要素を省略するには、空リスト () を返します。 |
| 7693 | 9062 | これは以下のように書くことでも達成できて |
| 7694 | 9063 | |
| 7695 | 9064 | my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; |
| 7696 | 9065 | |
| 7697 | 9066 | =begin original |
| 7698 | 9067 | |
| 7699 | 9068 | which makes the intention more clear. |
| 7700 | 9069 | |
| 7701 | 9070 | =end original |
| 7702 | 9071 | |
| 7703 | 9072 | この方が目的がよりはっきりします。 |
| 7704 | 9073 | |
| 7705 | 9074 | =begin original |
| 7706 | 9075 | |
| 7707 | 9076 | Map always returns a list, which can be |
| 7708 | 9077 | assigned to a hash such that the elements |
| 7709 | 9078 | become key/value pairs. See L<perldata> for more details. |
| 7710 | 9079 | |
| 7711 | 9080 | =end original |
| 7712 | 9081 | |
| 7713 | 9082 | map は常にリストを返し、要素がキー/値の組になるようなハッシュに |
| 7714 | 9083 | 代入できます。 |
| 7715 | 9084 | さらなる詳細については L<perldata> を参照してください。 |
| 7716 | 9085 | |
| 7717 | %hash = map { get_a_key_for($_) => $_ } @array; | |
| 9086 | my %hash = map { get_a_key_for($_) => $_ } @array; | |
| 7718 | 9087 | |
| 7719 | 9088 | =begin original |
| 7720 | 9089 | |
| 7721 | 9090 | is just a funny way to write |
| 7722 | 9091 | |
| 7723 | 9092 | =end original |
| 7724 | 9093 | |
| 7725 | 9094 | は以下のものをちょっと変わった書き方で書いたものです。 |
| 7726 | 9095 | |
| 7727 | %hash | |
| 9096 | my %hash; | |
| 7728 | 9097 | foreach (@array) { |
| 7729 | 9098 | $hash{get_a_key_for($_)} = $_; |
| 7730 | 9099 | } |
| 7731 | 9100 | |
| 7732 | 9101 | =begin original |
| 7733 | 9102 | |
| 7734 | Note that C<$_> is an alias to the list value, so it can | |
| 9103 | Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can | |
| 7735 | modify the elements of the LIST. While this is useful and | |
| 9104 | be used to modify the elements of the LIST. While this is useful and | |
| 7736 | it can cause bizarre results if the elements of LIST are not | |
| 9105 | supported, it can cause bizarre results if the elements of LIST are not | |
| 7737 | Using a regular C<foreach> loop for this purpose would be | |
| 9106 | variables. Using a regular C<foreach> loop for this purpose would be | |
| 7738 | most cases. See also L< | |
| 9107 | clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a | |
| 7739 | the original list for which the BLOCK | |
| 9108 | list composed of those items of the original list for which the BLOCK | |
| 9109 | or EXPR evaluates to true. | |
| 7740 | 9110 | |
| 7741 | 9111 | =end original |
| 7742 | 9112 | |
| 7743 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 9113 | L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 7744 | 9114 | 変更するために使うことができます。 |
| 7745 | 9115 | これは、便利でサポートされていますが、 |
| 7746 | 9116 | LIST の要素が変数でないと、おかしな結果になります。 |
| 7747 | 9117 | この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は |
| 7748 | 9118 | より明確になります。 |
| 7749 | BLOCK や EXPR が真になる元のリストの要素からなる | |
| 9119 | BLOCK や EXPR が真になる元のリストの要素からなるリストについては、 | |
| 7750 | L</grep> も参照してください。 | |
| 9120 | L<C<grep>|/grep BLOCK LIST> も参照してください。 | |
| 7751 | 9121 | |
| 7752 | 9122 | =begin original |
| 7753 | 9123 | |
| 7754 | If C<$_> is lexical in the scope where the C<map> appears (because it has | |
| 7755 | been declared with the deprecated C<my $_> construct), | |
| 7756 | then, in addition to being locally aliased to | |
| 7757 | the list elements, C<$_> keeps being lexical inside the block; that is, it | |
| 7758 | can't be seen from the outside, avoiding any potential side-effects. | |
| 7759 | ||
| 7760 | =end original | |
| 7761 | ||
| 7762 | (廃止予定の C<my $_> 構文で宣言されることによって) C<$_> が C<map> が現れる | |
| 7763 | スコープ内でレキシカルな場合は、ローカルではリスト要素への | |
| 7764 | エイリアスであることに加えて、C<$_> はブロック内でレキシカルでありつづけます; | |
| 7765 | つまり、外側からは見えず、起こりうる副作用を回避します。 | |
| 7766 | ||
| 7767 | =begin original | |
| 7768 | ||
| 7769 | 9124 | C<{> starts both hash references and blocks, so C<map { ...> could be either |
| 7770 | 9125 | the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look |
| 7771 | 9126 | ahead for the closing C<}> it has to take a guess at which it's dealing with |
| 7772 | 9127 | based on what it finds just after the |
| 7773 | 9128 | C<{>. Usually it gets it right, but if it |
| 7774 | 9129 | doesn't it won't realize something is wrong until it gets to the C<}> and |
| 7775 | 9130 | encounters the missing (or unexpected) comma. The syntax error will be |
| 7776 | 9131 | reported close to the C<}>, but you'll need to change something near the C<{> |
| 7777 | such as using a unary C<+> to give Perl some help: | |
| 9132 | such as using a unary C<+> or semicolon to give Perl some help: | |
| 7778 | 9133 | |
| 7779 | 9134 | =end original |
| 7780 | 9135 | |
| 7781 | 9136 | C<{> はハッシュリファレンスとブロックの両方の開始文字なので、 |
| 7782 | 9137 | C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。 |
| 7783 | 9138 | Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て |
| 7784 | 9139 | どちらとして扱うかを推測します。 |
| 7785 | 9140 | 通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで |
| 7786 | 9141 | カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに |
| 7787 | 9142 | 気付きません。 |
| 7788 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> | |
| 9143 | C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> や | |
| 7789 | 使うというように、C<{> の近くの何かを変更する必要があります。 | |
| 9144 | セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。 | |
| 7790 | 9145 | |
| 7791 | | |
| 9146 | my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong | |
| 7792 | | |
| 9147 | my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right | |
| 7793 | | |
| 9148 | my %hash = map {; "\L$_" => 1 } @array # this also works | |
| 7794 | | |
| 9149 | my %hash = map { ("\L$_" => 1) } @array # as does this | |
| 7795 | | |
| 9150 | my %hash = map { lc($_) => 1 } @array # and this. | |
| 9151 | my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! | |
| 7796 | 9152 | |
| 7797 | | |
| 9153 | my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) | |
| 7798 | 9154 | |
| 7799 | 9155 | =begin original |
| 7800 | 9156 | |
| 7801 | 9157 | or to force an anon hash constructor use C<+{>: |
| 7802 | 9158 | |
| 7803 | 9159 | =end original |
| 7804 | 9160 | |
| 7805 | 9161 | または C<+{> を使って無名ハッシュコンストラクタを強制します: |
| 7806 | 9162 | |
| 7807 | @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs | |
| 9163 | my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs | |
| 7808 | # comma at end | |
| 9164 | # comma at end | |
| 7809 | 9165 | |
| 7810 | 9166 | =begin original |
| 7811 | 9167 | |
| 7812 | 9168 | to get a list of anonymous hashes each with only one entry apiece. |
| 7813 | 9169 | |
| 7814 | 9170 | =end original |
| 7815 | 9171 | |
| 7816 | 9172 | こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。 |
| 7817 | 9173 | |
| 7818 | =item m | |
| 9174 | =item method NAME BLOCK | |
| 9175 | X<method> | |
| 9176 | ||
| 9177 | =item method NAME : ATTRS BLOCK | |
| 9178 | ||
| 9179 | =for Pod::Functions declare a method of a class | |
| 9180 | ||
| 9181 | =begin original | |
| 9182 | ||
| 9183 | Creates a new named method in the scope of the class that it appears within. | |
| 9184 | This is only valid inside a L<C<class>|/class NAMESPACE> declaration. | |
| 9185 | ||
| 9186 | =end original | |
| 9187 | ||
| 9188 | Creates a new named method in the scope of the class that it appears within. | |
| 9189 | This is only valid inside a L<C<class>|/class NAMESPACE> declaration. | |
| 9190 | (TBT) | |
| 9191 | ||
| 9192 | =item mkdir FILENAME,MODE | |
| 7819 | 9193 | X<mkdir> X<md> X<directory, create> |
| 7820 | 9194 | |
| 7821 | 9195 | =item mkdir FILENAME |
| 7822 | 9196 | |
| 7823 | 9197 | =item mkdir |
| 7824 | 9198 | |
| 7825 | 9199 | =for Pod::Functions create a directory |
| 7826 | 9200 | |
| 7827 | 9201 | =begin original |
| 7828 | 9202 | |
| 7829 | 9203 | Creates the directory specified by FILENAME, with permissions |
| 7830 | specified by M | |
| 9204 | specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it | |
| 7831 | returns true; otherwise it returns false and sets | |
| 9205 | succeeds it returns true; otherwise it returns false and sets | |
| 7832 | ||
| 9206 | L<C<$!>|perlvar/$!> (errno). | |
| 7833 | to | |
| 9207 | MODE defaults to 0777 if omitted, and FILENAME defaults | |
| 9208 | to L<C<$_>|perlvar/$_> if omitted. | |
| 7834 | 9209 | |
| 7835 | 9210 | =end original |
| 7836 | 9211 | |
| 7837 | FILENAME で指定したディレクトリを、M | |
| 9212 | FILENAME で指定したディレクトリを、MODE で指定した許可モード(を | |
| 7838 | C<umask> で修正したもの) で作成します。 | |
| 9213 | L<C<umask>|/umask EXPR> で修正したもの) で作成します。 | |
| 7839 | 成功時には真を返します; さもなければ偽を返して | |
| 9214 | 成功時には真を返します; さもなければ偽を返して | |
| 7840 | ||
| 9215 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 7841 | ||
| 9216 | MODE を省略すると、0777 とみなし、 | |
| 9217 | FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。 | |
| 7842 | 9218 | |
| 7843 | 9219 | =begin original |
| 7844 | 9220 | |
| 7845 | In general, it is better to create directories with a permissive M | |
| 9221 | In general, it is better to create directories with a permissive MODE | |
| 7846 | and let the user modify that with their C<umask> than it | |
| 9222 | and let the user modify that with their L<C<umask>|/umask EXPR> than it | |
| 7847 | ||
| 9223 | is to supply | |
| 9224 | a restrictive MODE and give the user no way to be more permissive. | |
| 7848 | 9225 | The exceptions to this rule are when the file or directory should be |
| 7849 | kept private (mail files, for instance). The | |
| 9226 | kept private (mail files, for instance). The documentation for | |
| 7850 | C<umask> discusses the choice of M | |
| 9227 | L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail. | |
| 9228 | If bits in MODE other than the permission bits are set, the result may | |
| 9229 | be implementation defined, per POSIX 1003.1-2008. | |
| 7851 | 9230 | |
| 7852 | 9231 | =end original |
| 7853 | 9232 | |
| 7854 | 一般的に、制限された M | |
| 9233 | 一般的に、制限された MODE を使ってユーザーがより寛容にする方法を | |
| 7855 | 与えないより、寛容な M | |
| 9234 | 与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の | |
| 7856 | 修正するようにした方がよいです。 | |
| 9235 | L<C<umask>|/umask EXPR> で修正するようにした方がよいです。 | |
| 7857 | 9236 | 例外は、(例えばメールファイルのような)プライベートに保つべきファイルや |
| 7858 | 9237 | ディレクトリを書く場合です。 |
| 7859 | ||
| 9238 | L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。 | |
| 9239 | If bits in MODE other than the permission bits are set, the result may | |
| 9240 | be implementation defined, per POSIX 1003.1-2008. | |
| 9241 | (TBT) | |
| 7860 | 9242 | |
| 7861 | 9243 | =begin original |
| 7862 | 9244 | |
| 7863 | 9245 | Note that according to the POSIX 1003.1-1996 the FILENAME may have any |
| 7864 | 9246 | number of trailing slashes. Some operating and filesystems do not get |
| 7865 | 9247 | this right, so Perl automatically removes all trailing slashes to keep |
| 7866 | 9248 | everyone happy. |
| 7867 | 9249 | |
| 7868 | 9250 | =end original |
| 7869 | 9251 | |
| 7870 | 9252 | POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを |
| 7871 | 9253 | つけることができます。 |
| 7872 | 9254 | このようには動かない OS やファイルシステムもあるので、Perl はみんなが |
| 7873 | 9255 | 幸せになれるように、自動的に末尾のスラッシュを削除します。 |
| 7874 | 9256 | |
| 7875 | 9257 | =begin original |
| 7876 | 9258 | |
| 7877 | 9259 | To recursively create a directory structure, look at |
| 7878 | the C<mkpath> | |
| 9260 | the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function | |
| 9261 | of the L<File::Path> module. | |
| 7879 | 9262 | |
| 7880 | 9263 | =end original |
| 7881 | 9264 | |
| 7882 | 9265 | ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの |
| 7883 | C<makepath> 関数を | |
| 9266 | L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を | |
| 9267 | 参照してください。 | |
| 7884 | 9268 | |
| 7885 | 9269 | =item msgctl ID,CMD,ARG |
| 7886 | 9270 | X<msgctl> |
| 7887 | 9271 | |
| 7888 | 9272 | =for Pod::Functions SysV IPC message control operations |
| 7889 | 9273 | |
| 7890 | 9274 | =begin original |
| 7891 | 9275 | |
| 7892 | Calls the System V IPC function msgctl(2). You'll probably have to say | |
| 9276 | Calls the System V IPC function L<msgctl(2)>. You'll probably have to say | |
| 7893 | 9277 | |
| 7894 | 9278 | =end original |
| 7895 | 9279 | |
| 7896 | System V IPC 関数 msgctl を呼び出します。 | |
| 9280 | System V IPC 関数 L<msgctl(2)> を呼び出します。 | |
| 7897 | 9281 | 正しい定数定義を得るために、まず |
| 7898 | 9282 | |
| 7899 | 9283 | use IPC::SysV; |
| 7900 | 9284 | |
| 7901 | 9285 | =begin original |
| 7902 | 9286 | |
| 7903 | 9287 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
| 7904 | 9288 | then ARG must be a variable that will hold the returned C<msqid_ds> |
| 7905 | structure. Returns like C<ioctl> | |
| 9289 | structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: | |
| 7906 | C<"0 but true"> for zero, or the actual | |
| 9290 | the undefined value for error, C<"0 but true"> for zero, or the actual | |
| 7907 | L<perlipc/"SysV IPC"> and the | |
| 9291 | return value otherwise. See also L<perlipc/"SysV IPC"> and the | |
| 7908 | C<IPC::S | |
| 9292 | documentation for L<C<IPC::SysV>|IPC::SysV> and | |
| 9293 | L<C<IPC::Semaphore>|IPC::Semaphore>. | |
| 7909 | 9294 | |
| 7910 | 9295 | =end original |
| 7911 | 9296 | |
| 7912 | 9297 | と書くことが必要でしょう。 |
| 7913 | 9298 | CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を |
| 7914 | 9299 | 納める変数でなければなりません。 |
| 7915 | C<ioctl> と同じように、エラー時には | |
| 9300 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には | |
| 7916 | ゼロのときは C<"0 but true">、それ以外なら、その値そのものを | |
| 9301 | 未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを | |
| 7917 | ||
| 9302 | 返します。 | |
| 7918 | ||
| 9303 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 9304 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
| 7919 | 9305 | |
| 7920 | 9306 | =begin original |
| 7921 | 9307 | |
| 7922 | 9308 | Portability issues: L<perlport/msgctl>. |
| 7923 | 9309 | |
| 7924 | 9310 | =end original |
| 7925 | 9311 | |
| 7926 | 9312 | 移植性の問題: L<perlport/msgctl>。 |
| 7927 | 9313 | |
| 7928 | 9314 | =item msgget KEY,FLAGS |
| 7929 | 9315 | X<msgget> |
| 7930 | 9316 | |
| 7931 | 9317 | =for Pod::Functions get SysV IPC message queue |
| 7932 | 9318 | |
| 7933 | 9319 | =begin original |
| 7934 | 9320 | |
| 7935 | Calls the System V IPC function msgget(2). Returns the message queue | |
| 9321 | Calls the System V IPC function L<msgget(2)>. Returns the message queue | |
| 7936 | id, or C<undef> on error. See also | |
| 9322 | id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC"> | |
| 7937 | ||
| 9323 | and the documentation for L<C<IPC::SysV>|IPC::SysV> and | |
| 7938 | C<IPC::Msg>. | |
| 9324 | L<C<IPC::Msg>|IPC::Msg>. | |
| 7939 | 9325 | |
| 7940 | 9326 | =end original |
| 7941 | 9327 | |
| 7942 | System V IPC 関数 msgget を呼び出します。 | |
| 9328 | System V IPC 関数 L<msgget(2)> を呼び出します。 | |
| 7943 | メッセージキューの ID か、エラー時には C<undef> を返します。 | |
| 9329 | メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
| 7944 | L<perlipc/"SysV IPC"> よ | |
| 9330 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 7945 | 参照してください。 | |
| 9331 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 7946 | 9332 | |
| 7947 | 9333 | =begin original |
| 7948 | 9334 | |
| 7949 | 9335 | Portability issues: L<perlport/msgget>. |
| 7950 | 9336 | |
| 7951 | 9337 | =end original |
| 7952 | 9338 | |
| 7953 | 9339 | 移植性の問題: L<perlport/msgget>。 |
| 7954 | 9340 | |
| 7955 | 9341 | =item msgrcv ID,VAR,SIZE,TYPE,FLAGS |
| 7956 | 9342 | X<msgrcv> |
| 7957 | 9343 | |
| 7958 | 9344 | =for Pod::Functions receive a SysV IPC message from a message queue |
| 7959 | 9345 | |
| 7960 | 9346 | =begin original |
| 7961 | 9347 | |
| 7962 | 9348 | Calls the System V IPC function msgrcv to receive a message from |
| 7963 | 9349 | message queue ID into variable VAR with a maximum message size of |
| 7964 | 9350 | SIZE. Note that when a message is received, the message type as a |
| 7965 | 9351 | native long integer will be the first thing in VAR, followed by the |
| 7966 | 9352 | actual message. This packing may be opened with C<unpack("l! a*")>. |
| 7967 | Taints the variable. Returns true if successful, false | |
| 9353 | Taints the variable. Returns true if successful, false | |
| 7968 | 9354 | on error. See also L<perlipc/"SysV IPC"> and the documentation for |
| 7969 | C<IPC::SysV> and C<IPC:: | |
| 9355 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. | |
| 7970 | 9356 | |
| 7971 | 9357 | =end original |
| 7972 | 9358 | |
| 7973 | 9359 | System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、 |
| 7974 | 9360 | 変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。 |
| 7975 | 9361 | メッセージが受信された時、ネイティブな long 整数のメッセージタイプが |
| 7976 | 9362 | VAR の先頭となり、実際のメッセージが続きます。 |
| 7977 | 9363 | このパッキングは C<unpack("l! a*")> で展開できます。 |
| 7978 | 9364 | 変数は汚染されます。 |
| 7979 | 9365 | 成功時には真を、エラー時には偽を返します。 |
| 7980 | L<perlipc/"SysV IPC"> および、C<IPC::SysV> | |
| 9366 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 7981 | 参照してください。 | |
| 9367 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 7982 | 9368 | |
| 7983 | 9369 | =begin original |
| 7984 | 9370 | |
| 7985 | 9371 | Portability issues: L<perlport/msgrcv>. |
| 7986 | 9372 | |
| 7987 | 9373 | =end original |
| 7988 | 9374 | |
| 7989 | 9375 | 移植性の問題: L<perlport/msgrcv>。 |
| 7990 | 9376 | |
| 7991 | 9377 | =item msgsnd ID,MSG,FLAGS |
| 7992 | 9378 | X<msgsnd> |
| 7993 | 9379 | |
| 7994 | 9380 | =for Pod::Functions send a SysV IPC message to a message queue |
| 7995 | 9381 | |
| 7996 | 9382 | =begin original |
| 7997 | 9383 | |
| 7998 | 9384 | Calls the System V IPC function msgsnd to send the message MSG to the |
| 7999 | 9385 | message queue ID. MSG must begin with the native long integer message |
| 8000 | type, | |
| 9386 | type, followed by the message itself. This kind of packing can be achieved | |
| 8001 | the message | |
| 9387 | with C<pack("l! a*", $type, $message)>. Returns true if successful, | |
| 8002 | ||
| 9388 | false on error. See also L<perlipc/"SysV IPC"> and the documentation | |
| 8003 | f | |
| 9389 | for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>. | |
| 8004 | and C<IPC::SysV::Msg> documentation. | |
| 8005 | 9390 | |
| 8006 | 9391 | =end original |
| 8007 | 9392 | |
| 8008 | 9393 | System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に |
| 8009 | 9394 | メッセージ MSG を送信します。 |
| 8010 | MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、 | |
| 9395 | MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、 | |
| 8011 | メッセージ | |
| 9396 | メッセージ本体が続きます。 | |
| 8012 | 9397 | これは、C<pack("l! a*", $type, $message)> として生成できます。 |
| 8013 | 9398 | 成功時には真を、エラー時には偽を返します。 |
| 8014 | ||
| 9399 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 9400 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 8015 | 9401 | |
| 8016 | 9402 | =begin original |
| 8017 | 9403 | |
| 8018 | 9404 | Portability issues: L<perlport/msgsnd>. |
| 8019 | 9405 | |
| 8020 | 9406 | =end original |
| 8021 | 9407 | |
| 8022 | 9408 | 移植性の問題: L<perlport/msgsnd>。 |
| 8023 | 9409 | |
| 8024 | =item my | |
| 9410 | =item my VARLIST | |
| 8025 | 9411 | X<my> |
| 8026 | 9412 | |
| 8027 | =item my TYPE | |
| 9413 | =item my TYPE VARLIST | |
| 8028 | 9414 | |
| 8029 | =item my | |
| 9415 | =item my VARLIST : ATTRS | |
| 8030 | 9416 | |
| 8031 | =item my TYPE | |
| 9417 | =item my TYPE VARLIST : ATTRS | |
| 8032 | 9418 | |
| 8033 | 9419 | =for Pod::Functions declare and assign a local variable (lexical scoping) |
| 8034 | 9420 | |
| 8035 | 9421 | =begin original |
| 8036 | 9422 | |
| 8037 | A C<my> declares the listed variables to be local | |
| 9423 | A L<C<my>|/my VARLIST> declares the listed variables to be local | |
| 8038 | enclosing block, file, or C<eval> | |
| 9424 | (lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If | |
| 8039 | the list must be placed in | |
| 9425 | more than one variable is listed, the list must be placed in | |
| 9426 | parentheses. | |
| 8040 | 9427 | |
| 8041 | 9428 | =end original |
| 8042 | 9429 | |
| 8043 | C<my> はリストアップされた変数を、囲っているブロック、ファイル、 | |
| 9430 | L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、 | |
| 8044 | C<eval> の中でローカルな (レキシカルな) ものにします。 | |
| 9431 | L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。 | |
| 8045 | 複数の | |
| 9432 | 複数の変数を指定する場合は、リストはかっこで囲まなければなりません。 | |
| 8046 | 9433 | |
| 8047 | 9434 | =begin original |
| 8048 | 9435 | |
| 9436 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
| 9437 | as a dummy placeholder, for example to skip assignment of initial | |
| 9438 | values: | |
| 9439 | ||
| 9440 | =end original | |
| 9441 | ||
| 9442 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
| 9443 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
| 9444 | ||
| 9445 | my ( undef, $min, $hour ) = localtime; | |
| 9446 | ||
| 9447 | =begin original | |
| 9448 | ||
| 9449 | Redeclaring a variable in the same scope or statement will "shadow" the | |
| 9450 | previous declaration, creating a new instance and preventing access to | |
| 9451 | the previous one. This is usually undesired and, if warnings are enabled, | |
| 9452 | will result in a warning in the C<shadow> category. | |
| 9453 | ||
| 9454 | =end original | |
| 9455 | ||
| 9456 | 同じスコープや文で変数を再宣言すると、以前の宣言を「隠し」、 | |
| 9457 | 新しい実体を作って、以前の実体にアクセスできなくなります。 | |
| 9458 | これは普通は望まれているものではなく、警告が有効なら、 | |
| 9459 | C<shadow> カテゴリの警告が出ます。 | |
| 9460 | ||
| 9461 | =begin original | |
| 9462 | ||
| 8049 | 9463 | The exact semantics and interface of TYPE and ATTRS are still |
| 8050 | evolving. TYPE | |
| 9464 | evolving. TYPE may be a bareword, a constant declared | |
| 8051 | ||
| 9465 | with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It | |
| 8052 | ||
| 9466 | is | |
| 8053 | ||
| 9467 | currently bound to the use of the L<fields> pragma, | |
| 8054 | ||
| 9468 | and attributes are handled using the L<attributes> pragma, or starting | |
| 9469 | from Perl 5.8.0 also via the L<Attribute::Handlers> module. See | |
| 9470 | L<perlsub/"Private Variables via my()"> for details. | |
| 8055 | 9471 | |
| 8056 | 9472 | =end original |
| 8057 | 9473 | |
| 8058 | 9474 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
| 8059 | ||
| 9475 | TYPE は、裸の単語、L<C<use constant>|constant> で宣言された定数、 | |
| 8060 | ||
| 9476 | L<C<__PACKAGE__>|/__PACKAGE__> のいずれかです。 | |
| 8061 | ||
| 9477 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 | |
| 8062 | ||
| 9478 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
| 8063 | L< | |
| 9479 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
| 9480 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
| 8064 | 9481 | |
| 8065 | 9482 | =item next LABEL |
| 8066 | 9483 | X<next> X<continue> |
| 8067 | 9484 | |
| 8068 | 9485 | =item next EXPR |
| 8069 | 9486 | |
| 8070 | 9487 | =item next |
| 8071 | 9488 | |
| 8072 | 9489 | =for Pod::Functions iterate a block prematurely |
| 8073 | 9490 | |
| 8074 | 9491 | =begin original |
| 8075 | 9492 | |
| 8076 | The C<next> command is like the C<continue> statement in | |
| 9493 | The L<C<next>|/next LABEL> command is like the C<continue> statement in | |
| 8077 | the next iteration of the loop: | |
| 9494 | C; it starts the next iteration of the loop: | |
| 8078 | 9495 | |
| 8079 | 9496 | =end original |
| 8080 | 9497 | |
| 8081 | C<next> コマンドは、C での C<continue> 文のようなもので、 | |
| 9498 | L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、 | |
| 8082 | 9499 | ループの次の繰り返しを開始します: |
| 8083 | 9500 | |
| 8084 | 9501 | LINE: while (<STDIN>) { |
| 8085 | 9502 | next LINE if /^#/; # discard comments |
| 8086 | 9503 | #... |
| 8087 | 9504 | } |
| 8088 | 9505 | |
| 8089 | 9506 | =begin original |
| 8090 | 9507 | |
| 8091 | Note that if there were a C<continue> block on the | |
| 9508 | Note that if there were a L<C<continue>|/continue BLOCK> block on the | |
| 9509 | above, it would get | |
| 8092 | 9510 | executed even on discarded lines. If LABEL is omitted, the command |
| 8093 | 9511 | refers to the innermost enclosing loop. The C<next EXPR> form, available |
| 8094 | 9512 | as of Perl 5.18.0, allows a label name to be computed at run time, being |
| 8095 | 9513 | otherwise identical to C<next LABEL>. |
| 8096 | 9514 | |
| 8097 | 9515 | =end original |
| 8098 | 9516 | |
| 8099 | C<continue> ブロックが存在すれば、たとえ捨てられる行に | |
| 9517 | L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に | |
| 8100 | 9518 | あっても、それが実行されます。 |
| 8101 | 9519 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
| 8102 | 9520 | Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される |
| 8103 | 9521 | ラベル名が使えます; それ以外は C<next LABEL> と同一です。 |
| 8104 | 9522 | |
| 8105 | 9523 | =begin original |
| 8106 | 9524 | |
| 8107 | C<next> cannot | |
| 9525 | L<C<next>|/next LABEL> cannot return a value from a block that typically | |
| 8108 | C<eval {}>, C<sub {}>, or C<do {}> | |
| 9526 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
| 8109 | ||
| 9527 | its flow control behavior, which precludes any return value. It should not be | |
| 9528 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 9529 | operation. | |
| 8110 | 9530 | |
| 8111 | 9531 | =end original |
| 8112 | 9532 | |
| 8113 | C<next> は C<eval {}>, C<sub {}>, C<do {}> | |
| 9533 | L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
| 8114 | ||
| 9534 | 典型的には値を返すブロックから値を返せません。 | |
| 9535 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
| 9536 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 8115 | 9537 | 使うべきではありません。 |
| 8116 | 9538 | |
| 8117 | 9539 | =begin original |
| 8118 | 9540 | |
| 8119 | 9541 | Note that a block by itself is semantically identical to a loop |
| 8120 | that executes once. Thus C<next> will exit such a block | |
| 9542 | that executes once. Thus L<C<next>|/next LABEL> will exit such a block | |
| 9543 | early. | |
| 8121 | 9544 | |
| 8122 | 9545 | =end original |
| 8123 | 9546 | |
| 8124 | 9547 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
| 8125 | 9548 | 注意してください。 |
| 8126 | 従って、C<next> はそのようなブロックから早く抜けるのに使えます。 | |
| 9549 | 従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。 | |
| 8127 | 9550 | |
| 8128 | 9551 | =begin original |
| 8129 | 9552 | |
| 8130 | See also L</continue> for an illustration of how | |
| 9553 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
| 8131 | C< | |
| 9554 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
| 9555 | L<C<redo>|/redo LABEL> work. | |
| 8132 | 9556 | |
| 8133 | 9557 | =end original |
| 8134 | 9558 | |
| 8135 | C<last>, C<next>, C<redo> が | |
| 9559 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
| 8136 | L</continue> も参照してください。 | |
| 9560 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
| 8137 | 9561 | |
| 8138 | 9562 | =begin original |
| 8139 | 9563 | |
| 8140 | 9564 | Unlike most named operators, this has the same precedence as assignment. |
| 8141 | 9565 | It is also exempt from the looks-like-a-function rule, so |
| 8142 | 9566 | C<next ("foo")."bar"> will cause "bar" to be part of the argument to |
| 8143 | C<next>. | |
| 9567 | L<C<next>|/next LABEL>. | |
| 8144 | 9568 | |
| 8145 | 9569 | =end original |
| 8146 | 9570 | |
| 8147 | 9571 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
| 8148 | 9572 | また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と |
| 8149 | すると "bar" は C<next> への引数の一部となります。 | |
| 9573 | すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。 | |
| 8150 | 9574 | |
| 8151 | 9575 | =item no MODULE VERSION LIST |
| 8152 | 9576 | X<no declarations> |
| 8153 | 9577 | X<unimporting> |
| 8154 | 9578 | |
| 8155 | 9579 | =item no MODULE VERSION |
| 8156 | 9580 | |
| 8157 | 9581 | =item no MODULE LIST |
| 8158 | 9582 | |
| 8159 | 9583 | =item no MODULE |
| 8160 | 9584 | |
| 8161 | 9585 | =item no VERSION |
| 8162 | 9586 | |
| 8163 | 9587 | =for Pod::Functions unimport some module symbols or semantics at compile time |
| 8164 | 9588 | |
| 8165 | 9589 | =begin original |
| 8166 | 9590 | |
| 8167 | See the C<use> function, of which | |
| 9591 | See the L<C<use>|/use Module VERSION LIST> function, of which | |
| 9592 | L<C<no>|/no MODULE VERSION LIST> is the opposite. | |
| 8168 | 9593 | |
| 8169 | 9594 | =end original |
| 8170 | 9595 | |
| 8171 | L<use> 関数を参照してください; | |
| 9596 | L<C<use>|/use Module VERSION LIST> 関数を参照してください; | |
| 9597 | L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。 | |
| 8172 | 9598 | |
| 8173 | 9599 | =item oct EXPR |
| 8174 | 9600 | X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin> |
| 8175 | 9601 | |
| 8176 | 9602 | =item oct |
| 8177 | 9603 | |
| 8178 | 9604 | =for Pod::Functions convert a string to an octal number |
| 8179 | 9605 | |
| 8180 | 9606 | =begin original |
| 8181 | 9607 | |
| 8182 | 9608 | Interprets EXPR as an octal string and returns the corresponding |
| 8183 | value. | |
| 9609 | value. An octal string consists of octal digits and, as of Perl 5.33.5, | |
| 8184 | ||
| 9610 | an optional C<0o> or C<o> prefix. Each octal digit may be preceded by | |
| 9611 | a single underscore, which will be ignored. | |
| 9612 | (If EXPR happens to start off with C<0x> or C<x>, interprets it as a | |
| 9613 | hex string. If EXPR starts off with C<0b> or C<b>, it is interpreted as a | |
| 8185 | 9614 | binary string. Leading whitespace is ignored in all three cases.) |
| 8186 | 9615 | The following will handle decimal, binary, octal, and hex in standard |
| 8187 | 9616 | Perl notation: |
| 8188 | 9617 | |
| 8189 | 9618 | =end original |
| 8190 | 9619 | |
| 8191 | 9620 | EXPR を 8 進数文字列と解釈して、対応する値を返します。 |
| 8192 | ||
| 9621 | 8 進数文字列は、8 進文字と、Perl 5.33.5 からはオプションの | |
| 8193 | ||
| 9622 | C<0o> または C<o> 接頭辞からなります。 | |
| 9623 | 各 8 進文字の前には一つの下線を置くことができ、これは無視されます。 | |
| 9624 | (EXPR が C<0x> か C<x> で始まるときには、16 進数文字列と解釈します。 | |
| 9625 | EXPR が C<0b> か C<b> で始まるときは、2 進数文字列と解釈します。 | |
| 8194 | 9626 | どの場合でも、先頭の空白は無視されます。) |
| 8195 | 9627 | 以下の例は、標準的な Perl の記法での |
| 8196 | 9628 | 10 進数、2 進数、8 進数、16 進数を扱います: |
| 8197 | 9629 | |
| 8198 | 9630 | $val = oct($val) if $val =~ /^0/; |
| 8199 | 9631 | |
| 8200 | 9632 | =begin original |
| 8201 | 9633 | |
| 8202 | If EXPR is omitted, uses C<$_>. To go the other way | |
| 9634 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way | |
| 8203 | in octal), use sprintf | |
| 9635 | (produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or | |
| 9636 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>: | |
| 8204 | 9637 | |
| 8205 | 9638 | =end original |
| 8206 | 9639 | |
| 8207 | EXPR が省略されると、C<$_> を使います。 | |
| 9640 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 8208 | (8 進数を扱う)その他の方法としては sprintf | |
| 9641 | (8 進数を扱う)その他の方法をとしては L<C<sprintf>|/sprintf FORMAT, LIST> や | |
| 9642 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります: | |
| 8209 | 9643 | |
| 8210 | $dec_perms = (stat("filename"))[2] & 07777; | |
| 9644 | my $dec_perms = (stat("filename"))[2] & 07777; | |
| 8211 | $oct_perm_str = sprintf "%o", $perms; | |
| 9645 | my $oct_perm_str = sprintf "%o", $perms; | |
| 8212 | 9646 | |
| 8213 | 9647 | =begin original |
| 8214 | 9648 | |
| 8215 | The oct | |
| 9649 | The L<C<oct>|/oct EXPR> function is commonly used when a string such as | |
| 8216 | ||
| 9650 | C<644> needs | |
| 9651 | to be converted into a file mode, for example. Although Perl | |
| 8217 | 9652 | automatically converts strings into numbers as needed, this automatic |
| 8218 | 9653 | conversion assumes base 10. |
| 8219 | 9654 | |
| 8220 | 9655 | =end original |
| 8221 | 9656 | |
| 8222 | oct | |
| 9657 | L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに | |
| 8223 | よく使います。 | |
| 9658 | 変換する時によく使います。 | |
| 8224 | 9659 | Perl は必要に応じて自動的に文字列を数値に変換しますが、 |
| 8225 | 9660 | この自動変換は十進数を仮定します。 |
| 8226 | 9661 | |
| 8227 | 9662 | =begin original |
| 8228 | 9663 | |
| 8229 | Leading white space is ignored without warning, as too are any trailing | |
| 9664 | Leading white space is ignored without warning, as too are any trailing | |
| 8230 | non-digits, such as a decimal point (C<oct> only handles | |
| 9665 | non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles | |
| 8231 | integers, not negative integers or floating point). | |
| 9666 | non-negative integers, not negative integers or floating point). | |
| 8232 | 9667 | |
| 8233 | 9668 | =end original |
| 8234 | 9669 | |
| 8235 | 9670 | 先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます |
| 8236 | (C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 | |
| 9671 | (L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 | |
| 8237 | 9672 | |
| 8238 | =item open FILEHANDLE,EXPR | |
| 8239 | X<open> X<pipe> X<file, open> X<fopen> | |
| 8240 | 9673 | |
| 8241 | 9674 | =item open FILEHANDLE,MODE,EXPR |
| 9675 | X<open> X<pipe> X<file, open> X<fopen> | |
| 8242 | 9676 | |
| 8243 | 9677 | =item open FILEHANDLE,MODE,EXPR,LIST |
| 8244 | 9678 | |
| 8245 | 9679 | =item open FILEHANDLE,MODE,REFERENCE |
| 8246 | 9680 | |
| 9681 | =item open FILEHANDLE,EXPR | |
| 9682 | ||
| 8247 | 9683 | =item open FILEHANDLE |
| 8248 | 9684 | |
| 8249 | 9685 | =for Pod::Functions open a file, pipe, or descriptor |
| 8250 | 9686 | |
| 8251 | 9687 | =begin original |
| 8252 | 9688 | |
| 8253 | ||
| 9689 | Associates an internal FILEHANDLE with the external file specified by | |
| 8254 | ||
| 9690 | EXPR. That filehandle will subsequently allow you to perform | |
| 9691 | I/O operations on that file, such as reading from it or writing to it. | |
| 8255 | 9692 | |
| 8256 | 9693 | =end original |
| 8257 | 9694 | |
| 8258 | ||
| 9695 | 内部の FILEHANDLE を、EXPR で指定された外部ファイルに関連付けます。 | |
| 9696 | このファイルハンドルはその後、読んだり書いたりといったそのファイルへの | |
| 9697 | I/O 操作をできるようにします。 | |
| 8259 | 9698 | |
| 8260 | 9699 | =begin original |
| 8261 | 9700 | |
| 8262 | ||
| 9701 | Instead of a filename, you may specify an external command | |
| 9702 | (plus an optional argument list) or a scalar reference, in order to open | |
| 9703 | filehandles on commands or in-memory scalars, respectively. | |
| 8263 | 9704 | |
| 8264 | 9705 | =end original |
| 8265 | 9706 | |
| 8266 | ||
| 9707 | ファイル名の代わりに、コマンドやメモリ内スカラへのファイルハンドルを | |
| 9708 | 開くために、外部コマンド (とオプションの引数リスト) やスカラリファレンスを | |
| 9709 | 指定できます。 | |
| 8267 | 9710 | |
| 8268 | ||
| 9711 | =begin original | |
| 8269 | or die "cannot open < input.txt: $!"; | |
| 8270 | 9712 | |
| 9713 | A thorough reference to C<open> follows. For a gentler introduction to | |
| 9714 | the basics of C<open>, see also the L<perlopentut> manual page. | |
| 9715 | ||
| 9716 | =end original | |
| 9717 | ||
| 9718 | C<open> の完全なリファレンスは後述します。 | |
| 9719 | C<open> の基本に関するより親切な導入に関しては、 | |
| 9720 | L<perlopentut> man ページも参照してください。 | |
| 9721 | ||
| 9722 | =over | |
| 9723 | ||
| 9724 | =item Working with files | |
| 9725 | ||
| 8271 | 9726 | =begin original |
| 8272 | 9727 | |
| 8273 | ||
| 9728 | Most often, C<open> gets invoked with three arguments: the required | |
| 9729 | FILEHANDLE (usually an empty scalar variable), followed by MODE (usually | |
| 9730 | a literal describing the I/O mode the filehandle will use), and then the | |
| 9731 | filename that the new filehandle will refer to. | |
| 8274 | 9732 | |
| 8275 | 9733 | =end original |
| 8276 | 9734 | |
| 8277 | ||
| 9735 | ほとんどの場合、C<open> は 3 引数で起動されます: | |
| 9736 | 必須の FILEHANDLE (通常は空のスカラ変数), 引き続いて MODE (通常は | |
| 9737 | ファイルハンドルを使う I/O モードを記述するリテラル)、 | |
| 9738 | それから新しいファイルハンドルが参照するファイル名です。 | |
| 8278 | 9739 | |
| 8279 | ||
| 9740 | =over | |
| 8280 | or die "cannot open > output.txt: $!"; | |
| 8281 | 9741 | |
| 9742 | =item Simple examples | |
| 9743 | ||
| 9744 | (単純な例) | |
| 9745 | ||
| 8282 | 9746 | =begin original |
| 8283 | 9747 | |
| 8284 | ||
| 9748 | Reading from a file: | |
| 8285 | introduction you may consider L<perlopentut>.) | |
| 8286 | 9749 | |
| 8287 | 9750 | =end original |
| 8288 | 9751 | |
| 8289 | ||
| 9752 | ファイルからの読み込み: | |
| 8290 | L<perlopentut> を参照してください。) | |
| 8291 | 9753 | |
| 9754 | open(my $fh, "<", "input.txt") | |
| 9755 | or die "Can't open < input.txt: $!"; | |
| 9756 | ||
| 9757 | # Process every line in input.txt | |
| 9758 | while (my $line = readline($fh)) { | |
| 9759 | # | |
| 9760 | # ... do something interesting with $line here ... | |
| 9761 | # | |
| 9762 | } | |
| 9763 | ||
| 8292 | 9764 | =begin original |
| 8293 | 9765 | |
| 8294 | ||
| 9766 | or writing to one: | |
| 8295 | new filehandle is autovivified, meaning that the variable is assigned a | |
| 8296 | reference to a newly allocated anonymous filehandle. Otherwise if | |
| 8297 | FILEHANDLE is an expression, its value is the real filehandle. (This is | |
| 8298 | considered a symbolic reference, so C<use strict "refs"> should I<not> be | |
| 8299 | in effect.) | |
| 8300 | 9767 | |
| 8301 | 9768 | =end original |
| 8302 | 9769 | |
| 8303 | ||
| 9770 | そして書き込み: | |
| 8304 | 新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた | |
| 8305 | 無名ファイルハンドルへのリファレンスが代入されます。 | |
| 8306 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の | |
| 8307 | ファイルハンドルの名前として使います。 | |
| 8308 | (これはシンボリックリファレンスとして扱われるので、 | |
| 8309 | C<use strict "refs"> の影響を I<受けません>。) | |
| 8310 | 9771 | |
| 9772 | open(my $fh, ">", "output.txt") | |
| 9773 | or die "Can't open > output.txt: $!"; | |
| 9774 | ||
| 9775 | print $fh "This line gets printed into output.txt.\n"; | |
| 9776 | ||
| 8311 | 9777 | =begin original |
| 8312 | 9778 | |
| 8313 | ||
| 9779 | For a summary of common filehandle operations such as these, see | |
| 8314 | ||
| 9780 | L<perlintro/Files and I/O>. | |
| 8315 | variables--those declared with C<my> or C<state>--will not work for this | |
| 8316 | purpose; so if you're using C<my> or C<state>, specify EXPR in your | |
| 8317 | call to open.) | |
| 8318 | 9781 | |
| 8319 | 9782 | =end original |
| 8320 | 9783 | |
| 8321 | ||
| 9784 | このような基本的なファイルハンドル操作の要約については、 | |
| 8322 | ||
| 9785 | L<perlintro/Files and I/O> を参照してください。 | |
| 8323 | (レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には | |
| 8324 | 使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、 | |
| 8325 | open を呼び出すときに EXPR を指定してください。) | |
| 8326 | 9786 | |
| 9787 | =item About filehandles | |
| 9788 | ||
| 9789 | (ファイルハンドルについて) | |
| 9790 | ||
| 8327 | 9791 | =begin original |
| 8328 | 9792 | |
| 8329 | ||
| 9793 | The first argument to C<open>, labeled FILEHANDLE in this reference, is | |
| 8330 | ||
| 9794 | usually a scalar variable. (Exceptions exist, described in "Other | |
| 8331 | ||
| 9795 | considerations", below.) If the call to C<open> succeeds, then the | |
| 9796 | expression provided as FILEHANDLE will get assigned an open | |
| 9797 | I<filehandle>. That filehandle provides an internal reference to the | |
| 9798 | specified external file, conveniently stored in a Perl variable, and | |
| 9799 | ready for I/O operations such as reading and writing. | |
| 9800 | ||
| 9801 | =end original | |
| 9802 | ||
| 9803 | このリファレンスでは FILEHANDLE というラベルが付いている、 | |
| 9804 | C<open> の最初の引数は、通常はスカラ変数です。 | |
| 9805 | (例外があります; 後述する "Other considerations" で記述されます。) | |
| 9806 | C<open> の呼び出しが成功すると、 | |
| 9807 | FILEHANDLE として提供された式には、 | |
| 9808 | 開いた I<ファイルハンドル> が代入されます。 | |
| 9809 | このファイルハンドルは指定された外部ファイルへの内部参照を提供し、 | |
| 9810 | 好都合なように Perl 変数に保管し、読み書きのような I/O 操作の準備をします。 | |
| 9811 | ||
| 9812 | =item About modes | |
| 9813 | ||
| 9814 | (モードについて) | |
| 9815 | ||
| 9816 | =begin original | |
| 9817 | ||
| 9818 | When calling C<open> with three or more arguments, the second argument | |
| 9819 | -- labeled MODE here -- defines the I<open mode>. MODE is usually a | |
| 9820 | literal string comprising special characters that define the intended | |
| 9821 | I/O role of the filehandle being created: whether it's read-only, or | |
| 9822 | read-and-write, and so on. | |
| 9823 | ||
| 9824 | =end original | |
| 9825 | ||
| 9826 | 3 引数以上で C<open> を呼び出すとき、 | |
| 9827 | 2 番目の引数 -- ここでは MODE -- は I<開くモード> を定義します。 | |
| 9828 | MODE は普通、作られるファイルハンドルが意図している I/O の役割 (読み込み専用、 | |
| 9829 | 読み書き、など)を定義する特別な文字で構成されるリテラルな文字列です。 | |
| 9830 | ||
| 9831 | =begin original | |
| 9832 | ||
| 9833 | If MODE is C<< < >>, the file is opened for input (read-only). | |
| 8332 | 9834 | If MODE is C<< > >>, the file is opened for output, with existing files |
| 8333 | 9835 | first being truncated ("clobbered") and nonexisting files newly created. |
| 8334 | 9836 | If MODE is C<<< >> >>>, the file is opened for appending, again being |
| 8335 | 9837 | created if necessary. |
| 8336 | 9838 | |
| 8337 | 9839 | =end original |
| 8338 | 9840 | |
| 8339 | ||
| 9841 | MODE が C<< < >> の場合、ファイルは入力用(読み込み専用)に開かれます。 | |
| 8340 | エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。 | |
| 8341 | MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。 | |
| 8342 | 9842 | MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが |
| 8343 | 9843 | ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。 |
| 8344 | 9844 | MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら |
| 8345 | 9845 | 作成されます。 |
| 8346 | 9846 | |
| 8347 | 9847 | =begin original |
| 8348 | 9848 | |
| 8349 | 9849 | You can put a C<+> in front of the C<< > >> or C<< < >> to |
| 8350 | 9850 | indicate that you want both read and write access to the file; thus |
| 8351 | C<< +< >> is almost always preferred for read/write updates--the | |
| 9851 | C<< +< >> is almost always preferred for read/write updates--the | |
| 8352 | 9852 | C<< +> >> mode would clobber the file first. You can't usually use |
| 8353 | 9853 | either read-write mode for updating textfiles, since they have |
| 8354 | variable-length records. See the B<-i> switch in | |
| 9854 | variable-length records. See the B<-i> switch in | |
| 8355 | better approach. The file is | |
| 9855 | L<perlrun|perlrun/-i[extension]> for a better approach. The file is | |
| 8356 | modified by the process's | |
| 9856 | created with permissions of C<0666> modified by the process's | |
| 9857 | L<C<umask>|/umask EXPR> value. | |
| 8357 | 9858 | |
| 8358 | 9859 | =end original |
| 8359 | 9860 | |
| 8360 | 9861 | ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、 |
| 8361 | 9862 | C<< > >> や C<< < >> の前に C<+> を付けることができます: |
| 8362 | 9863 | 従って、ほとんど常に C<< +< >> が読み書き更新のために使われます -- |
| 8363 | 9864 | C<< +> >> モードはまずファイルを上書きします。 |
| 8364 | 9865 | 普通はこれらの読み書きモードをテキストファイルの更新のためには使えません; |
| 8365 | 9866 | なぜなら可変長のレコードで構成されているからです。 |
| 8366 | よりよい手法については L<perlrun | |
| 9867 | よりよい手法については L<perlrun|perlrun/-i[extension]> の | |
| 8367 | ||
| 9868 | B<-i> オプションを参照してください。 | |
| 8368 | ||
| 9869 | ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した | |
| 9870 | パーミッションで作成されます。 | |
| 8369 | 9871 | |
| 8370 | 9872 | =begin original |
| 8371 | 9873 | |
| 8372 | These various prefixes correspond to the fopen(3) modes of C<r>, | |
| 9874 | These various prefixes correspond to the L<fopen(3)> modes of C<r>, | |
| 8373 | 9875 | C<r+>, C<w>, C<w+>, C<a>, and C<a+>. |
| 8374 | 9876 | |
| 8375 | 9877 | =end original |
| 8376 | 9878 | |
| 8377 | これらの様々な前置詞は fopen(3) の C<r>, C<r+>, | |
| 9879 | これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>, | |
| 8378 | 9880 | C<w>, C<w+>, C<a>, C<a+> のモードに対応します。 |
| 8379 | 9881 | |
| 8380 | 9882 | =begin original |
| 8381 | 9883 | |
| 8382 | ||
| 9884 | More examples of different modes in action: | |
| 8383 | should be concatenated (in that order), preferably separated by white | |
| 8384 | space. You can--but shouldn't--omit the mode in these forms when that mode | |
| 8385 | is C<< < >>. It is always safe to use the two-argument form of C<open> if | |
| 8386 | the filename argument is a known literal. | |
| 8387 | 9885 | |
| 8388 | 9886 | =end original |
| 8389 | 9887 | |
| 8390 | ||
| 9888 | 実用的な異なったモードに関する更なる例: | |
| 8391 | 結合されます(空白によって分割されているかもしれません)。 | |
| 8392 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 | |
| 8393 | するべきではありません)。 | |
| 8394 | ファイル引数が既知のリテラルの場合、2 引数形式の C<open> は常に安全です。 | |
| 8395 | 9889 | |
| 8396 | ||
| 9890 | # Open a file for concatenation | |
| 9891 | open(my $log, ">>", "/usr/spool/news/twitlog") | |
| 9892 | or warn "Couldn't open log file; discarding input"; | |
| 8397 | 9893 | |
| 8398 | ||
| 9894 | # Open a file for reading and writing | |
| 8399 | ||
| 9895 | open(my $dbase, "+<", "dbase.mine") | |
| 8400 | ||
| 9896 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 8401 | output to us. In the two-argument (and one-argument) form, one should | |
| 8402 | replace dash (C<->) with the command. | |
| 8403 | See L<perlipc/"Using open() for IPC"> for more examples of this. | |
| 8404 | (You are not allowed to C<open> to a command that pipes both in I<and> | |
| 8405 | out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
| 8406 | L<perlipc/"Bidirectional Communication with Another Process"> for | |
| 8407 | alternatives.) | |
| 8408 | 9897 | |
| 8409 | =e | |
| 9898 | =item Checking the return value | |
| 8410 | 9899 | |
| 8411 | ||
| 9900 | (返り値をチェックする) | |
| 8412 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして | |
| 8413 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに | |
| 8414 | パイプされるコマンドとして解釈されます。 | |
| 8415 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに | |
| 8416 | 使えます。 | |
| 8417 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を | |
| 8418 | 参照してください。 | |
| 8419 | (C<open> を入出力 I<両用> にパイプすることは出来ませんが | |
| 8420 | 代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
| 8421 | L<perlipc/"Bidirectional Communication with Another Process"> を | |
| 8422 | 参照してください。) | |
| 8423 | 9901 | |
| 8424 | 9902 | =begin original |
| 8425 | 9903 | |
| 8426 | ||
| 9904 | Open returns nonzero on success, the undefined value otherwise. If the | |
| 8427 | ||
| 9905 | C<open> involved a pipe, the return value happens to be the pid of the | |
| 8428 | ||
| 9906 | subprocess. | |
| 8429 | C<open> with more than three arguments for non-pipe modes is not yet | |
| 8430 | defined, but experimental "layers" may give extra LIST arguments | |
| 8431 | meaning. | |
| 8432 | 9907 | |
| 8433 | 9908 | =end original |
| 8434 | 9909 | |
| 8435 | ||
| 9910 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 | |
| 8436 | ||
| 9911 | パイプに関る C<open> のときには、返り値は | |
| 8437 | ||
| 9912 | サブプロセスの pid となります。 | |
| 8438 | パイプモードではない C<open> での三つ以上の引数の意味はまだ未定義ですが、 | |
| 8439 | 実験的な「層」は追加の LIST 引数の意味を与えます。 | |
| 8440 | 9913 | |
| 8441 | 9914 | =begin original |
| 8442 | 9915 | |
| 8443 | ||
| 9916 | When opening a file, it's seldom a good idea to continue if the request | |
| 8444 | o | |
| 9917 | failed, so C<open> is frequently used with L<C<die>|/die LIST>. Even if | |
| 9918 | you want your code to do something other than C<die> on a failed open, | |
| 9919 | you should still always check the return value from opening a file. | |
| 8445 | 9920 | |
| 8446 | 9921 | =end original |
| 8447 | 9922 | |
| 8448 | ||
| 9923 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い | |
| 8449 | ||
| 9924 | 考えなので、C<open> はしばしば | |
| 9925 | L<C<die>|/die LIST> と結び付けられて使われます。 | |
| 9926 | 開くときに失敗したときに L<C<die>|/die LIST> 意外の何かを | |
| 9927 | したい場合でも、ファイルを開いた時の返り値を常にチェックするべきです。 | |
| 8450 | 9928 | |
| 9929 | =back | |
| 9930 | ||
| 9931 | =item Specifying I/O layers in MODE | |
| 9932 | ||
| 9933 | (MODE で I/O 層を指定する) | |
| 9934 | ||
| 8451 | 9935 | =begin original |
| 8452 | 9936 | |
| 8453 | You | |
| 9937 | You can use the three-argument form of open to specify | |
| 8454 | I/O layers (sometimes referred to as "disciplines") to apply to the | |
| 9938 | I/O layers (sometimes referred to as "disciplines") to apply to the new | |
| 8455 | ||
| 9939 | filehandle. These affect how the input and output are processed (see | |
| 9940 | L<open> and | |
| 8456 | 9941 | L<PerlIO> for more details). For example: |
| 8457 | 9942 | |
| 8458 | 9943 | =end original |
| 8459 | 9944 | |
| 8460 | ||
| 9945 | 新しいファイルハンドルに適用する | |
| 8461 | I/O 層(「ディシプリン」とも呼ばれます)を指定 | |
| 9946 | I/O 層(「ディシプリン」とも呼ばれます)を指定するために | |
| 8462 | ||
| 9947 | open の 3 引数形式を使えます。 | |
| 9948 | これらはどのように入出力が処理されるかに影響を与えます | |
| 8463 | 9949 | (詳細については L<open> と L<PerlIO> を参照してください)。 |
| 8464 | 9950 | 例えば: |
| 8465 | 9951 | |
| 8466 | | |
| 9952 | # loads PerlIO::encoding automatically | |
| 8467 | | |
| 9953 | open(my $fh, "<:encoding(UTF-8)", $filename) | |
| 9954 | || die "Can't open UTF-8 encoded $filename: $!"; | |
| 8468 | 9955 | |
| 8469 | 9956 | =begin original |
| 8470 | 9957 | |
| 8471 | opens the UTF8-encoded file containing Unicode characters; | |
| 9958 | This opens the UTF8-encoded file containing Unicode characters; | |
| 8472 | 9959 | see L<perluniintro>. Note that if layers are specified in the |
| 8473 | three-argument form, then default layers stored in | |
| 9960 | three-argument form, then default layers stored in | |
| 8474 | ||
| 9961 | L<C<${^OPEN}>|perlvar/${^OPEN}> | |
| 8475 | ||
| 9962 | (usually set by the L<open> pragma or the switch C<-CioD>) are ignored. | |
| 9963 | Those layers will also be ignored if you specify a colon with no name | |
| 8476 | 9964 | following it. In that case the default layer for the operating system |
| 8477 | 9965 | (:raw on Unix, :crlf on Windows) is used. |
| 8478 | 9966 | |
| 8479 | 9967 | =end original |
| 8480 | 9968 | |
| 8481 | は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; | |
| 9969 | これは、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; | |
| 8482 | 9970 | L<perluniintro> を参照してください。 |
| 8483 | 3 引数形式で層を指定すると、${^OPEN} | |
| 9971 | 3 引数形式で層を指定すると、L<C<${^OPEN}>|perlvar/${^OPEN}> | |
| 8484 | 通常は | |
| 9972 | (通常は L<open> プラグマか C<-CioD> オプションでセットされます) に | |
| 8485 | ||
| 9973 | 保存されたデフォルト層は無視されることに注意してください。 | |
| 8486 | 9974 | これらの層は、名前なしでコロンを指定した場合にも無視されます。 |
| 8487 | 9975 | この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が |
| 8488 | 9976 | 使われます。 |
| 8489 | 9977 | |
| 8490 | 9978 | =begin original |
| 8491 | 9979 | |
| 8492 | O | |
| 9980 | On some systems (in general, DOS- and Windows-based systems) | |
| 8493 | ||
| 9981 | L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not | |
| 8494 | the s | |
| 9982 | working with a text file. For the sake of portability it is a good idea | |
| 9983 | always to use it when appropriate, and never to use it when it isn't | |
| 9984 | appropriate. Also, people can set their I/O to be by default | |
| 9985 | UTF8-encoded Unicode, not bytes. | |
| 8495 | 9986 | |
| 8496 | 9987 | =end original |
| 8497 | 9988 | |
| 8498 | ||
| 9989 | テキストファイルでないものを扱う場合に | |
| 8499 | ||
| 9990 | L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な | |
| 9991 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 | |
| 9992 | 移植性のために、適切なときには常にこれを使い、適切でないときには | |
| 9993 | 決して使わないというのは良い考えです。 | |
| 9994 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた | |
| 9995 | Unicode にセットすることも出来ます。 | |
| 8500 | 9996 | |
| 9997 | =item Using C<undef> for temporary files | |
| 9998 | ||
| 9999 | (一時ファイルとして C<undef> を使う) | |
| 10000 | ||
| 8501 | 10001 | =begin original |
| 8502 | 10002 | |
| 8503 | ||
| 10003 | As a special case the three-argument form with a read/write mode and the third | |
| 8504 | ||
| 10004 | argument being L<C<undef>|/undef EXPR>: | |
| 8505 | for dealing with this. The key distinction between systems that need | |
| 8506 | C<binmode> and those that don't is their text file formats. Systems | |
| 8507 | like Unix, Mac OS, and Plan 9, that end lines with a single | |
| 8508 | character and encode that character in C as C<"\n"> do not | |
| 8509 | need C<binmode>. The rest need it. | |
| 8510 | 10005 | |
| 8511 | 10006 | =end original |
| 8512 | 10007 | |
| 8513 | ||
| 10008 | 特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が | |
| 8514 | ||
| 10009 | L<C<undef>|/undef EXPR> の場合: | |
| 8515 | 動作させているシステムで C<binmode> が必要か不要化を区別する鍵は、テキスト | |
| 8516 | ファイルの形式です。 | |
| 8517 | Unix, Mac OS, Plan 9 といった、行の境界を 1 文字で表現し、それが C では | |
| 8518 | C<"\n"> でエンコードされる場合、C<binmode> は不要です。 | |
| 8519 | それ以外では必要です。 | |
| 8520 | 10010 | |
| 10011 | open(my $tmp, "+>", undef) or die ... | |
| 10012 | ||
| 8521 | 10013 | =begin original |
| 8522 | 10014 | |
| 8523 | ||
| 10015 | opens a filehandle to a newly created empty anonymous temporary file. | |
| 8524 | i | |
| 10016 | (This happens under any mode, which makes C<< +> >> the only useful and | |
| 8525 | ||
| 10017 | sensible mode to use.) You will need to | |
| 8526 | ||
| 10018 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading. | |
| 8527 | modules that can help with that problem)) always check | |
| 8528 | the return value from opening a file. | |
| 8529 | 10019 | |
| 8530 | 10020 | =end original |
| 8531 | 10021 | |
| 8532 | ファイル | |
| 10022 | 新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。 | |
| 8533 | ||
| 10023 | (これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります。) | |
| 8534 | ||
| 10024 | 読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が | |
| 8535 | ||
| 10025 | 必要です。 | |
| 8536 | きれいにフォーマットされたエラーメッセージを作りたい場合 | |
| 8537 | (但しこの問題を助けるモジュールがあります))でも、 | |
| 8538 | ファイルを開いた時の返り値を常にチェックするべきです。 | |
| 8539 | 10026 | |
| 10027 | =item Opening a filehandle into an in-memory scalar | |
| 10028 | ||
| 10029 | (ファイルハンドルをメモリ内スカラに開く) | |
| 10030 | ||
| 8540 | 10031 | =begin original |
| 8541 | 10032 | |
| 8542 | ||
| 10033 | You can open filehandles directly to Perl scalars instead of a file or | |
| 8543 | ||
| 10034 | other resource external to the program. To do so, provide a reference to | |
| 10035 | that scalar as the third argument to C<open>, like so: | |
| 8544 | 10036 | |
| 8545 | 10037 | =end original |
| 8546 | 10038 | |
| 8547 | ||
| 10039 | ファイルやその他のプログラムから見ての外部リソースではなく、 | |
| 8548 | ||
| 10040 | Perl スカラに対して直接ファイルハンドルを開くことができます。 | |
| 10041 | そうするためには、次のように、C<open> の 3 番目の引数としてその | |
| 10042 | スカラへのリファレンスを提供します: | |
| 8549 | 10043 | |
| 8550 | | |
| 10044 | open(my $memory, ">", \$var) | |
| 10045 | or die "Can't open memory file: $!"; | |
| 10046 | print $memory "foo!\n"; # output will appear in $var | |
| 8551 | 10047 | |
| 8552 | 10048 | =begin original |
| 8553 | 10049 | |
| 8554 | open | |
| 10050 | To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first: | |
| 8555 | works for symmetry, but you really should consider writing something | |
| 8556 | to the temporary file first. You will need to seek() to do the | |
| 8557 | reading. | |
| 8558 | 10051 | |
| 8559 | 10052 | =end original |
| 8560 | 10053 | |
| 8561 | ||
| 10054 | C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして | |
| 8562 | ||
| 10055 | 再び開きたい場合は、先にそれを閉じます: | |
| 8563 | 一時ファイルにはまず何かを書き込みたいはずです。 | |
| 8564 | 読み込みを行うためには seek() が必要です。 | |
| 8565 | 10056 | |
| 10057 | close STDOUT; | |
| 10058 | open(STDOUT, ">", \$variable) | |
| 10059 | or die "Can't open STDOUT: $!"; | |
| 10060 | ||
| 8566 | 10061 | =begin original |
| 8567 | 10062 | |
| 8568 | ||
| 10063 | The scalars for in-memory files are treated as octet strings: unless | |
| 8569 | ||
| 10064 | the file is being opened with truncation the scalar may not contain | |
| 8570 | ||
| 10065 | any code points over 0xFF. | |
| 8571 | 10066 | |
| 8572 | 10067 | =end original |
| 8573 | 10068 | |
| 8574 | ||
| 10069 | オンメモリファイルのためのスカラはオクテット文字列として扱われます: | |
| 8575 | ||
| 10070 | ファイルが切り詰められて開かれない限り、 | |
| 8576 | ||
| 10071 | スカラは 0xFF を超える符号位置を含みません。 | |
| 8577 | 開くことができます: | |
| 8578 | 10072 | |
| 8579 | ||
| 10073 | =begin original | |
| 8580 | 10074 | |
| 10075 | Opening in-memory files I<can> fail for a variety of reasons. As with | |
| 10076 | any other C<open>, check the return value for success. | |
| 10077 | ||
| 10078 | =end original | |
| 10079 | ||
| 10080 | オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。 | |
| 10081 | その他の C<open> と同様、成功したかを返り値でチェックしてください。 | |
| 10082 | ||
| 8581 | 10083 | =begin original |
| 8582 | 10084 | |
| 8583 | T | |
| 10085 | I<Technical note>: This feature works only when Perl is built with | |
| 10086 | PerlIO -- the default, except with older (pre-5.16) Perl installations | |
| 10087 | that were configured to not include it (e.g. via C<Configure | |
| 10088 | -Uuseperlio>). You can see whether your Perl was built with PerlIO by | |
| 10089 | running C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO; | |
| 10090 | otherwise you don't. | |
| 8584 | 10091 | |
| 8585 | 10092 | =end original |
| 8586 | 10093 | |
| 8587 | ||
| 10094 | I<技術ノート>: この機能は Perl が PerlIO を使ってビルドされている | |
| 8588 | ||
| 10095 | 場合にのみ動作します; これは (C<Configure -Uuseperlio> によって) | |
| 10096 | これを含まないように設定されていた古い (5.16 より前の) Perl でない限り、 | |
| 10097 | デフォルトです。 | |
| 10098 | Perl が PerlIO つきでビルドされているかどうかを確認するには、 | |
| 10099 | C<perl -V:useperlio> を見ます。 | |
| 10100 | これが C<'define'> なら PerlIO を使っています; | |
| 10101 | そうでなければ使っていません。 | |
| 8589 | 10102 | |
| 8590 | ||
| 10103 | =begin original | |
| 8591 | open(STDOUT, ">", \$variable) | |
| 8592 | or die "Can't open STDOUT: $!"; | |
| 8593 | 10104 | |
| 10105 | See L<perliol> for detailed info on PerlIO. | |
| 10106 | ||
| 10107 | =end original | |
| 10108 | ||
| 10109 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 | |
| 10110 | ||
| 10111 | =item Opening a filehandle into a command | |
| 10112 | ||
| 10113 | (ファイルハンドルをコマンドに開く) | |
| 10114 | ||
| 8594 | 10115 | =begin original |
| 8595 | 10116 | |
| 8596 | ||
| 10117 | If MODE is C<|->, then the filename is | |
| 10118 | interpreted as a command to which output is to be piped, and if MODE | |
| 10119 | is C<-|>, the filename is interpreted as a command that pipes | |
| 10120 | output to us. In the two-argument (and one-argument) form, one should | |
| 10121 | replace dash (C<->) with the command. | |
| 10122 | See L<perlipc/"Using open() for IPC"> for more examples of this. | |
| 10123 | (You are not allowed to L<C<open>|/open FILEHANDLE,MODE,EXPR> to a command | |
| 10124 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
| 10125 | L<perlipc/"Bidirectional Communication with Another Process"> for | |
| 10126 | alternatives.) | |
| 8597 | 10127 | |
| 8598 | 10128 | =end original |
| 8599 | 10129 | |
| 8600 | ||
| 10130 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして | |
| 10131 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに | |
| 10132 | パイプされるコマンドとして解釈されます。 | |
| 10133 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。 | |
| 10134 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を | |
| 10135 | 参照してください。 | |
| 10136 | (L<C<open>|/open FILEHANDLE,MODE,EXPR> を入出力 I<両用> にパイプすることは | |
| 10137 | 出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
| 10138 | L<perlipc/"Bidirectional Communication with Another Process"> を | |
| 10139 | 参照してください。) | |
| 8601 | 10140 | |
| 8602 | $ | |
| 10141 | open(my $article_fh, "-|", "caesar <$article") # decrypt | |
| 8603 | | |
| 10142 | # article | |
| 8604 | | |
| 10143 | or die "Can't start caesar: $!"; | |
| 8605 | 10144 | |
| 8606 | | |
| 10145 | open(my $article_fh, "caesar <$article |") # ditto | |
| 8607 | | |
| 10146 | or die "Can't start caesar: $!"; | |
| 8608 | 10147 | |
| 8609 | | |
| 10148 | open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id | |
| 8610 | | |
| 10149 | or die "Can't start sort: $!"; | |
| 8611 | 10150 | |
| 8612 | ||
| 10151 | =begin original | |
| 8613 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 8614 | 10152 | |
| 8615 | open | |
| 10153 | In the form of pipe opens taking three or more arguments, if LIST is specified | |
| 8616 | | |
| 10154 | (extra arguments after the command name) then LIST becomes arguments | |
| 10155 | to the command invoked if the platform supports it. The meaning of | |
| 10156 | L<C<open>|/open FILEHANDLE,MODE,EXPR> with more than three arguments for | |
| 10157 | non-pipe modes is not yet defined, but experimental "layers" may give | |
| 10158 | extra LIST arguments meaning. | |
| 8617 | 10159 | |
| 8618 | ||
| 10160 | =end original | |
| 8619 | or die "Can't start caesar: $!"; | |
| 8620 | 10161 | |
| 8621 | ||
| 10162 | パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が | |
| 8622 | | |
| 10163 | 指定されると、プラットフォームが対応していれば、LIST は起動される | |
| 10164 | コマンドへの引数となります。 | |
| 10165 | パイプモードではない L<C<open>|/open FILEHANDLE,MODE,EXPR> での | |
| 10166 | 三つ以上の引数の意味はまだ未定義ですが、実験的な「層」は | |
| 10167 | 追加の LIST 引数の意味を与えます。 | |
| 8623 | 10168 | |
| 8624 | ||
| 10169 | =begin original | |
| 8625 | open(MEMORY, ">", \$var) | |
| 8626 | or die "Can't open memory file: $!"; | |
| 8627 | print MEMORY "foo!\n"; # output will appear in $var | |
| 8628 | 10170 | |
| 8629 | | |
| 10171 | If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|> | |
| 10172 | with the one- or two-argument forms of | |
| 10173 | L<C<open>|/open FILEHANDLE,MODE,EXPR>), an implicit L<C<fork>|/fork> is done, | |
| 10174 | so L<C<open>|/open FILEHANDLE,MODE,EXPR> returns twice: in the parent process | |
| 10175 | it returns the pid | |
| 10176 | of the child process, and in the child process it returns (a defined) C<0>. | |
| 10177 | Use C<defined($pid)> or C<//> to determine whether the open was successful. | |
| 8630 | 10178 | |
| 8631 | | |
| 10179 | =end original | |
| 8632 | process($file, "fh00"); | |
| 8633 | } | |
| 8634 | 10180 | |
| 8635 | | |
| 10181 | 1 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR>) で | |
| 8636 | | |
| 10182 | (C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、 | |
| 8637 | | |
| 10183 | 暗黙の L<C<fork>|/fork> が行なわれるので、 | |
| 8638 | ||
| 10184 | L<C<open>|/open FILEHANDLE,MODE,EXPR> は 2 回返ります; | |
| 8639 | | |
| 10185 | 親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が | |
| 8640 | ||
| 10186 | 返されます。 | |
| 8641 | | |
| 10187 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を | |
| 10188 | 使います。 | |
| 8642 | 10189 | |
| 8643 | | |
| 10190 | =begin original | |
| 8644 | ||
| 8645 | | |
| 10192 | For example, use either | |
| 8646 | ||
| 8647 | | |
| 10194 | =end original | |
| 8648 | ||
| 8649 | ||
| 10196 | 例えば、以下の二つ | |
| 8650 | ||
| 10198 | my $child_pid = open(my $from_kid, "-|") | |
| 10199 | // die "Can't fork: $!"; | |
| 10200 | ||
| 10201 | =begin original | |
| 10202 | ||
| 10203 | or | |
| 10204 | ||
| 10205 | =end original | |
| 10206 | ||
| 10207 | または | |
| 10208 | ||
| 10209 | my $child_pid = open(my $to_kid, "|-") | |
| 10210 | // die "Can't fork: $!"; | |
| 10211 | ||
| 10212 | =begin original | |
| 10213 | ||
| 10214 | followed by | |
| 10215 | ||
| 10216 | =end original | |
| 10217 | ||
| 10218 | を使って、後で以下のようにします。 | |
| 10219 | ||
| 10220 | if ($child_pid) { | |
| 10221 | # am the parent: | |
| 10222 | # either write $to_kid or else read $from_kid | |
| 10223 | ... | |
| 10224 | waitpid $child_pid, 0; | |
| 10225 | } else { | |
| 10226 | # am the child; use STDIN/STDOUT normally | |
| 10227 | ... | |
| 10228 | exit; | |
| 8651 | 10229 | } |
| 8652 | 10230 | |
| 8653 | 10231 | =begin original |
| 8654 | 10232 | |
| 8655 | ||
| 10233 | The filehandle behaves normally for the parent, but I/O to that | |
| 10234 | filehandle is piped from/to the STDOUT/STDIN of the child process. | |
| 10235 | In the child process, the filehandle isn't opened--I/O happens from/to | |
| 10236 | the new STDOUT/STDIN. Typically this is used like the normal | |
| 10237 | piped open when you want to exercise more control over just how the | |
| 10238 | pipe command gets executed, such as when running setuid and | |
| 10239 | you don't want to have to scan shell commands for metacharacters. | |
| 8656 | 10240 | |
| 8657 | 10241 | =end original |
| 8658 | 10242 | |
| 8659 | ||
| 10243 | 親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる | |
| 10244 | 入出力は、子プロセスの STDIN/STDOUT にパイプされます。 | |
| 10245 | 子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か | |
| 10246 | STDIN に対して行なわれます。 | |
| 10247 | これは、setuid で実行して、シェルコマンドのメタ文字を | |
| 10248 | 検索させたくないような場合に、パイプコマンドの起動の仕方を | |
| 10249 | 制御したいとき、普通のパイプの open と同じように使います。 | |
| 8660 | 10250 | |
| 8661 | 10251 | =begin original |
| 8662 | 10252 | |
| 10253 | The following blocks are more or less equivalent: | |
| 10254 | ||
| 10255 | =end original | |
| 10256 | ||
| 10257 | 以下の組み合わせは、だいたい同じものです: | |
| 10258 | ||
| 10259 | open(my $fh, "|tr '[a-z]' '[A-Z]'"); | |
| 10260 | open(my $fh, "|-", "tr '[a-z]' '[A-Z]'"); | |
| 10261 | open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]'; | |
| 10262 | open(my $fh, "|-", "tr", '[a-z]', '[A-Z]'); | |
| 10263 | ||
| 10264 | open(my $fh, "cat -n '$file'|"); | |
| 10265 | open(my $fh, "-|", "cat -n '$file'"); | |
| 10266 | open(my $fh, "-|") || exec "cat", "-n", $file; | |
| 10267 | open(my $fh, "-|", "cat", "-n", $file); | |
| 10268 | ||
| 10269 | =begin original | |
| 10270 | ||
| 10271 | The last two examples in each block show the pipe as "list form", which | |
| 10272 | is not yet supported on all platforms. (If your platform has a real | |
| 10273 | L<C<fork>|/fork>, such as Linux and macOS, you can use the list form; it | |
| 10274 | also works on Windows with Perl 5.22 or later.) You would want to use | |
| 10275 | the list form of the pipe so you can pass literal arguments to the | |
| 10276 | command without risk of the shell interpreting any shell metacharacters | |
| 10277 | in them. However, this also bars you from opening pipes to commands that | |
| 10278 | intentionally contain shell metacharacters, such as: | |
| 10279 | ||
| 10280 | =end original | |
| 10281 | ||
| 10282 | それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、 | |
| 10283 | これはまだ全てのプラットフォームで対応しているわけではなりません。 | |
| 10284 | (もし実行しているプラットフォームで本当の | |
| 10285 | L<C<fork>|/fork> があれば(Linux や | |
| 10286 | MacOS X なら)リスト形式が使えます; Perl 5.22 以降では Windows でも | |
| 10287 | 動作します。) | |
| 10288 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 | |
| 10289 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 | |
| 10290 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして | |
| 10291 | 開くことを妨げます: | |
| 10292 | ||
| 10293 | open(my $fh, "|cat -n | expand -4 | lpr") | |
| 10294 | || die "Can't open pipeline to lpr: $!"; | |
| 10295 | ||
| 10296 | =begin original | |
| 10297 | ||
| 10298 | See L<perlipc/"Safe Pipe Opens"> for more examples of this. | |
| 10299 | ||
| 10300 | =end original | |
| 10301 | ||
| 10302 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を | |
| 10303 | 参照してください。 | |
| 10304 | ||
| 10305 | =item Duping filehandles | |
| 10306 | ||
| 10307 | (ハンドルの複製) | |
| 10308 | ||
| 10309 | =begin original | |
| 10310 | ||
| 8663 | 10311 | You may also, in the Bourne shell tradition, specify an EXPR beginning |
| 8664 | 10312 | with C<< >& >>, in which case the rest of the string is interpreted |
| 8665 | 10313 | as the name of a filehandle (or file descriptor, if numeric) to be |
| 8666 | duped (as | |
| 10314 | duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>, | |
| 8667 | 10315 | C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. |
| 8668 | 10316 | The mode you specify should match the mode of the original filehandle. |
| 8669 | 10317 | (Duping a filehandle does not take into account any existing contents |
| 8670 | 10318 | of IO buffers.) If you use the three-argument |
| 8671 | 10319 | form, then you can pass either a |
| 8672 | 10320 | number, the name of a filehandle, or the normal "reference to a glob". |
| 8673 | 10321 | |
| 8674 | 10322 | =end original |
| 8675 | 10323 | |
| 8676 | 10324 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >> |
| 8677 | 10325 | を付けると、EXPR の残りの文字列をファイルハンドル名 |
| 8678 | (数字であれば、ファイル記述子) と解釈して、それを ( | |
| 10326 | (数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって) | |
| 8679 | 10327 | 複製してオープンします。 |
| 8680 | 10328 | C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, |
| 8681 | 10329 | C<< +< >>というモード指定に付けることができます。 |
| 8682 | 10330 | 指定するモード指定は、もとのファイルハンドルのモードと |
| 8683 | 10331 | 合っていないといけません。 |
| 8684 | 10332 | (ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。) |
| 8685 | 10333 | 3 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、 |
| 8686 | 10334 | 通常の「グロブへのリファレンス」を渡します。 |
| 8687 | 10335 | |
| 8688 | 10336 | =begin original |
| 8689 | 10337 | |
| 8690 | 10338 | Here is a script that saves, redirects, and restores C<STDOUT> and |
| 8691 | 10339 | C<STDERR> using various methods: |
| 8692 | 10340 | |
| 8693 | 10341 | =end original |
| 8694 | 10342 | |
| 8695 | 10343 | C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します: |
| 8696 | 10344 | |
| 8697 | 10345 | #!/usr/bin/perl |
| 8698 | open(my $oldout, ">&STDOUT") | |
| 10346 | open(my $oldout, ">&STDOUT") | |
| 8699 | | |
| 10347 | or die "Can't dup STDOUT: $!"; | |
| 10348 | open(OLDERR, ">&", \*STDERR) | |
| 10349 | or die "Can't dup STDERR: $!"; | |
| 8700 | 10350 | |
| 8701 | open(STDOUT, '>', "foo.out") | |
| 10351 | open(STDOUT, '>', "foo.out") | |
| 8702 | | |
| 10352 | or die "Can't redirect STDOUT: $!"; | |
| 10353 | open(STDERR, ">&STDOUT") | |
| 10354 | or die "Can't dup STDOUT: $!"; | |
| 8703 | 10355 | |
| 8704 | 10356 | select STDERR; $| = 1; # make unbuffered |
| 8705 | 10357 | select STDOUT; $| = 1; # make unbuffered |
| 8706 | 10358 | |
| 8707 | 10359 | print STDOUT "stdout 1\n"; # this works for |
| 8708 | 10360 | print STDERR "stderr 1\n"; # subprocesses too |
| 8709 | 10361 | |
| 8710 | open(STDOUT, ">&", $oldout) | |
| 10362 | open(STDOUT, ">&", $oldout) | |
| 8711 | | |
| 10363 | or die "Can't dup \$oldout: $!"; | |
| 10364 | open(STDERR, ">&OLDERR") | |
| 10365 | or die "Can't dup OLDERR: $!"; | |
| 8712 | 10366 | |
| 8713 | 10367 | print STDOUT "stdout 2\n"; |
| 8714 | 10368 | print STDERR "stderr 2\n"; |
| 8715 | 10369 | |
| 8716 | 10370 | =begin original |
| 8717 | 10371 | |
| 8718 | 10372 | If you specify C<< '<&=X' >>, where C<X> is a file descriptor number |
| 8719 | or a filehandle, then Perl will do an equivalent of C's | |
| 10373 | or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of | |
| 8720 | that file descriptor (and not call | |
| 10374 | that file descriptor (and not call L<dup(2)>); this is more | |
| 8721 | 10375 | parsimonious of file descriptors. For example: |
| 8722 | 10376 | |
| 8723 | 10377 | =end original |
| 8724 | 10378 | |
| 8725 | 10379 | C<X> をファイル記述子の番号かファイルハンドルとして、 |
| 8726 | 10380 | C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する |
| 8727 | C の | |
| 10381 | C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません); | |
| 8728 | 10382 | これはファイル記述子をより節約します。 |
| 8729 | 10383 | 例えば: |
| 8730 | 10384 | |
| 8731 | 10385 | # open for input, reusing the fileno of $fd |
| 8732 | open( | |
| 10386 | open(my $fh, "<&=", $fd) | |
| 8733 | 10387 | |
| 8734 | 10388 | =begin original |
| 8735 | 10389 | |
| 8736 | 10390 | or |
| 8737 | 10391 | |
| 8738 | 10392 | =end original |
| 8739 | 10393 | |
| 8740 | 10394 | または |
| 8741 | 10395 | |
| 8742 | open( | |
| 10396 | open(my $fh, "<&=$fd") | |
| 8743 | 10397 | |
| 8744 | 10398 | =begin original |
| 8745 | 10399 | |
| 8746 | 10400 | or |
| 8747 | 10401 | |
| 8748 | 10402 | =end original |
| 8749 | 10403 | |
| 8750 | 10404 | または |
| 8751 | 10405 | |
| 8752 | # open for append, using the fileno of | |
| 10406 | # open for append, using the fileno of $oldfh | |
| 8753 | open( | |
| 10407 | open(my $fh, ">>&=", $oldfh) | |
| 8754 | 10408 | |
| 8755 | 10409 | =begin original |
| 8756 | 10410 | |
| 8757 | or | |
| 8758 | ||
| 8759 | =end original | |
| 8760 | ||
| 8761 | または | |
| 8762 | ||
| 8763 | open(FH, ">>&=OLDFH") | |
| 8764 | ||
| 8765 | =begin original | |
| 8766 | ||
| 8767 | 10411 | Being parsimonious on filehandles is also useful (besides being |
| 8768 | 10412 | parsimonious) for example when something is dependent on file |
| 8769 | descriptors, like for example locking using | |
| 10413 | descriptors, like for example locking using | |
| 8770 | C< | |
| 10414 | L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just | |
| 8771 | ||
| 10415 | C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the | |
| 8772 | ||
| 10416 | same file descriptor as C<$B>, and therefore C<flock($A)> will not | |
| 8773 | ||
| 10417 | C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>, | |
| 10418 | the filehandles will share the same underlying system file descriptor. | |
| 8774 | 10419 | |
| 8775 | 10420 | =end original |
| 8776 | 10421 | |
| 8777 | 10422 | ファイルハンドルを倹約することは、(倹約できること以外に)何かが |
| 8778 | ファイル記述子に依存している場合、例えば | |
| 10423 | ファイル記述子に依存している場合、例えば | |
| 10424 | L<C<flock>|/flock FILEHANDLE,OPERATION> を使った | |
| 8779 | 10425 | ファイルロックといった場合に有用です。 |
| 8780 | C<< open(A, ">>& | |
| 10426 | C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ | |
| 8781 | ファイル記述子にはならないので、flock(A) と flock(B) は別々になります。 | |
| 10427 | ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。 | |
| 8782 | しかし C<< open(A, ">>&= | |
| 10428 | しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの | |
| 8783 | 10429 | 同じファイル記述子を共有します。 |
| 8784 | 10430 | |
| 8785 | 10431 | =begin original |
| 8786 | 10432 | |
| 8787 | 10433 | Note that under Perls older than 5.8.0, Perl uses the standard C library's' |
| 8788 | fdopen() to implement the C<=> functionality. On many Unix systems, | |
| 10434 | L<fdopen(3)> to implement the C<=> functionality. On many Unix systems, | |
| 8789 | fdopen() fails when file descriptors exceed a certain value, typically 255. | |
| 10435 | L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255. | |
| 8790 | 10436 | For Perls 5.8.0 and later, PerlIO is (most often) the default. |
| 8791 | 10437 | |
| 8792 | 10438 | =end original |
| 8793 | 10439 | |
| 8794 | 10440 | 5.8.0 より前の Perl の場合、C<=> 機能の実装は |
| 8795 | 標準 C ライブラリの fdopen() を使っています。 | |
| 10441 | 標準 C ライブラリの L<fdopen(3)> を使っています。 | |
| 8796 | 多くの Unix システムでは、fdopen() はファイル記述子がある値 | |
| 10442 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値 | |
| 8797 | 10443 | (典型的には 255)を超えた場合に失敗することが知られています。 |
| 8798 | 5.8.0 以降の Perl では、(ほ | |
| 10444 | 5.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。 | |
| 8799 | 10445 | |
| 10446 | =item Legacy usage | |
| 10447 | ||
| 10448 | (古い使い方) | |
| 10449 | ||
| 8800 | 10450 | =begin original |
| 8801 | 10451 | |
| 8802 | ||
| 10452 | This section describes ways to call C<open> outside of best practices; | |
| 8803 | a | |
| 10453 | you may encounter these uses in older code. Perl does not consider their | |
| 8804 | ||
| 10454 | use deprecated, exactly, but neither is it recommended in new code, for | |
| 10455 | the sake of clarity and readability. | |
| 8805 | 10456 | |
| 8806 | 10457 | =end original |
| 8807 | 10458 | |
| 8808 | ||
| 10459 | この節では、ベストプラクティスではない C<open> の呼び出し方について | |
| 8809 | ||
| 10460 | 記述します; より古いコードでこれらが使われているのに遭遇するかもしれません。 | |
| 8810 | ||
| 10461 | 厳密には、Perl はこれらの仕様を廃止予定にはしていませんが、 | |
| 8811 | ||
| 10462 | 明瞭性と可読性のために、新しいコードには薦めません。 | |
| 8812 | 10463 | |
| 10464 | =over | |
| 10465 | ||
| 10466 | =item Specifying mode and filename as a single argument | |
| 10467 | ||
| 10468 | (モードとファイル名を一つの引数で指定する) | |
| 10469 | ||
| 8813 | 10470 | =begin original |
| 8814 | 10471 | |
| 8815 | I | |
| 10472 | In the one- and two-argument forms of the call, the mode and filename | |
| 8816 | ||
| 10473 | should be concatenated (in that order), preferably separated by white | |
| 8817 | ||
| 10474 | space. You can--but shouldn't--omit the mode in these forms when that mode | |
| 8818 | ||
| 10475 | is C<< < >>. It is safe to use the two-argument form of | |
| 8819 | o | |
| 10476 | L<C<open>|/open FILEHANDLE,MODE,EXPR> if the filename argument is a known literal. | |
| 8820 | Use C<defined($pid)> or C<//> to determine whether the open was successful. | |
| 8821 | 10477 | |
| 8822 | 10478 | =end original |
| 8823 | 10479 | |
| 8824 | 1 引数 | |
| 10480 | 1 引数 と 2 引数の形式ではモードとファイル名は(この順番で) | |
| 8825 | ||
| 10481 | 結合されます(空白によって分割されているかもしれません)。 | |
| 8826 | C< | |
| 10482 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 | |
| 8827 | ||
| 10483 | するべきではありません)。 | |
| 8828 | ||
| 10484 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
| 8829 | open | |
| 10485 | L<C<open>|/open FILEHANDLE,MODE,EXPR> は安全です。 | |
| 8830 | 使います。 | |
| 8831 | 10486 | |
| 10487 | open(my $dbase, "+<dbase.mine") # ditto | |
| 10488 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 10489 | ||
| 8832 | 10490 | =begin original |
| 8833 | 10491 | |
| 8834 | ||
| 10492 | In the two-argument (and one-argument) form, opening C<< <- >> | |
| 10493 | or C<-> opens STDIN and opening C<< >- >> opens STDOUT. | |
| 8835 | 10494 | |
| 8836 | 10495 | =end original |
| 8837 | 10496 | |
| 8838 | ||
| 10497 | 2 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が | |
| 10498 | オープンされ、C<< >- >> を open すると STDOUT がオープンされます。 | |
| 8839 | 10499 | |
| 8840 | $child_pid = open(FROM_KID, "-|") // die "can't fork: $!"; | |
| 8841 | ||
| 8842 | 10500 | =begin original |
| 8843 | 10501 | |
| 8844 | or | |
| 10502 | New code should favor the three-argument form of C<open> over this older | |
| 10503 | form. Declaring the mode and the filename as two distinct arguments | |
| 10504 | avoids any confusion between the two. | |
| 8845 | 10505 | |
| 8846 | 10506 | =end original |
| 8847 | 10507 | |
| 8848 | ||
| 10508 | 新しいコードでは、このより古い形式ではなく、3 引数形式の C<open> を | |
| 10509 | 使うべきです。 | |
| 10510 | モードとファイル名を異なった二つの引数として指定することで、 | |
| 10511 | 二つの間の混乱を避けられます。 | |
| 8849 | 10512 | |
| 8850 | ||
| 10513 | =item Calling C<open> with one argument via global variables | |
| 8851 | 10514 | |
| 10515 | (グローバル変数を使って C<open> を 1 引数で呼び出す) | |
| 10516 | ||
| 8852 | 10517 | =begin original |
| 8853 | 10518 | |
| 8854 | ||
| 10519 | As a shortcut, a one-argument call takes the filename from the global | |
| 10520 | scalar variable of the same name as the filehandle: | |
| 8855 | 10521 | |
| 8856 | 10522 | =end original |
| 8857 | 10523 | |
| 8858 | ||
| 10524 | 短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の | |
| 10525 | グローバルなスカラ変数から取ります: | |
| 8859 | 10526 | |
| 8860 | | |
| 10527 | $ARTICLE = 100; | |
| 8861 | ||
| 10528 | open(ARTICLE) | |
| 8862 | ||
| 10529 | or die "Can't find article $ARTICLE: $!\n"; | |
| 8863 | ... | |
| 8864 | waitpid $child_pid, 0; | |
| 8865 | } else { | |
| 8866 | # am the child; use STDIN/STDOUT normally | |
| 8867 | ... | |
| 8868 | exit; | |
| 8869 | } | |
| 8870 | 10530 | |
| 8871 | 10531 | =begin original |
| 8872 | 10532 | |
| 8873 | T | |
| 10533 | Here C<$ARTICLE> must be a global (package) scalar variable - not one | |
| 8874 | ||
| 10534 | declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>. | |
| 8875 | In the child process, the filehandle isn't opened--I/O happens from/to | |
| 8876 | the new STDOUT/STDIN. Typically this is used like the normal | |
| 8877 | piped open when you want to exercise more control over just how the | |
| 8878 | pipe command gets executed, such as when running setuid and | |
| 8879 | you don't want to have to scan shell commands for metacharacters. | |
| 8880 | 10535 | |
| 8881 | 10536 | =end original |
| 8882 | 10537 | |
| 8883 | ||
| 10538 | ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません - | |
| 8884 | ||
| 10539 | L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された | |
| 8885 | ||
| 10540 | 変数ではありません。 | |
| 8886 | チャイルドプロセス側では、そのファイルハンドルは | |
| 8887 | オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。 | |
| 8888 | これは、setuid で実行して、シェルコマンドのメタ文字を | |
| 8889 | 検索させたくないような場合に、パイプコマンドの起動の仕方を | |
| 8890 | 制御したいとき、普通のパイプの open と同じように使います。 | |
| 8891 | 10541 | |
| 10542 | =item Assigning a filehandle to a bareword | |
| 10543 | ||
| 10544 | (ファイルハンドルを裸の単語に代入する) | |
| 10545 | ||
| 8892 | 10546 | =begin original |
| 8893 | 10547 | |
| 8894 | ||
| 10548 | An older style is to use a bareword as the filehandle, as | |
| 8895 | 10549 | |
| 8896 | 10550 | =end original |
| 8897 | 10551 | |
| 8898 | ||
| 10552 | より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います | |
| 8899 | 10553 | |
| 8900 | open(F | |
| 10554 | open(FH, "<", "input.txt") | |
| 8901 | open | |
| 10555 | or die "Can't open < input.txt: $!"; | |
| 8902 | open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]'; | |
| 8903 | open(FOO, "|-", "tr", '[a-z]', '[A-Z]'); | |
| 8904 | 10556 | |
| 8905 | open(FOO, "cat -n '$file'|"); | |
| 8906 | open(FOO, "-|", "cat -n '$file'"); | |
| 8907 | open(FOO, "-|") || exec "cat", "-n", $file; | |
| 8908 | open(FOO, "-|", "cat", "-n", $file); | |
| 8909 | ||
| 8910 | 10557 | =begin original |
| 8911 | 10558 | |
| 8912 | The | |
| 10559 | Then you can use C<FH> as the filehandle, in C<< close FH >> and C<< | |
| 8913 | ||
| 10560 | <FH> >> and so on. Note that it's a global variable, so this form is | |
| 8914 | ||
| 10561 | not recommended when dealing with filehandles other than Perl's built-in ones | |
| 8915 | U | |
| 10562 | (e.g. STDOUT and STDIN). In fact, using a bareword for the filehandle is | |
| 8916 | ||
| 10563 | an error when the C<bareword_filehandles> feature has been disabled. This | |
| 8917 | ||
| 10564 | feature is disabled by default when in the scope of C<use v5.36.0> or later. | |
| 8918 | in them. However, this also bars you from opening pipes to commands | |
| 8919 | that intentionally contain shell metacharacters, such as: | |
| 8920 | 10565 | |
| 8921 | 10566 | =end original |
| 8922 | 10567 | |
| 8923 | それ | |
| 10568 | それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、 | |
| 8924 | ||
| 10569 | ファイルハンドルとして使えます。 | |
| 8925 | ||
| 10570 | これはグローバル変数なので、Perl の組み込みのもの (例えば STDOUT と STDIN) | |
| 8926 | あ | |
| 10571 | 以外では非推奨であることに注意してください。 | |
| 8927 | ||
| 10572 | 実際、C<bareword_filehandles> 機能が無効になっている場合は | |
| 8928 | ||
| 10573 | ファイルハンドルに裸の単語を使うことはエラーです。 | |
| 8929 | ||
| 10574 | この機能は、C<use v5.36.0> 以降のスコープ内ではデフォルトでは | |
| 8930 | ||
| 10575 | 無効になっています。 | |
| 8931 | 開くことを妨げます: | |
| 8932 | 10576 | |
| 8933 | ||
| 10577 | =back | |
| 8934 | // die "Can't open pipeline to lpr: $!"; | |
| 8935 | 10578 | |
| 10579 | =item Other considerations | |
| 10580 | ||
| 10581 | (その他の考慮点) | |
| 10582 | ||
| 10583 | =over | |
| 10584 | ||
| 10585 | =item Automatic filehandle closure | |
| 10586 | ||
| 10587 | (自動的にファイルハンドルを閉じる) | |
| 10588 | ||
| 8936 | 10589 | =begin original |
| 8937 | 10590 | |
| 8938 | ||
| 10591 | The filehandle will be closed when its reference count reaches zero. If | |
| 10592 | it is a lexically scoped variable declared with L<C<my>|/my VARLIST>, | |
| 10593 | that usually means the end of the enclosing scope. However, this | |
| 10594 | automatic close does not check for errors, so it is better to explicitly | |
| 10595 | close filehandles, especially those used for writing: | |
| 8939 | 10596 | |
| 8940 | 10597 | =end original |
| 8941 | 10598 | |
| 8942 | ||
| 10599 | ファイルハンドルは、参照カウントが 0 になったときに閉じられます。 | |
| 8943 | ||
| 10600 | これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、 | |
| 10601 | 普通は囲まれたスコープの終わりを意味します。 | |
| 10602 | しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、 | |
| 10603 | 明示的にファイルハンドルを閉じる方がよいです。 | |
| 8944 | 10604 | |
| 10605 | close($handle) | |
| 10606 | || warn "close failed: $!"; | |
| 10607 | ||
| 10608 | =item Automatic pipe flushing | |
| 10609 | ||
| 10610 | (パイプの自動フラッシュ) | |
| 10611 | ||
| 8945 | 10612 | =begin original |
| 8946 | 10613 | |
| 8947 | 10614 | Perl will attempt to flush all files opened for |
| 8948 | 10615 | output before any operation that may do a fork, but this may not be |
| 8949 | 10616 | supported on some platforms (see L<perlport>). To be safe, you may need |
| 8950 | to set C<$|> ($AUTOFLUSH in English | |
| 10617 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) | |
| 8951 | of C<IO::Handle> | |
| 10618 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> | |
| 10619 | on any open handles. | |
| 8952 | 10620 | |
| 8953 | 10621 | =end original |
| 8954 | 10622 | |
| 8955 | ||
| 10623 | Perl は書き込み用に開いている全てのファイルに対して | |
| 8956 | 10624 | fork を行う前にフラッシュしようとしますが、これに対応していない |
| 8957 | 10625 | プラットフォームもあります(L<perlport> を参照してください)。 |
| 8958 | 安全のために、C<$|> (English モジュールでは | |
| 10626 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは | |
| 8959 | 全ての開いているハンドルに対して | |
| 10627 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して | |
| 10628 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを | |
| 8960 | 10629 | 呼び出す必要があるかもしれません。 |
| 8961 | 10630 | |
| 8962 | 10631 | =begin original |
| 8963 | 10632 | |
| 8964 | 10633 | On systems that support a close-on-exec flag on files, the flag will |
| 8965 | 10634 | be set for the newly opened file descriptor as determined by the value |
| 8966 | of C<$^F>. See L<perlvar/$^F>. | |
| 10635 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
| 8967 | 10636 | |
| 8968 | 10637 | =end original |
| 8969 | 10638 | |
| 8970 | 10639 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 8971 | フラグは C<$^F> の値で決定される、新しくオープンされた | |
| 10640 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
| 8972 | セットされます。 | |
| 10641 | ファイル記述子に対してセットされます。 | |
| 8973 | 10642 | L<perlvar/$^F> を参照してください。 |
| 8974 | 10643 | |
| 8975 | 10644 | =begin original |
| 8976 | 10645 | |
| 8977 | 10646 | Closing any piped filehandle causes the parent process to wait for the |
| 8978 | child to finish, then returns the status value in C<$?> and | |
| 10647 | child to finish, then returns the status value in L<C<$?>|perlvar/$?> and | |
| 8979 | C<${^CHILD_ERROR_NATIVE}>. | |
| 10648 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 8980 | 10649 | |
| 8981 | 10650 | =end original |
| 8982 | 10651 | |
| 8983 | パイプのファイルハンドルを close することで、 | |
| 10652 | パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を | |
| 8984 | ||
| 10653 | 待ち、それから L<C<$?>|perlvar/$?> と | |
| 8985 | C<${^CHILD_ERROR_NATIVE}> にステータス値を | |
| 10654 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を | |
| 10655 | 返します。 | |
| 8986 | 10656 | |
| 10657 | =item Direct versus by-reference assignment of filehandles | |
| 10658 | ||
| 10659 | (ファイルハンドルの直接代入とリファレンスによる代入) | |
| 10660 | ||
| 8987 | 10661 | =begin original |
| 8988 | 10662 | |
| 8989 | ||
| 10663 | If FILEHANDLE -- the first argument in a call to C<open> -- is an | |
| 10664 | undefined scalar variable (or array or hash element), a new filehandle | |
| 10665 | is autovivified, meaning that the variable is assigned a reference to a | |
| 10666 | newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an | |
| 10667 | expression, its value is the real filehandle. (This is considered a | |
| 10668 | symbolic reference, so C<use strict "refs"> should I<not> be in effect.) | |
| 10669 | ||
| 10670 | =end original | |
| 10671 | ||
| 10672 | FILEHANDLE (C<open> を呼び出すときの最初の引数) が未定義のスカラ変数 | |
| 10673 | (または配列かハッシュの要素)の場合、 | |
| 10674 | 新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた | |
| 10675 | 無名ファイルハンドルへのリファレンスが代入されます。 | |
| 10676 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の | |
| 10677 | ファイルハンドルの名前として使います。 | |
| 10678 | (これはシンボリックリファレンスとして扱われるので、 | |
| 10679 | C<use strict "refs"> の影響を I<受けません>。) | |
| 10680 | ||
| 10681 | =item Whitespace and special characters in the filename argument | |
| 10682 | ||
| 10683 | (ファイル名引数の空白と特殊文字) | |
| 10684 | ||
| 10685 | =begin original | |
| 10686 | ||
| 10687 | The filename passed to the one- and two-argument forms of | |
| 10688 | L<C<open>|/open FILEHANDLE,MODE,EXPR> will | |
| 8990 | 10689 | have leading and trailing whitespace deleted and normal |
| 8991 | 10690 | redirection characters honored. This property, known as "magic open", |
| 8992 | 10691 | can often be used to good effect. A user could specify a filename of |
| 8993 | 10692 | F<"rsh cat file |">, or you could change certain filenames as needed: |
| 8994 | 10693 | |
| 8995 | 10694 | =end original |
| 8996 | 10695 | |
| 8997 | 1 引数 と 2 引数の形の open | |
| 10696 | 1 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR> に渡された | |
| 8998 | はじめと終わりの空白が取り除かれ、 | |
| 10697 | ファイル名は、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を | |
| 8999 | ||
| 10698 | 受け付けます。 | |
| 9000 | この機能は "magic open" として知られていますが、 | |
| 10699 | この機能は "magic open" として知られていますが、普通いい効果をもたらします。 | |
| 9001 | 普通いい効果をもたらします。 | |
| 9002 | 10700 | ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、 |
| 9003 | 10701 | 特定のファイル名を必要に応じて変更できます。 |
| 9004 | 10702 | |
| 9005 | 10703 | $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/; |
| 9006 | open( | |
| 10704 | open(my $fh, $filename) | |
| 10705 | or die "Can't open $filename: $!"; | |
| 9007 | 10706 | |
| 9008 | 10707 | =begin original |
| 9009 | 10708 | |
| 9010 | 10709 | Use the three-argument form to open a file with arbitrary weird characters in it, |
| 9011 | 10710 | |
| 9012 | 10711 | =end original |
| 9013 | 10712 | |
| 9014 | 10713 | 妙な文字が含まれているようなファイル名をオープンするには、 |
| 9015 | 10714 | 3 引数の形を使います。 |
| 9016 | 10715 | |
| 9017 | open( | |
| 10716 | open(my $fh, "<", $file) | |
| 9018 | || die " | |
| 10717 | || die "Can't open $file: $!"; | |
| 9019 | 10718 | |
| 9020 | 10719 | =begin original |
| 9021 | 10720 | |
| 9022 | 10721 | otherwise it's necessary to protect any leading and trailing whitespace: |
| 9023 | 10722 | |
| 9024 | 10723 | =end original |
| 9025 | 10724 | |
| 9026 | 10725 | あるいは、次のようにして、最初と最後の空白を保護します: |
| 9027 | 10726 | |
| 9028 | 10727 | $file =~ s#^(\s)#./$1#; |
| 9029 | open( | |
| 10728 | open(my $fh, "< $file\0") | |
| 9030 | || die "open f | |
| 10729 | || die "Can't open $file: $!"; | |
| 9031 | 10730 | |
| 9032 | 10731 | =begin original |
| 9033 | 10732 | |
| 9034 | 10733 | (this may not work on some bizarre filesystems). One should |
| 9035 | 10734 | conscientiously choose between the I<magic> and I<three-argument> form |
| 9036 | of open | |
| 10735 | of L<C<open>|/open FILEHANDLE,MODE,EXPR>: | |
| 9037 | 10736 | |
| 9038 | 10737 | =end original |
| 9039 | 10738 | |
| 9040 | 10739 | (これは奇妙なファイルシステムでは動作しないかもしれません)。 |
| 9041 | open | |
| 10740 | L<C<open>|/open FILEHANDLE,MODE,EXPR> の I<magic> と I<3 引数> 形式を誠実に | |
| 10741 | 選択するべきです。 | |
| 9042 | 10742 | |
| 9043 | open( | |
| 10743 | open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!"; | |
| 9044 | 10744 | |
| 9045 | 10745 | =begin original |
| 9046 | 10746 | |
| 9047 | 10747 | will allow the user to specify an argument of the form C<"rsh cat file |">, |
| 9048 | 10748 | but will not work on a filename that happens to have a trailing space, while |
| 9049 | 10749 | |
| 9050 | 10750 | =end original |
| 9051 | 10751 | |
| 9052 | 10752 | とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、 |
| 9053 | 10753 | 末尾にスペースがついてしまったファイル名では動作しません; 一方: |
| 9054 | 10754 | |
| 9055 | open( | |
| 10755 | open(my $in, "<", $ARGV[0]) | |
| 9056 | || die " | |
| 10756 | || die "Can't open $ARGV[0]: $!"; | |
| 9057 | 10757 | |
| 9058 | 10758 | =begin original |
| 9059 | 10759 | |
| 9060 | will have exactly the opposite restrictions. | |
| 10760 | will have exactly the opposite restrictions. (However, some shells | |
| 10761 | support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which | |
| 10762 | produces a filename that can be opened normally.) | |
| 9061 | 10763 | |
| 9062 | 10764 | =end original |
| 9063 | 10765 | |
| 9064 | 10766 | はまったく逆の制限があります。 |
| 10767 | (しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という | |
| 10768 | 文法に対応していて、普通に開くことが出来るファイル名を出力します。) | |
| 9065 | 10769 | |
| 10770 | =item Invoking C-style C<open> | |
| 10771 | ||
| 10772 | (C 形式の C<open> の起動) | |
| 10773 | ||
| 9066 | 10774 | =begin original |
| 9067 | 10775 | |
| 9068 | If you want a "real" C | |
| 10776 | If you want a "real" C L<open(2)>, then you should use the | |
| 9069 | s | |
| 10777 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves | |
| 9070 | ||
| 10778 | no such magic (but uses different filemodes than Perl | |
| 9071 | ||
| 10779 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, which corresponds to C L<fopen(3)>). | |
| 9072 | interpretation. For | |
| 10780 | This is another way to protect your filenames from interpretation. For | |
| 10781 | example: | |
| 9073 | 10782 | |
| 9074 | 10783 | =end original |
| 9075 | 10784 | |
| 9076 | もし「本当の」C 言語の | |
| 10785 | もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない | |
| 9077 | ||
| 10786 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです | |
| 9078 | (ただし、C の fopen() に | |
| 10787 | (ただし、C の L<fopen(3)> に対応する Perl の | |
| 9079 | ||
| 10788 | L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違うファイルモードを持ちます)。 | |
| 9080 | 10789 | これはファイル名を解釈から守るもう一つの方法です。 |
| 9081 | 10790 | 例えば: |
| 9082 | 10791 | |
| 9083 | 10792 | use IO::Handle; |
| 9084 | sysopen( | |
| 10793 | sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL) | |
| 9085 | or die " | |
| 10794 | or die "Can't open $path: $!"; | |
| 9086 | $ | |
| 10795 | $fh->autoflush(1); | |
| 9087 | print | |
| 10796 | print $fh "stuff $$\n"; | |
| 9088 | seek( | |
| 10797 | seek($fh, 0, 0); | |
| 9089 | print "File contains: ", | |
| 10798 | print "File contains: ", readline($fh); | |
| 9090 | 10799 | |
| 9091 | 10800 | =begin original |
| 9092 | 10801 | |
| 9093 | ||
| 10802 | See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about | |
| 9094 | ||
| 10803 | mixing reading and writing. | |
| 9095 | filehandles that have the scope of the variables used to hold them, then | |
| 9096 | automatically (but silently) close once their reference counts become | |
| 9097 | zero, typically at scope exit: | |
| 9098 | 10804 | |
| 9099 | 10805 | =end original |
| 9100 | 10806 | |
| 9101 | ||
| 10807 | 読み書きを混ぜる場合の詳細については | |
| 9102 | ||
| 10808 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> を参照してください。 | |
| 9103 | これらへのリファレンスを保持している変数のスコープを持ち、それから | |
| 9104 | 参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる | |
| 9105 | 無名ファイルハンドルを作成できます: | |
| 9106 | 10809 | |
| 9107 | ||
| 10810 | =item Portability issues | |
| 9108 | #... | |
| 9109 | sub read_myfile_munged { | |
| 9110 | my $ALL = shift; | |
| 9111 | # or just leave it undef to autoviv | |
| 9112 | my $handle = IO::File->new; | |
| 9113 | open($handle, "<", "myfile") or die "myfile: $!"; | |
| 9114 | $first = <$handle> | |
| 9115 | or return (); # Automatically closed here. | |
| 9116 | mung($first) or die "mung failed"; # Or here. | |
| 9117 | return (first, <$handle>) if $ALL; # Or here. | |
| 9118 | return $first; # Or here. | |
| 9119 | } | |
| 9120 | 10811 | |
| 9121 | ||
| 10812 | (移植性の問題) | |
| 9122 | 10813 | |
| 9123 | B<WARNING:> The previous example has a bug because the automatic | |
| 9124 | close that happens when the refcount on C<handle> reaches zero does not | |
| 9125 | properly detect and report failures. I<Always> close the handle | |
| 9126 | yourself and inspect the return value. | |
| 9127 | ||
| 9128 | =end original | |
| 9129 | ||
| 9130 | B<警告:> 先の例には、自動的に閉じると、C<handle> の参照カウントが | |
| 9131 | 0 になったことが適切に検出できなくて失敗が報告されるというバグがあります。 | |
| 9132 | I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。 | |
| 9133 | ||
| 9134 | close($handle) | |
| 9135 | || warn "close failed: $!"; | |
| 9136 | ||
| 9137 | 10814 | =begin original |
| 9138 | 10815 | |
| 9139 | See L< | |
| 10816 | See L<perlport/open>. | |
| 9140 | 10817 | |
| 9141 | 10818 | =end original |
| 9142 | 10819 | |
| 9143 | ||
| 10820 | L<perlport/open> を参照してください。 | |
| 9144 | 10821 | |
| 9145 | =b | |
| 10822 | =back | |
| 9146 | 10823 | |
| 9147 | ||
| 10824 | =back | |
| 9148 | 10825 | |
| 9149 | =end original | |
| 9150 | ||
| 9151 | 移植性の問題: L<perlport/open>。 | |
| 9152 | ||
| 9153 | 10826 | =item opendir DIRHANDLE,EXPR |
| 9154 | 10827 | X<opendir> |
| 9155 | 10828 | |
| 9156 | 10829 | =for Pod::Functions open a directory |
| 9157 | 10830 | |
| 9158 | 10831 | =begin original |
| 9159 | 10832 | |
| 9160 | Opens a directory named EXPR for processing by | |
| 10833 | Opens a directory named EXPR for processing by | |
| 9161 | C< | |
| 10834 | L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>, | |
| 10835 | L<C<seekdir>|/seekdir DIRHANDLE,POS>, | |
| 10836 | L<C<rewinddir>|/rewinddir DIRHANDLE>, and | |
| 10837 | L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful. | |
| 9162 | 10838 | DIRHANDLE may be an expression whose value can be used as an indirect |
| 9163 | 10839 | dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined |
| 9164 | 10840 | scalar variable (or array or hash element), the variable is assigned a |
| 9165 | 10841 | reference to a new anonymous dirhandle; that is, it's autovivified. |
| 9166 | D | |
| 10842 | Dirhandles are the same objects as filehandles; an I/O object can only | |
| 10843 | be open as one of these handle types at once. | |
| 9167 | 10844 | |
| 9168 | 10845 | =end original |
| 9169 | 10846 | |
| 9170 | C<readdir> | |
| 10847 | L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、 | |
| 9171 | ||
| 10848 | L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、 | |
| 10849 | L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の | |
| 10850 | ディレクトリをオープンします。 | |
| 9172 | 10851 | 成功時には真を返します。 |
| 9173 | 10852 | DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ |
| 9174 | 10853 | ハンドルの名前)となる式でも構いません。 |
| 9175 | 10854 | DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は |
| 9176 | 10855 | 新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、 |
| 9177 | 10856 | 自動有効化されます。 |
| 9178 | ||
| 10857 | ディレクトリハンドルはファイルハンドルと同じオブジェクトです; | |
| 10858 | 一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ | |
| 10859 | 開くことができます。 | |
| 9179 | 10860 | |
| 9180 | 10861 | =begin original |
| 9181 | 10862 | |
| 9182 | See the example at C<readdir>. | |
| 10863 | See the example at L<C<readdir>|/readdir DIRHANDLE>. | |
| 9183 | 10864 | |
| 9184 | 10865 | =end original |
| 9185 | 10866 | |
| 9186 | C<readdir> の例を参照してください。 | |
| 10867 | L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。 | |
| 9187 | 10868 | |
| 9188 | 10869 | =item ord EXPR |
| 9189 | 10870 | X<ord> X<encoding> |
| 9190 | 10871 | |
| 9191 | 10872 | =item ord |
| 9192 | 10873 | |
| 9193 | 10874 | =for Pod::Functions find a character's numeric representation |
| 9194 | 10875 | |
| 9195 | 10876 | =begin original |
| 9196 | 10877 | |
| 9197 | 10878 | Returns the numeric value of the first character of EXPR. |
| 9198 | If EXPR is an empty string, returns 0. If EXPR is omitted, uses | |
| 10879 | If EXPR is an empty string, returns 0. If EXPR is omitted, uses | |
| 10880 | L<C<$_>|perlvar/$_>. | |
| 9199 | 10881 | (Note I<character>, not byte.) |
| 9200 | 10882 | |
| 9201 | 10883 | =end original |
| 9202 | 10884 | |
| 9203 | 10885 | EXPR の最初の文字の数値としての値を返します。 |
| 9204 | 10886 | EXPR が空文字列の場合は、0 を返します。 |
| 9205 | EXPR が省略されると、C<$_> を使います。 | |
| 10887 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 9206 | 10888 | (バイトではなく I<文字> であることに注意してください。) |
| 9207 | 10889 | |
| 9208 | 10890 | =begin original |
| 9209 | 10891 | |
| 9210 | For the reverse, see L</chr>. | |
| 10892 | For the reverse, see L<C<chr>|/chr NUMBER>. | |
| 9211 | 10893 | See L<perlunicode> for more about Unicode. |
| 9212 | 10894 | |
| 9213 | 10895 | =end original |
| 9214 | 10896 | |
| 9215 | 逆のことをするには L</chr> を参照してください。 | |
| 10897 | 逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。 | |
| 9216 | 10898 | Unicode については L<perlunicode> を参照してください。 |
| 9217 | 10899 | |
| 9218 | =item our | |
| 10900 | =item our VARLIST | |
| 9219 | 10901 | X<our> X<global> |
| 9220 | 10902 | |
| 9221 | =item our TYPE | |
| 10903 | =item our TYPE VARLIST | |
| 9222 | 10904 | |
| 9223 | =item our | |
| 10905 | =item our VARLIST : ATTRS | |
| 9224 | 10906 | |
| 9225 | =item our TYPE | |
| 10907 | =item our TYPE VARLIST : ATTRS | |
| 9226 | 10908 | |
| 9227 | 10909 | =for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping) |
| 9228 | 10910 | |
| 9229 | 10911 | =begin original |
| 9230 | 10912 | |
| 9231 | C<our> makes a lexical alias to a package | |
| 10913 | L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global) | |
| 9232 | ||
| 10914 | variable of the same name in the current package for use within the | |
| 10915 | current lexical scope. | |
| 9233 | 10916 | |
| 9234 | 10917 | =end original |
| 9235 | 10918 | |
| 9236 | C<our> は単純名を、現在のレキシカルスコープ内で使うために、 | |
| 10919 | L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、 | |
| 9237 | 同じ名前のパッケージ変数への | |
| 10920 | 現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への | |
| 10921 | レキシカルな別名を作ります。 | |
| 9238 | 10922 | |
| 9239 | 10923 | =begin original |
| 9240 | 10924 | |
| 9241 | C<our> has the same scoping rules as | |
| 10925 | L<C<our>|/our VARLIST> has the same scoping rules as | |
| 9242 | ||
| 10926 | L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is | |
| 9243 | ||
| 10927 | only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and | |
| 10928 | L<C<state>|/state VARLIST>, which both declare new (lexical) variables, | |
| 10929 | L<C<our>|/our VARLIST> only creates an alias to an existing variable: a | |
| 10930 | package variable of the same name. | |
| 9244 | 10931 | |
| 9245 | 10932 | =end original |
| 9246 | 10933 | |
| 9247 | C<our> は C<my> | |
| 10934 | L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や | |
| 9248 | ||
| 10935 | L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり | |
| 9249 | ||
| 10936 | レキシカルスコープの中でだけ有効です。 | |
| 10937 | 新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や | |
| 10938 | L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に | |
| 10939 | 存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。 | |
| 9250 | 10940 | |
| 9251 | 10941 | =begin original |
| 9252 | 10942 | |
| 9253 | This means that when C<use strict 'vars'> is in effect, C<our> | |
| 10943 | This means that when C<use strict 'vars'> is in effect, L<C<our>|/our | |
| 9254 | a package variable without qualifying it with the | |
| 10944 | VARLIST> lets you use a package variable without qualifying it with the | |
| 9255 | the lexical scope of the | |
| 10945 | package name, but only within the lexical scope of the | |
| 9256 | C<u | |
| 10946 | L<C<our>|/our VARLIST> declaration. This applies immediately--even | |
| 9257 | ||
| 10947 | within the same statement. | |
| 9258 | 10948 | |
| 9259 | 10949 | =end original |
| 9260 | 10950 | |
| 9261 | つまり、C<use strict 'vars'> が有効の場合は、C<our> を | |
| 10951 | つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を | |
| 10952 | 使うことで、 | |
| 9262 | 10953 | パッケージ変数をパッケージ名で修飾することなく使うことができますが、 |
| 9263 | C<our> 宣言のレキシカルスコープ内だけということです。 | |
| 10954 | L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。 | |
| 9264 | こ | |
| 10955 | これは(たとえ同じ文の中でも)直ちに適用されます。 | |
| 9265 | これは影響するパッケージの中で I<のみ> 非修飾名を使え、スコープを超えることは | |
| 9266 | できません。 | |
| 9267 | 10956 | |
| 10957 | package Foo; | |
| 10958 | use v5.36; # which implies "use strict;" | |
| 10959 | ||
| 10960 | $Foo::foo = 23; | |
| 10961 | ||
| 10962 | { | |
| 10963 | our $foo; # alias to $Foo::foo | |
| 10964 | print $foo; # prints 23 | |
| 10965 | } | |
| 10966 | ||
| 10967 | print $Foo::foo; # prints 23 | |
| 10968 | ||
| 10969 | print $foo; # ERROR: requires explicit package name | |
| 10970 | ||
| 9268 | 10971 | =begin original |
| 9269 | 10972 | |
| 9270 | ||
| 10973 | This works even if the package variable has not been used before, as | |
| 10974 | package variables spring into existence when first used. | |
| 10975 | ||
| 10976 | =end original | |
| 10977 | ||
| 10978 | これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、 | |
| 10979 | 最初に使われた時にひょっこり現れるからです。 | |
| 10980 | ||
| 10981 | package Foo; | |
| 10982 | use v5.36; | |
| 10983 | ||
| 10984 | our $foo = 23; # just like $Foo::foo = 23 | |
| 10985 | ||
| 10986 | print $Foo::foo; # prints 23 | |
| 10987 | ||
| 10988 | =begin original | |
| 10989 | ||
| 10990 | Because the variable becomes legal immediately under C<use strict 'vars'>, so | |
| 10991 | long as there is no variable with that name is already in scope, you can then | |
| 10992 | reference the package variable again even within the same statement. | |
| 10993 | ||
| 10994 | =end original | |
| 10995 | ||
| 10996 | 変数は C<use strict 'vars'> の基で直ちに正当になるので、 | |
| 10997 | スコープ内に同じ名前の変数がない限り、 | |
| 10998 | たとえ同じ文の中でもパッケージ変数を再び参照できます。 | |
| 10999 | ||
| 11000 | package Foo; | |
| 11001 | use v5.36; | |
| 11002 | ||
| 11003 | my $foo = $foo; # error, undeclared $foo on right-hand side | |
| 11004 | our $foo = $foo; # no errors | |
| 11005 | ||
| 11006 | =begin original | |
| 11007 | ||
| 11008 | If more than one variable is listed, the list must be placed | |
| 9271 | 11009 | in parentheses. |
| 9272 | 11010 | |
| 9273 | 11011 | =end original |
| 9274 | 11012 | |
| 9275 | 複数の | |
| 11013 | 複数の変数を指定する場合は、リストはかっこで囲まなければなりません。 | |
| 9276 | 11014 | |
| 9277 | our $foo; | |
| 9278 | 11015 | our($bar, $baz); |
| 9279 | 11016 | |
| 9280 | 11017 | =begin original |
| 9281 | 11018 | |
| 9282 | An C<our> declaration declares an alias for a packag | |
| 11019 | An L<C<our>|/our VARLIST> declaration declares an alias for a package | |
| 11020 | variable that will be visible | |
| 9283 | 11021 | across its entire lexical scope, even across package boundaries. The |
| 9284 | 11022 | package in which the variable is entered is determined at the point |
| 9285 | 11023 | of the declaration, not at the point of use. This means the following |
| 9286 | 11024 | behavior holds: |
| 9287 | 11025 | |
| 9288 | 11026 | =end original |
| 9289 | 11027 | |
| 9290 | C<our> 宣言はレキシカルスコープ全体に対して(たとえ | |
| 11028 | L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ | |
| 9291 | 越えていても)見える、パッケージ変数への別名を宣言します。 | |
| 11029 | パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。 | |
| 9292 | 11030 | この変数が入るパッケージは宣言した時点で定義され、 |
| 9293 | 11031 | 使用した時点ではありません。 |
| 9294 | 11032 | これにより、以下のような振る舞いになります: |
| 9295 | 11033 | |
| 9296 | 11034 | package Foo; |
| 9297 | 11035 | our $bar; # declares $Foo::bar for rest of lexical scope |
| 9298 | 11036 | $bar = 20; |
| 9299 | 11037 | |
| 9300 | 11038 | package Bar; |
| 9301 | 11039 | print $bar; # prints 20, as it refers to $Foo::bar |
| 9302 | 11040 | |
| 9303 | 11041 | =begin original |
| 9304 | 11042 | |
| 9305 | Multiple C<our> declarations with the same name in the | |
| 11043 | Multiple L<C<our>|/our VARLIST> declarations with the same name in the | |
| 11044 | same lexical | |
| 9306 | 11045 | scope are allowed if they are in different packages. If they happen |
| 9307 | 11046 | to be in the same package, Perl will emit warnings if you have asked |
| 9308 | for them, just like multiple C<my> declarations. Unlike | |
| 11047 | for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike | |
| 9309 | C<my> declaration, which will bind the name to | |
| 11048 | a second L<C<my>|/my VARLIST> declaration, which will bind the name to a | |
| 9310 | second C<our> declaration in the same | |
| 11049 | fresh variable, a second L<C<our>|/our VARLIST> declaration in the same | |
| 9311 | merely redundant. | |
| 11050 | package, in the same scope, is merely redundant. | |
| 9312 | 11051 | |
| 9313 | 11052 | =end original |
| 9314 | 11053 | |
| 9315 | 11054 | 同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の |
| 9316 | C<our> 宣言ができます。 | |
| 11055 | L<C<our>|/our VARLIST> 宣言ができます。 | |
| 9317 | 11056 | 同じパッケージになっていると、警告が出力されるようになっていれば |
| 9318 | 複数の C<my> 宣言がある場合と同じように警告が出力されます。 | |
| 11057 | 複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。 | |
| 9319 | 新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と | |
| 11058 | 新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と | |
| 9320 | 同じパッケージの同じスコープで 2 回 | |
| 11059 | 違って、同じパッケージの同じスコープで 2 回 | |
| 11060 | L<C<our>|/our VARLIST> 宣言するのは単に冗長です。 | |
| 9321 | 11061 | |
| 9322 | 11062 | use warnings; |
| 9323 | 11063 | package Foo; |
| 9324 | 11064 | our $bar; # declares $Foo::bar for rest of lexical scope |
| 9325 | 11065 | $bar = 20; |
| 9326 | 11066 | |
| 9327 | 11067 | package Bar; |
| 9328 | 11068 | our $bar = 30; # declares $Bar::bar for rest of lexical scope |
| 9329 | 11069 | print $bar; # prints 30 |
| 9330 | 11070 | |
| 9331 | 11071 | our $bar; # emits warning but has no other effect |
| 9332 | 11072 | print $bar; # still prints 30 |
| 9333 | 11073 | |
| 9334 | 11074 | =begin original |
| 9335 | 11075 | |
| 9336 | An C<our> declaration may also have a list of attributes | |
| 11076 | An L<C<our>|/our VARLIST> declaration may also have a list of attributes | |
| 9337 | with it. | |
| 11077 | associated with it. | |
| 9338 | 11078 | |
| 9339 | 11079 | =end original |
| 9340 | 11080 | |
| 9341 | C<our> 宣言には、それと結び付けられる属性のリストを | |
| 11081 | L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを | |
| 11082 | 持つこともあります。 | |
| 9342 | 11083 | |
| 9343 | 11084 | =begin original |
| 9344 | 11085 | |
| 9345 | 11086 | The exact semantics and interface of TYPE and ATTRS are still |
| 9346 | evolving. TYPE is currently bound to the use of the | |
| 11087 | evolving. TYPE is currently bound to the use of the L<fields> pragma, | |
| 9347 | and attributes are handled using the | |
| 11088 | and attributes are handled using the L<attributes> pragma, or, starting | |
| 9348 | from Perl 5.8.0, also via the | |
| 11089 | from Perl 5.8.0, also via the L<Attribute::Handlers> module. See | |
| 9349 | L<perlsub/"Private Variables via my()"> for details | |
| 11090 | L<perlsub/"Private Variables via my()"> for details. | |
| 9350 | L<attributes>, and L<Attribute::Handlers>. | |
| 9351 | 11091 | |
| 9352 | 11092 | =end original |
| 9353 | 11093 | |
| 9354 | 11094 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 |
| 9355 | 現在のところ、TYPE は | |
| 11095 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 | |
| 9356 | 属性は | |
| 11096 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
| 9357 | ||
| 11097 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
| 9358 | 詳しくはL<perlsub/"Private Variables via my()"> | |
| 11098 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
| 9359 | L<attributes>, L<Attribute::Handlers> を参照してください。 | |
| 9360 | 11099 | |
| 11100 | =begin original | |
| 11101 | ||
| 11102 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
| 11103 | as a dummy placeholder, for example to skip assignment of initial | |
| 11104 | values: | |
| 11105 | ||
| 11106 | =end original | |
| 11107 | ||
| 11108 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
| 11109 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
| 11110 | ||
| 11111 | our ( undef, $min, $hour ) = localtime; | |
| 11112 | ||
| 11113 | =begin original | |
| 11114 | ||
| 11115 | L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows | |
| 11116 | use of an unqualified name I<only> within the affected package, but | |
| 11117 | across scopes. | |
| 11118 | ||
| 11119 | =end original | |
| 11120 | ||
| 11121 | L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを | |
| 11122 | またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない | |
| 11123 | 名前を使えるようにします。 | |
| 11124 | ||
| 9361 | 11125 | =item pack TEMPLATE,LIST |
| 9362 | 11126 | X<pack> |
| 9363 | 11127 | |
| 9364 | 11128 | =for Pod::Functions convert a list into a binary representation |
| 9365 | 11129 | |
| 9366 | 11130 | =begin original |
| 9367 | 11131 | |
| 9368 | 11132 | Takes a LIST of values and converts it into a string using the rules |
| 9369 | 11133 | given by the TEMPLATE. The resulting string is the concatenation of |
| 9370 | 11134 | the converted values. Typically, each converted value looks |
| 9371 | 11135 | like its machine-level representation. For example, on 32-bit machines |
| 9372 | 11136 | an integer may be represented by a sequence of 4 bytes, which will in |
| 9373 | Perl be presented as a string that's 4 characters long. | |
| 11137 | Perl be presented as a string that's 4 characters long. | |
| 9374 | 11138 | |
| 9375 | 11139 | =end original |
| 9376 | 11140 | |
| 9377 | 11141 | LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。 |
| 9378 | 11142 | 結果の文字列は変換した値を連結したものです。 |
| 9379 | 11143 | 典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。 |
| 9380 | 11144 | 例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、 |
| 9381 | Perl では 4 文字の文字列で表現されます。 | |
| 11145 | Perl では 4 文字の文字列で表現されます。 | |
| 9382 | 11146 | |
| 9383 | 11147 | =begin original |
| 9384 | 11148 | |
| 9385 | 11149 | See L<perlpacktut> for an introduction to this function. |
| 9386 | 11150 | |
| 9387 | 11151 | =end original |
| 9388 | 11152 | |
| 9389 | 11153 | この関数の説明については L<perlpacktut> を参照してください。 |
| 9390 | 11154 | |
| 9391 | 11155 | =begin original |
| 9392 | 11156 | |
| 9393 | 11157 | The TEMPLATE is a sequence of characters that give the order and type |
| 9394 | 11158 | of values, as follows: |
| 9395 | 11159 | |
| 9396 | 11160 | =end original |
| 9397 | 11161 | |
| 9398 | 11162 | TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです: |
| 9399 | 11163 | |
| 9400 | 11164 | =begin original |
| 9401 | 11165 | |
| 9402 | 11166 | a A string with arbitrary binary data, will be null padded. |
| 9403 | 11167 | A A text (ASCII) string, will be space padded. |
| 9404 | 11168 | Z A null-terminated (ASCIZ) string, will be null padded. |
| 9405 | 11169 | |
| 9406 | 11170 | =end original |
| 9407 | 11171 | |
| 9408 | 11172 | a 任意のバイナリデータを含む文字列、ヌル文字で埋める。 |
| 9409 | 11173 | A テキスト (ASCII) 文字列、スペース文字で埋める。 |
| 9410 | 11174 | Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。 |
| 9411 | 11175 | |
| 9412 | 11176 | =begin original |
| 9413 | 11177 | |
| 9414 | 11178 | b A bit string (ascending bit order inside each byte, |
| 9415 | 11179 | like vec()). |
| 9416 | 11180 | B A bit string (descending bit order inside each byte). |
| 9417 | 11181 | h A hex string (low nybble first). |
| 9418 | 11182 | H A hex string (high nybble first). |
| 9419 | 11183 | |
| 9420 | 11184 | =end original |
| 9421 | 11185 | |
| 9422 | 11186 | b ビット列 (バイトごとに昇ビット順、vec() と同じ)。 |
| 9423 | 11187 | B ビット列 (バイトごとに降ビット順)。 |
| 9424 | 11188 | h 16 進数文字列 (低位ニブルが先)。 |
| 9425 | 11189 | H 16 進数文字列 (高位ニブルが先)。 |
| 9426 | 11190 | |
| 9427 | 11191 | =begin original |
| 9428 | 11192 | |
| 9429 | 11193 | c A signed char (8-bit) value. |
| 9430 | 11194 | C An unsigned char (octet) value. |
| 9431 | 11195 | W An unsigned char value (can be greater than 255). |
| 9432 | 11196 | |
| 9433 | 11197 | =end original |
| 9434 | 11198 | |
| 9435 | 11199 | c signed char (8 ビット) 値。 |
| 9436 | 11200 | C unsigned char (オクテット) 値。 |
| 9437 | 11201 | W unsigned char 値 (255 より大きいかもしれません)。 |
| 9438 | 11202 | |
| 9439 | 11203 | =begin original |
| 9440 | 11204 | |
| 9441 | 11205 | s A signed short (16-bit) value. |
| 9442 | 11206 | S An unsigned short value. |
| 9443 | 11207 | |
| 9444 | 11208 | =end original |
| 9445 | 11209 | |
| 9446 | 11210 | s signed short (16 ビット) 値。 |
| 9447 | 11211 | S unsigned short 値。 |
| 9448 | 11212 | |
| 9449 | 11213 | =begin original |
| 9450 | 11214 | |
| 9451 | 11215 | l A signed long (32-bit) value. |
| 9452 | 11216 | L An unsigned long value. |
| 9453 | 11217 | |
| 9454 | 11218 | =end original |
| 9455 | 11219 | |
| 9456 | 11220 | l signed long (32 ビット) 値。 |
| 9457 | 11221 | L unsigned long 値。 |
| 9458 | 11222 | |
| 9459 | 11223 | =begin original |
| 9460 | 11224 | |
| 9461 | 11225 | q A signed quad (64-bit) value. |
| 9462 | 11226 | Q An unsigned quad value. |
| 9463 | 11227 | (Quads are available only if your system supports 64-bit |
| 9464 | 11228 | integer values _and_ if Perl has been compiled to support |
| 9465 | 11229 | those. Raises an exception otherwise.) |
| 9466 | 11230 | |
| 9467 | 11231 | =end original |
| 9468 | 11232 | |
| 9469 | 11233 | q 符号付き 64 ビット整数。 |
| 9470 | 11234 | Q 符号なし 64 ビット整数。 |
| 9471 | 11235 | (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が |
| 9472 | 11236 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 |
| 9473 | 11237 | それ以外の場合は例外が発生します。) |
| 9474 | 11238 | |
| 9475 | 11239 | =begin original |
| 9476 | 11240 | |
| 9477 | 11241 | i A signed integer value. |
| 9478 | I A unsigned integer value. | |
| 11242 | I An unsigned integer value. | |
| 9479 | 11243 | (This 'integer' is _at_least_ 32 bits wide. Its exact |
| 9480 | 11244 | size depends on what a local C compiler calls 'int'.) |
| 9481 | 11245 | |
| 9482 | 11246 | =end original |
| 9483 | 11247 | |
| 9484 | 11248 | i signed int 値。 |
| 9485 | 11249 | I unsigned int 値。 |
| 9486 | (ここでの 'integer' は 「最低」 32 | |
| 11250 | (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは | |
| 9487 | ローカルの C コンパイラの'int'のサイズに依存します。) | |
| 11251 | ローカルの C コンパイラの 'int' のサイズに依存します。) | |
| 9488 | 11252 | |
| 9489 | 11253 | =begin original |
| 9490 | 11254 | |
| 9491 | 11255 | n An unsigned short (16-bit) in "network" (big-endian) order. |
| 9492 | 11256 | N An unsigned long (32-bit) in "network" (big-endian) order. |
| 9493 | 11257 | v An unsigned short (16-bit) in "VAX" (little-endian) order. |
| 9494 | 11258 | V An unsigned long (32-bit) in "VAX" (little-endian) order. |
| 9495 | 11259 | |
| 9496 | 11260 | =end original |
| 9497 | 11261 | |
| 9498 | 11262 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。 |
| 9499 | 11263 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。 |
| 9500 | 11264 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。 |
| 9501 | 11265 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。 |
| 9502 | 11266 | |
| 9503 | 11267 | =begin original |
| 9504 | 11268 | |
| 9505 | 11269 | j A Perl internal signed integer value (IV). |
| 9506 | 11270 | J A Perl internal unsigned integer value (UV). |
| 9507 | 11271 | |
| 9508 | 11272 | =end original |
| 9509 | 11273 | |
| 9510 | 11274 | j Perl 内部符号付き整数 (IV)。 |
| 9511 | 11275 | J Perl 内部符号なし整数 (UV)。 |
| 9512 | 11276 | |
| 9513 | 11277 | =begin original |
| 9514 | 11278 | |
| 9515 | 11279 | f A single-precision float in native format. |
| 9516 | 11280 | d A double-precision float in native format. |
| 9517 | 11281 | |
| 9518 | 11282 | =end original |
| 9519 | 11283 | |
| 9520 | 11284 | f 機種依存の単精度浮動小数点数。 |
| 9521 | 11285 | d 機種依存の倍精度浮動小数点数。 |
| 9522 | 11286 | |
| 9523 | 11287 | =begin original |
| 9524 | 11288 | |
| 9525 | 11289 | F A Perl internal floating-point value (NV) in native format |
| 9526 | 11290 | D A float of long-double precision in native format. |
| 9527 | 11291 | (Long doubles are available only if your system supports |
| 9528 | long double values | |
| 11292 | long double values. Raises an exception otherwise. | |
| 9529 | | |
| 11293 | Note that there are different long double formats.) | |
| 9530 | 11294 | |
| 9531 | 11295 | =end original |
| 9532 | 11296 | |
| 9533 | 11297 | F ネイティブフォーマットの Perl 内部浮動小数点数 (NV) |
| 9534 | 11298 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。 |
| 9535 | (long double は、システムが long double に対応してい | |
| 11299 | (long double は、システムが long double に対応している場合にのみ | |
| 9536 | | |
| 11300 | 使用可能です。それ以外の場合は例外が発生します。 | |
| 9537 | | |
| 11301 | long double 型式の場合は異なることに注意してください。) | |
| 9538 | 11302 | |
| 9539 | 11303 | =begin original |
| 9540 | 11304 | |
| 9541 | 11305 | p A pointer to a null-terminated string. |
| 9542 | 11306 | P A pointer to a structure (fixed-length string). |
| 9543 | 11307 | |
| 9544 | 11308 | =end original |
| 9545 | 11309 | |
| 9546 | 11310 | p ヌル文字で終端する文字列へのポインタ。 |
| 9547 | 11311 | P 構造体 (固定長文字列) へのポインタ。 |
| 9548 | 11312 | |
| 9549 | 11313 | =begin original |
| 9550 | 11314 | |
| 9551 | 11315 | u A uuencoded string. |
| 9552 | 11316 | U A Unicode character number. Encodes to a character in char- |
| 9553 | 11317 | acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in |
| 9554 | byte mode. | |
| 11318 | byte mode. Also on EBCDIC platforms, the character number will | |
| 11319 | be the native EBCDIC value for character numbers below 256. | |
| 11320 | This allows most programs using this feature to not have to | |
| 11321 | care which type of platform they are running on. | |
| 9555 | 11322 | |
| 11323 | ||
| 9556 | 11324 | =end original |
| 9557 | 11325 | |
| 9558 | 11326 | u uuencode 文字列。 |
| 9559 | 11327 | U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に |
| 9560 | 11328 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。 |
| 11329 | また EBCDIC プラットフォームでは、文字番号が 256 より下の場合は | |
| 11330 | EBCDIC にネイティブな値です。 | |
| 11331 | これにより、この機能を使うほとんどのプログラムで、どの種類の | |
| 11332 | プラットフォームで実行されるかを気にする必要がなくなります。 | |
| 9561 | 11333 | |
| 9562 | 11334 | =begin original |
| 9563 | 11335 | |
| 9564 | 11336 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut |
| 9565 | 11337 | for details). Its bytes represent an unsigned integer in |
| 9566 | 11338 | base 128, most significant digit first, with as few digits |
| 9567 | 11339 | as possible. Bit eight (the high bit) is set on each byte |
| 9568 | 11340 | except the last. |
| 9569 | 11341 | |
| 9570 | 11342 | =end original |
| 9571 | 11343 | |
| 9572 | 11344 | w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を |
| 9573 | 11345 | 参照してください)。このバイト列はできるだけ少ない桁数で表現された |
| 9574 | 11346 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 |
| 9575 | 11347 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 |
| 9576 | 11348 | |
| 9577 | 11349 | =begin original |
| 9578 | 11350 | |
| 9579 | 11351 | x A null byte (a.k.a ASCII NUL, "\000", chr(0)) |
| 9580 | 11352 | X Back up a byte. |
| 9581 | 11353 | @ Null-fill or truncate to absolute position, counted from the |
| 9582 | 11354 | start of the innermost ()-group. |
| 9583 | 11355 | . Null-fill or truncate to absolute position specified by |
| 9584 | 11356 | the value. |
| 9585 | 11357 | ( Start of a ()-group. |
| 9586 | 11358 | |
| 9587 | 11359 | =end original |
| 9588 | 11360 | |
| 9589 | 11361 | x ヌル文字 (つまり ASCII NUL, "\000", chr(0)) |
| 9590 | 11362 | X 1 文字後退。 |
| 9591 | 11363 | @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で |
| 9592 | 11364 | 埋めるか切り詰める。 |
| 9593 | 11365 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。 |
| 9594 | 11366 | ( () の組の開始。 |
| 9595 | 11367 | |
| 9596 | 11368 | =begin original |
| 9597 | 11369 | |
| 9598 | 11370 | One or more modifiers below may optionally follow certain letters in the |
| 9599 | 11371 | TEMPLATE (the second column lists letters for which the modifier is valid): |
| 9600 | 11372 | |
| 9601 | 11373 | =end original |
| 9602 | 11374 | |
| 9603 | 11375 | 以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで |
| 9604 | 11376 | 付けることができます(表の 2 列目は、その修飾子が有効な文字です): |
| 9605 | 11377 | |
| 9606 | 11378 | =begin original |
| 9607 | 11379 | |
| 9608 | 11380 | ! sSlLiI Forces native (short, long, int) sizes instead |
| 9609 | 11381 | of fixed (16-/32-bit) sizes. |
| 9610 | 11382 | |
| 9611 | 11383 | =end original |
| 9612 | 11384 | |
| 9613 | 11385 | ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな |
| 9614 | 11386 | (short, long, int)サイズを強制する。 |
| 9615 | 11387 | |
| 9616 | 11388 | =begin original |
| 9617 | 11389 | |
| 9618 | | |
| 11390 | ! xX Make x and X act as alignment commands. | |
| 9619 | 11391 | |
| 9620 | 11392 | =end original |
| 9621 | 11393 | |
| 9622 | | |
| 11394 | ! xX x と X をアライメントコマンドとして振舞わせる。 | |
| 9623 | 11395 | |
| 9624 | 11396 | =begin original |
| 9625 | 11397 | |
| 9626 | | |
| 11398 | ! nNvV Treat integers as signed instead of unsigned. | |
| 9627 | 11399 | |
| 9628 | 11400 | =end original |
| 9629 | 11401 | |
| 9630 | | |
| 11402 | ! nNvV 整数を符号なしではなく符号付きとして扱わせる。 | |
| 9631 | 11403 | |
| 9632 | 11404 | =begin original |
| 9633 | 11405 | |
| 9634 | | |
| 11406 | ! @. Specify position as byte offset in the internal | |
| 9635 | 11407 | representation of the packed string. Efficient |
| 9636 | 11408 | but dangerous. |
| 9637 | 11409 | |
| 9638 | 11410 | =end original |
| 9639 | 11411 | |
| 9640 | | |
| 11412 | ! @. pack された内部表現のバイトオフセットとして位置を指定する。 | |
| 9641 | 11413 | 効率的ですが危険です。 |
| 9642 | 11414 | |
| 9643 | 11415 | =begin original |
| 9644 | 11416 | |
| 9645 | 11417 | > sSiIlLqQ Force big-endian byte-order on the type. |
| 9646 | 11418 | jJfFdDpP (The "big end" touches the construct.) |
| 9647 | 11419 | |
| 9648 | 11420 | =end original |
| 9649 | 11421 | |
| 9650 | 11422 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。 |
| 9651 | 11423 | jJfFdDpP (「大きい端」が構造に触れています。) |
| 9652 | 11424 | |
| 9653 | 11425 | =begin original |
| 9654 | 11426 | |
| 9655 | 11427 | < sSiIlLqQ Force little-endian byte-order on the type. |
| 9656 | 11428 | jJfFdDpP (The "little end" touches the construct.) |
| 9657 | 11429 | |
| 9658 | 11430 | =end original |
| 9659 | 11431 | |
| 9660 | 11432 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。 |
| 9661 | 11433 | jJfFdDpP (「小さい端」が構造に触れています。) |
| 9662 | 11434 | |
| 9663 | 11435 | =begin original |
| 9664 | 11436 | |
| 9665 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups | |
| 11437 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups | |
| 9666 | to force a particular byte-order on all components in that group, | |
| 11438 | to force a particular byte-order on all components in that group, | |
| 9667 | 11439 | including all its subgroups. |
| 9668 | 11440 | |
| 9669 | 11441 | =end original |
| 9670 | 11442 | |
| 9671 | 11443 | C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます; |
| 9672 | 11444 | この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に |
| 9673 | 11445 | 強制します。 |
| 9674 | 11446 | |
| 9675 | 11447 | =begin comment |
| 9676 | 11448 | |
| 9677 | 11449 | Larry recalls that the hex and bit string formats (H, h, B, b) were added to |
| 9678 | pack for processing data from NASA's Magellan probe. Magellan was in an | |
| 11450 | pack for processing data from NASA's Magellan probe. Magellan was in an | |
| 9679 | 11451 | elliptical orbit, using the antenna for the radar mapping when close to |
| 9680 | 11452 | Venus and for communicating data back to Earth for the rest of the orbit. |
| 9681 | 11453 | There were two transmission units, but one of these failed, and then the |
| 9682 | 11454 | other developed a fault whereby it would randomly flip the sense of all the |
| 9683 | 11455 | bits. It was easy to automatically detect complete records with the correct |
| 9684 | 11456 | sense, and complete records with all the bits flipped. However, this didn't |
| 9685 | 11457 | recover the records where the sense flipped midway. A colleague of Larry's |
| 9686 | 11458 | was able to pretty much eyeball where the records flipped, so they wrote an |
| 9687 | 11459 | editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to |
| 9688 | 11460 | manually correct the records and recover the data. For this purpose pack |
| 9689 | 11461 | gained the hex and bit string format specifiers. |
| 9690 | 11462 | |
| 9691 | 11463 | git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit |
| 9692 | 11464 | 27e2fb84680b9cc1), but the patch description makes no mention of their |
| 9693 | 11465 | addition, let alone the story behind them. |
| 9694 | 11466 | |
| 9695 | 11467 | =end comment |
| 9696 | 11468 | |
| 9697 | 11469 | =begin original |
| 9698 | 11470 | |
| 9699 | 11471 | The following rules apply: |
| 9700 | 11472 | |
| 9701 | 11473 | =end original |
| 9702 | 11474 | |
| 9703 | 11475 | 以下の条件が適用されます: |
| 9704 | 11476 | |
| 9705 | =over | |
| 11477 | =over | |
| 9706 | 11478 | |
| 9707 | 11479 | =item * |
| 9708 | 11480 | |
| 9709 | 11481 | =begin original |
| 9710 | 11482 | |
| 9711 | 11483 | Each letter may optionally be followed by a number indicating the repeat |
| 9712 | 11484 | count. A numeric repeat count may optionally be enclosed in brackets, as |
| 9713 | 11485 | in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from |
| 9714 | 11486 | the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>, |
| 9715 | 11487 | C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means |
| 9716 | 11488 | something else, described below. Supplying a C<*> for the repeat count |
| 9717 | 11489 | instead of a number means to use however many items are left, except for: |
| 9718 | 11490 | |
| 9719 | 11491 | =end original |
| 9720 | 11492 | |
| 9721 | 11493 | これらの文字の後には、繰り返し数を示す数字を付けることができます。 |
| 9722 | 11494 | 数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで |
| 9723 | 11495 | 囲むこともできます。 |
| 9724 | 11496 | C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P> |
| 9725 | 11497 | 以外の全ての型では、LIST から繰り返し数の値を取り出して使います。 |
| 9726 | 11498 | 繰り返し数に C<*> を指定すると、以下の例外を除いて、 |
| 9727 | 11499 | その時点で残っているすべての要素を意味します。 |
| 9728 | 11500 | |
| 9729 | =over | |
| 11501 | =over | |
| 9730 | 11502 | |
| 9731 | =item * | |
| 11503 | =item * | |
| 9732 | 11504 | |
| 9733 | 11505 | =begin original |
| 9734 | 11506 | |
| 9735 | 11507 | C<@>, C<x>, and C<X>, where it is equivalent to C<0>. |
| 9736 | 11508 | |
| 9737 | 11509 | =end original |
| 9738 | 11510 | |
| 9739 | 11511 | C<@>, C<x>, C<X> では C<0> と等価です。 |
| 9740 | 11512 | |
| 9741 | =item * | |
| 11513 | =item * | |
| 9742 | 11514 | |
| 9743 | 11515 | =begin original |
| 9744 | 11516 | |
| 9745 | 11517 | <.>, where it means relative to the start of the string. |
| 9746 | 11518 | |
| 9747 | 11519 | =end original |
| 9748 | 11520 | |
| 9749 | ||
| 11521 | <.> では文字列の先頭からの相対位置を意味します。 | |
| 9750 | 11522 | |
| 9751 | =item * | |
| 11523 | =item * | |
| 9752 | 11524 | |
| 9753 | 11525 | =begin original |
| 9754 | 11526 | |
| 9755 | 11527 | C<u>, where it is equivalent to 1 (or 45, which here is equivalent). |
| 9756 | 11528 | |
| 9757 | 11529 | =end original |
| 9758 | 11530 | |
| 9759 | 11531 | C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。 |
| 9760 | 11532 | |
| 9761 | =back | |
| 11533 | =back | |
| 9762 | 11534 | |
| 9763 | 11535 | =begin original |
| 9764 | 11536 | |
| 9765 | 11537 | One can replace a numeric repeat count with a template letter enclosed in |
| 9766 | 11538 | brackets to use the packed byte length of the bracketed template for the |
| 9767 | 11539 | repeat count. |
| 9768 | 11540 | |
| 9769 | 11541 | =end original |
| 9770 | 11542 | |
| 9771 | 11543 | このテンプレートでパックされたバイト長を繰り返し数として使うために、 |
| 9772 | 11544 | 大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが |
| 9773 | 11545 | できます。 |
| 9774 | 11546 | |
| 9775 | 11547 | =begin original |
| 9776 | 11548 | |
| 9777 | 11549 | For example, the template C<x[L]> skips as many bytes as in a packed long, |
| 9778 | 11550 | and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when |
| 9779 | 11551 | variable-expanded) unpacks. If the template in brackets contains alignment |
| 9780 | 11552 | commands (such as C<x![d]>), its packed length is calculated as if the |
| 9781 | 11553 | start of the template had the maximal possible alignment. |
| 9782 | 11554 | |
| 9783 | 11555 | =end original |
| 9784 | 11556 | |
| 9785 | 11557 | 例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、 |
| 9786 | 11558 | テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を |
| 9787 | 11559 | unpack したものの 2 倍を unpack します。 |
| 9788 | 11560 | (C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、 |
| 9789 | 11561 | パックされた長さは、テンプレートの先頭で最大限可能なアライメントを |
| 9790 | 11562 | 持っているものとして計算されます。 |
| 9791 | 11563 | |
| 9792 | 11564 | =begin original |
| 9793 | 11565 | |
| 9794 | 11566 | When used with C<Z>, a C<*> as the repeat count is guaranteed to add a |
| 9795 | 11567 | trailing null byte, so the resulting string is always one byte longer than |
| 9796 | 11568 | the byte length of the item itself. |
| 9797 | 11569 | |
| 9798 | 11570 | =end original |
| 9799 | 11571 | |
| 9800 | 11572 | C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが |
| 9801 | 保証されるので、 | |
| 11573 | 保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト | |
| 9802 | ||
| 11574 | 長くなります。 | |
| 9803 | 11575 | |
| 9804 | 11576 | =begin original |
| 9805 | 11577 | |
| 9806 | 11578 | When used with C<@>, the repeat count represents an offset from the start |
| 9807 | 11579 | of the innermost C<()> group. |
| 9808 | 11580 | |
| 9809 | 11581 | =end original |
| 9810 | 11582 | |
| 9811 | 11583 | C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを |
| 9812 | 11584 | 表現します。 |
| 9813 | 11585 | |
| 9814 | 11586 | =begin original |
| 9815 | 11587 | |
| 9816 | 11588 | When used with C<.>, the repeat count determines the starting position to |
| 9817 | 11589 | calculate the value offset as follows: |
| 9818 | 11590 | |
| 9819 | 11591 | =end original |
| 9820 | 11592 | |
| 9821 | 11593 | C<.> で使われると、繰り返し数は以下のようにして、 |
| 9822 | 11594 | 値のオフセットを計算するための開始位置を決定するために使われます。 |
| 9823 | 11595 | |
| 9824 | =over | |
| 11596 | =over | |
| 9825 | 11597 | |
| 9826 | 11598 | =item * |
| 9827 | 11599 | |
| 9828 | 11600 | =begin original |
| 9829 | 11601 | |
| 9830 | 11602 | If the repeat count is C<0>, it's relative to the current position. |
| 9831 | 11603 | |
| 9832 | 11604 | =end original |
| 9833 | 11605 | |
| 9834 | 11606 | 繰り返し数が C<0> なら、現在位置からの相対位置となります。 |
| 9835 | 11607 | |
| 9836 | 11608 | =item * |
| 9837 | 11609 | |
| 9838 | 11610 | =begin original |
| 9839 | 11611 | |
| 9840 | 11612 | If the repeat count is C<*>, the offset is relative to the start of the |
| 9841 | 11613 | packed string. |
| 9842 | 11614 | |
| 9843 | 11615 | =end original |
| 9844 | 11616 | |
| 9845 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
| 11617 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
| 11618 | 相対位置です。 | |
| 9846 | 11619 | |
| 9847 | 11620 | =item * |
| 9848 | 11621 | |
| 9849 | 11622 | =begin original |
| 9850 | 11623 | |
| 9851 | 11624 | And if it's an integer I<n>, the offset is relative to the start of the |
| 9852 | 11625 | I<n>th innermost C<( )> group, or to the start of the string if I<n> is |
| 9853 | 11626 | bigger then the group level. |
| 9854 | 11627 | |
| 9855 | 11628 | =end original |
| 9856 | 11629 | |
| 9857 | 11630 | そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの |
| 9858 | 11631 | 先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの |
| 9859 | 11632 | 相対位置です。 |
| 9860 | 11633 | |
| 9861 | 11634 | =back |
| 9862 | 11635 | |
| 9863 | 11636 | =begin original |
| 9864 | 11637 | |
| 9865 | 11638 | The repeat count for C<u> is interpreted as the maximal number of bytes |
| 9866 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat | |
| 11639 | to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat | |
| 9867 | 11640 | count should not be more than 65. |
| 9868 | 11641 | |
| 9869 | 11642 | =end original |
| 9870 | 11643 | |
| 9871 | 11644 | C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを |
| 9872 | 11645 | 示します; 0, 1, 2 は 45 として扱われます。 |
| 9873 | 11646 | 繰り返し数は 65 を超えてはなりません。 |
| 9874 | 11647 | |
| 9875 | 11648 | =item * |
| 9876 | 11649 | |
| 9877 | 11650 | =begin original |
| 9878 | 11651 | |
| 9879 | 11652 | The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a |
| 9880 | 11653 | string of length count, padding with nulls or spaces as needed. When |
| 9881 | 11654 | unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything |
| 9882 | 11655 | after the first null, and C<a> returns data with no stripping at all. |
| 9883 | 11656 | |
| 9884 | 11657 | =end original |
| 9885 | 11658 | |
| 9886 | 11659 | C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、 |
| 9887 | 11660 | 繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か |
| 9888 | 11661 | スペース文字を付け足します。 |
| 9889 | 11662 | unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の |
| 9890 | 11663 | ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく |
| 9891 | 11664 | そのまま返します。 |
| 9892 | 11665 | |
| 9893 | 11666 | =begin original |
| 9894 | 11667 | |
| 9895 | 11668 | If the value to pack is too long, the result is truncated. If it's too |
| 9896 | 11669 | long and an explicit count is provided, C<Z> packs only C<$count-1> bytes, |
| 9897 | 11670 | followed by a null byte. Thus C<Z> always packs a trailing null, except |
| 9898 | 11671 | when the count is 0. |
| 9899 | 11672 | |
| 9900 | 11673 | =end original |
| 9901 | 11674 | |
| 9902 | 11675 | pack する値が長すぎる場合、結果は切り詰められます。 |
| 9903 | 11676 | 長すぎてかつ明示的に個数が指定されている場合、 |
| 9904 | 11677 | C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。 |
| 9905 | 11678 | 従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが |
| 9906 | 11679 | つきます。 |
| 9907 | 11680 | |
| 9908 | 11681 | =item * |
| 9909 | 11682 | |
| 9910 | 11683 | =begin original |
| 9911 | 11684 | |
| 9912 | 11685 | Likewise, the C<b> and C<B> formats pack a string that's that many bits long. |
| 9913 | 11686 | Each such format generates 1 bit of the result. These are typically followed |
| 9914 | 11687 | by a repeat count like C<B8> or C<B64>. |
| 9915 | 11688 | |
| 9916 | 11689 | =end original |
| 9917 | 11690 | |
| 9918 | 11691 | 同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。 |
| 9919 | 11692 | これらの各文字は結果の 1 ビットを生成します。 |
| 9920 | 11693 | これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。 |
| 9921 | 11694 | |
| 9922 | 11695 | =begin original |
| 9923 | 11696 | |
| 9924 | 11697 | Each result bit is based on the least-significant bit of the corresponding |
| 9925 | 11698 | input character, i.e., on C<ord($char)%2>. In particular, characters C<"0"> |
| 9926 | 11699 | and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">. |
| 9927 | 11700 | |
| 9928 | 11701 | =end original |
| 9929 | 11702 | |
| 9930 | 11703 | 結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします |
| 9931 | 11704 | (つまり C<ord($char)%2>)。 |
| 9932 | 11705 | 特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、 |
| 9933 | 11706 | ビット 0 と 1 を生成します。 |
| 9934 | 11707 | |
| 9935 | 11708 | =begin original |
| 9936 | 11709 | |
| 9937 | 11710 | Starting from the beginning of the input string, each 8-tuple |
| 9938 | 11711 | of characters is converted to 1 character of output. With format C<b>, |
| 9939 | 11712 | the first character of the 8-tuple determines the least-significant bit of a |
| 9940 | 11713 | character; with format C<B>, it determines the most-significant bit of |
| 9941 | 11714 | a character. |
| 9942 | 11715 | |
| 9943 | 11716 | =end original |
| 9944 | 11717 | |
| 9945 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に | |
| 11718 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。 | |
| 9946 | 変換されます。 | |
| 9947 | 11719 | C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります; |
| 9948 | 11720 | C<B> フォーマットでは出力の最上位ビットとなります。 |
| 9949 | 11721 | |
| 9950 | 11722 | =begin original |
| 9951 | 11723 | |
| 9952 | 11724 | If the length of the input string is not evenly divisible by 8, the |
| 9953 | 11725 | remainder is packed as if the input string were padded by null characters |
| 9954 | 11726 | at the end. Similarly during unpacking, "extra" bits are ignored. |
| 9955 | 11727 | |
| 9956 | 11728 | =end original |
| 9957 | 11729 | |
| 9958 | 11730 | もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の |
| 9959 | 11731 | 最後にヌル文字がパッディングされているものとしてパックされます。 |
| 9960 | 11732 | 同様に、unpack 中は「余分な」ビットは無視されます。 |
| 9961 | 11733 | |
| 9962 | 11734 | =begin original |
| 9963 | 11735 | |
| 9964 | 11736 | If the input string is longer than needed, remaining characters are ignored. |
| 9965 | 11737 | |
| 9966 | 11738 | =end original |
| 9967 | 11739 | |
| 9968 | 11740 | 入力文字列が必要な分よりも長い場合、余分な文字は無視されます。 |
| 9969 | 11741 | |
| 9970 | 11742 | =begin original |
| 9971 | 11743 | |
| 9972 | A C<*> for the repeat count uses all characters of the input field. | |
| 11744 | A C<*> for the repeat count uses all characters of the input field. | |
| 9973 | 11745 | On unpacking, bits are converted to a string of C<0>s and C<1>s. |
| 9974 | 11746 | |
| 9975 | 11747 | =end original |
| 9976 | 11748 | |
| 9977 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が | |
| 11749 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
| 9978 | 使われます。 | |
| 9979 | 11750 | unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。 |
| 9980 | 11751 | |
| 9981 | 11752 | =item * |
| 9982 | 11753 | |
| 9983 | 11754 | =begin original |
| 9984 | 11755 | |
| 9985 | 11756 | The C<h> and C<H> formats pack a string that many nybbles (4-bit groups, |
| 9986 | 11757 | representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long. |
| 9987 | 11758 | |
| 9988 | 11759 | =end original |
| 9989 | 11760 | |
| 9990 | 11761 | C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で |
| 9991 | 11762 | 表現可能な 4 ビットグループ)のニブル列に pack します。 |
| 9992 | 11763 | |
| 9993 | 11764 | =begin original |
| 9994 | 11765 | |
| 9995 | For each such format, pack | |
| 11766 | For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result. | |
| 9996 | 11767 | With non-alphabetical characters, the result is based on the 4 least-significant |
| 9997 | 11768 | bits of the input character, i.e., on C<ord($char)%16>. In particular, |
| 9998 | 11769 | characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes |
| 9999 | 11770 | C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result |
| 10000 | 11771 | is compatible with the usual hexadecimal digits, so that C<"a"> and |
| 10001 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex | |
| 11772 | C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex | |
| 10002 | 11773 | characters with this format. |
| 10003 | 11774 | |
| 10004 | 11775 | =end original |
| 10005 | 11776 | |
| 10006 | このようなフォーマット文字のそれぞれについて、pack | |
| 11777 | このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST> は | |
| 10007 | 11778 | 結果の 4 ビットを生成します。 |
| 10008 | 11779 | 英字でない文字の場合、結果は入力文字の下位 4 ビットを |
| 10009 | 11780 | 基にします(つまり C<ord($char)%16>)。 |
| 10010 | 11781 | 特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に |
| 10011 | 11782 | ニブル 0 と 1 を生成します。 |
| 10012 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の | |
| 11783 | 文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に | |
| 10013 | ||
| 11784 | なるので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。 | |
| 10014 | ニブル C<0xa==10> を生成します。 | |
| 10015 | 11785 | これらの 16 進文字はこの特定のフォーマットでだけ使ってください。 |
| 10016 | 11786 | |
| 10017 | 11787 | =begin original |
| 10018 | 11788 | |
| 10019 | Starting from the beginning of the template to | |
| 11789 | Starting from the beginning of the template to | |
| 11790 | L<C<pack>|/pack TEMPLATE,LIST>, each pair | |
| 10020 | 11791 | of characters is converted to 1 character of output. With format C<h>, the |
| 10021 | 11792 | first character of the pair determines the least-significant nybble of the |
| 10022 | 11793 | output character; with format C<H>, it determines the most-significant |
| 10023 | 11794 | nybble. |
| 10024 | 11795 | |
| 10025 | 11796 | =end original |
| 10026 | 11797 | |
| 10027 | pack | |
| 11798 | L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に | |
| 10028 | 変換されます。 | |
| 11799 | 1 文字の出力に変換されます。 | |
| 10029 | 11800 | C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、 |
| 10030 | 11801 | C<H> フォーマットでは出力の最上位ニブルとなります。 |
| 10031 | 11802 | |
| 10032 | 11803 | =begin original |
| 10033 | 11804 | |
| 10034 | 11805 | If the length of the input string is not even, it behaves as if padded by |
| 10035 | 11806 | a null character at the end. Similarly, "extra" nybbles are ignored during |
| 10036 | 11807 | unpacking. |
| 10037 | 11808 | |
| 10038 | 11809 | =end original |
| 10039 | 11810 | |
| 10040 | 11811 | 入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて |
| 10041 | 11812 | いるかのように振る舞います。 |
| 10042 | 11813 | 同様に、unpack 中は「余分な」ニブルは無視されます。 |
| 10043 | 11814 | |
| 10044 | 11815 | =begin original |
| 10045 | 11816 | |
| 10046 | 11817 | If the input string is longer than needed, extra characters are ignored. |
| 10047 | 11818 | |
| 10048 | 11819 | =end original |
| 10049 | 11820 | |
| 10050 | 11821 | 入力文字列が必要な分より長い場合、余分な部分は無視されます。 |
| 10051 | 11822 | |
| 10052 | 11823 | =begin original |
| 10053 | 11824 | |
| 10054 | 11825 | A C<*> for the repeat count uses all characters of the input field. For |
| 10055 | unpack | |
| 11826 | L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of | |
| 11827 | hexadecimal digits. | |
| 10056 | 11828 | |
| 10057 | 11829 | =end original |
| 10058 | 11830 | |
| 10059 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が | |
| 11831 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
| 10060 | ||
| 11832 | L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に | |
| 10061 | ||
| 11833 | 変換されます。 | |
| 10062 | 11834 | |
| 10063 | 11835 | =item * |
| 10064 | 11836 | |
| 10065 | 11837 | =begin original |
| 10066 | 11838 | |
| 10067 | 11839 | The C<p> format packs a pointer to a null-terminated string. You are |
| 10068 | 11840 | responsible for ensuring that the string is not a temporary value, as that |
| 10069 | 11841 | could potentially get deallocated before you got around to using the packed |
| 10070 | 11842 | result. The C<P> format packs a pointer to a structure of the size indicated |
| 10071 | 11843 | by the length. A null pointer is created if the corresponding value for |
| 10072 | C<p> or C<P> is C<undef>; similarly with | |
| 11844 | C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with | |
| 10073 | unpack | |
| 11845 | L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into | |
| 11846 | L<C<undef>|/undef EXPR>. | |
| 10074 | 11847 | |
| 10075 | 11848 | =end original |
| 10076 | 11849 | |
| 10077 | 11850 | C<p> は、ヌル文字終端文字列へのポインタを pack します。 |
| 10078 | 11851 | 文字列が一時的な値でない(つまり pack された結果を使う前に文字列が |
| 10079 | 11852 | 解放されない) ことに責任を持つ必要があります。 |
| 10080 | 11853 | C<P> は、指定した長さの構造体へのポインタを pack します。 |
| 10081 | C<p> または C<P> に対応する値が C<undef> だった場合、 | |
| 11854 | C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、 | |
| 10082 | ヌルポインタが作成されます; ヌルポインタが C<undef> | |
| 11855 | ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に | |
| 10083 | unpack | |
| 11856 | unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。 | |
| 10084 | 11857 | |
| 10085 | 11858 | =begin original |
| 10086 | 11859 | |
| 10087 | 11860 | If your system has a strange pointer size--meaning a pointer is neither as |
| 10088 | 11861 | big as an int nor as big as a long--it may not be possible to pack or |
| 10089 | 11862 | unpack pointers in big- or little-endian byte order. Attempting to do |
| 10090 | 11863 | so raises an exception. |
| 10091 | 11864 | |
| 10092 | 11865 | =end original |
| 10093 | 11866 | |
| 10094 | 11867 | システムのポインタが変わったサイズの場合--つまり、int の大きさでも |
| 10095 | 11868 | long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの |
| 10096 | 11869 | バイト順で pack や unpack することはできません。 |
| 10097 | 11870 | そうしようとすると例外が発生します。 |
| 10098 | 11871 | |
| 10099 | 11872 | =item * |
| 10100 | 11873 | |
| 10101 | 11874 | =begin original |
| 10102 | 11875 | |
| 10103 | 11876 | The C</> template character allows packing and unpacking of a sequence of |
| 10104 | 11877 | items where the packed structure contains a packed item count followed by |
| 10105 | 11878 | the packed items themselves. This is useful when the structure you're |
| 10106 | 11879 | unpacking has encoded the sizes or repeat counts for some of its fields |
| 10107 | 11880 | within the structure itself as separate fields. |
| 10108 | 11881 | |
| 10109 | 11882 | =end original |
| 10110 | 11883 | |
| 10111 | 11884 | C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の |
| 10112 | 11885 | アイテム列を pack 及び unpack します。 |
| 10113 | 11886 | これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に |
| 10114 | 11887 | 独立したフィールドとしてエンコードされている場合に有効です。 |
| 10115 | 11888 | |
| 10116 | 11889 | =begin original |
| 10117 | 11890 | |
| 10118 | For C<pack>, you writ | |
| 11891 | For L<C<pack>|/pack TEMPLATE,LIST>, you write | |
| 11892 | I<length-item>C</>I<sequence-item>, and the | |
| 10119 | 11893 | I<length-item> describes how the length value is packed. Formats likely |
| 10120 | 11894 | to be of most use are integer-packing ones like C<n> for Java strings, |
| 10121 | 11895 | C<w> for ASN.1 or SNMP, and C<N> for Sun XDR. |
| 10122 | 11896 | |
| 10123 | 11897 | =end original |
| 10124 | 11898 | |
| 10125 | C<pack> では I<length-item>C</>I<string-item> の | |
| 11899 | L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の | |
| 11900 | 形になり、 | |
| 10126 | 11901 | I<length-item> は長さの値がどのように pack されているかを指定します。 |
| 10127 | 11902 | もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための |
| 10128 | 11903 | C<w>、Sun XDR のための C<N> といった整数型です。 |
| 10129 | 11904 | |
| 10130 | 11905 | =begin original |
| 10131 | 11906 | |
| 10132 | For C<pack>, I<sequence-item> may have a repeat | |
| 11907 | For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat | |
| 11908 | count, in which case | |
| 10133 | 11909 | the minimum of that and the number of available items is used as the argument |
| 10134 | 11910 | for I<length-item>. If it has no repeat count or uses a '*', the number |
| 10135 | 11911 | of available items is used. |
| 10136 | 11912 | |
| 10137 | 11913 | =end original |
| 10138 | 11914 | |
| 10139 | C<pack> では、I<sequence-item> は繰り返し数を | |
| 11915 | L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を | |
| 10140 | その最小値と利用可能なアイテムの数は | |
| 11916 | 持つことがあり、その場合はその最小値と利用可能なアイテムの数は | |
| 10141 | 使われます。 | |
| 11917 | I<length-item> のための引数として使われます。 | |
| 10142 | 11918 | 繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。 |
| 10143 | 11919 | |
| 10144 | 11920 | =begin original |
| 10145 | 11921 | |
| 10146 | For C<unpack>, an internal stack of integer | |
| 11922 | For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer | |
| 11923 | arguments unpacked so far is | |
| 10147 | 11924 | used. You write C</>I<sequence-item> and the repeat count is obtained by |
| 10148 | 11925 | popping off the last element from the stack. The I<sequence-item> must not |
| 10149 | 11926 | have a repeat count. |
| 10150 | 11927 | |
| 10151 | 11928 | =end original |
| 10152 | 11929 | |
| 10153 | C<unpack> では、今まで unpack した数値引数の | |
| 11930 | L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の | |
| 11931 | 内部スタックが使われます。 | |
| 10154 | 11932 | C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を |
| 10155 | 11933 | 取り出すことで得ます。 |
| 10156 | 11934 | I<sequence-item> は繰り返し数を持っていてはいけません。 |
| 10157 | 11935 | |
| 10158 | 11936 | =begin original |
| 10159 | 11937 | |
| 10160 | 11938 | If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">), |
| 10161 | 11939 | the I<length-item> is the string length, not the number of strings. With |
| 10162 | 11940 | an explicit repeat count for pack, the packed string is adjusted to that |
| 10163 | 11941 | length. For example: |
| 10164 | 11942 | |
| 10165 | 11943 | =end original |
| 10166 | 11944 | |
| 10167 | 11945 | I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、 |
| 10168 | 11946 | I<length-item> は文字列の数ではなく、文字列の長さです。 |
| 10169 | 11947 | pack で明示的な繰り返し数があると、pack された文字列は与えられた |
| 10170 | 11948 | 長さに調整されます。 |
| 10171 | 11949 | 例えば: |
| 10172 | 11950 | |
| 10173 | 11951 | This code: gives this result: |
| 10174 | 11952 | |
| 10175 | 11953 | unpack("W/a", "\004Gurusamy") ("Guru") |
| 10176 | 11954 | unpack("a3/A A*", "007 Bond J ") (" Bond", "J") |
| 10177 | 11955 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") |
| 10178 | 11956 | |
| 10179 | 11957 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" |
| 10180 | 11958 | pack("a/W2", ord("a") .. ord("z")) "2ab" |
| 10181 | 11959 | |
| 10182 | 11960 | =begin original |
| 10183 | 11961 | |
| 10184 | The I<length-item> is not returned explicitly from | |
| 11962 | The I<length-item> is not returned explicitly from | |
| 11963 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
| 10185 | 11964 | |
| 10186 | 11965 | =end original |
| 10187 | 11966 | |
| 10188 | I<length-item> は C<unpack> から明示的には | |
| 11967 | I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には | |
| 11968 | 返されません。 | |
| 10189 | 11969 | |
| 10190 | 11970 | =begin original |
| 10191 | 11971 | |
| 10192 | 11972 | Supplying a count to the I<length-item> format letter is only useful with |
| 10193 | 11973 | C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may |
| 10194 | 11974 | introduce C<"\000"> characters, which Perl does not regard as legal in |
| 10195 | 11975 | numeric strings. |
| 10196 | 11976 | |
| 10197 | 11977 | =end original |
| 10198 | 11978 | |
| 10199 | 11979 | I<length-item> 文字に繰り返し数をつけるのは、 |
| 10200 | 11980 | 文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。 |
| 10201 | 11981 | C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が |
| 10202 | 11982 | 出力されることがあり、Perl はこれを有効な数値文字列として認識しません。 |
| 10203 | 11983 | |
| 10204 | 11984 | =item * |
| 10205 | 11985 | |
| 10206 | 11986 | =begin original |
| 10207 | 11987 | |
| 10208 | 11988 | The integer types C<s>, C<S>, C<l>, and C<L> may be |
| 10209 | 11989 | followed by a C<!> modifier to specify native shorts or |
| 10210 | 11990 | longs. As shown in the example above, a bare C<l> means |
| 10211 | 11991 | exactly 32 bits, although the native C<long> as seen by the local C compiler |
| 10212 | 11992 | may be larger. This is mainly an issue on 64-bit platforms. You can |
| 10213 | 11993 | see whether using C<!> makes any difference this way: |
| 10214 | 11994 | |
| 10215 | 11995 | =end original |
| 10216 | 11996 | |
| 10217 | 11997 | C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を |
| 10218 | 11998 | つけることで、ネイティブの short や long を指定できます。 |
| 10219 | 11999 | 上述のように、C<l> は正確に 32 ビットですが、ネイティブな |
| 10220 | 12000 | (ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。 |
| 10221 | 12001 | これは主に 64 ビットプラットフォームで意味があります。 |
| 10222 | 12002 | C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます: |
| 10223 | 12003 | |
| 10224 | printf "format s is %d, s! is %d\n", | |
| 12004 | printf "format s is %d, s! is %d\n", | |
| 10225 | 12005 | length pack("s"), length pack("s!"); |
| 10226 | 12006 | |
| 10227 | printf "format l is %d, l! is %d\n", | |
| 12007 | printf "format l is %d, l! is %d\n", | |
| 10228 | 12008 | length pack("l"), length pack("l!"); |
| 10229 | 12009 | |
| 10230 | 12010 | =begin original |
| 10231 | 12011 | |
| 10232 | 12012 | C<i!> and C<I!> are also allowed, but only for completeness' sake: |
| 10233 | 12013 | they are identical to C<i> and C<I>. |
| 10234 | 12014 | |
| 10235 | 12015 | =end original |
| 10236 | 12016 | |
| 10237 | 12017 | C<i!> と C<I!> も動作しますが、単に完全性のためだけです; |
| 10238 | 12018 | これは C<i> 及び C<I> と同じです。 |
| 10239 | 12019 | |
| 10240 | 12020 | =begin original |
| 10241 | 12021 | |
| 10242 | 12022 | The actual sizes (in bytes) of native shorts, ints, longs, and long |
| 10243 | 12023 | longs on the platform where Perl was built are also available from |
| 10244 | 12024 | the command line: |
| 10245 | 12025 | |
| 10246 | 12026 | =end original |
| 10247 | 12027 | |
| 10248 | 12028 | Perl がビルドされたプラットフォームでの short, int, long, long long の |
| 10249 | 12029 | 実際の(バイト数での)サイズはコマンドラインから: |
| 10250 | 12030 | |
| 10251 | 12031 | $ perl -V:{short,int,long{,long}}size |
| 10252 | 12032 | shortsize='2'; |
| 10253 | 12033 | intsize='4'; |
| 10254 | 12034 | longsize='4'; |
| 10255 | 12035 | longlongsize='8'; |
| 10256 | 12036 | |
| 10257 | 12037 | =begin original |
| 10258 | 12038 | |
| 10259 | or programmatically via the C<Config> module: | |
| 12039 | or programmatically via the L<C<Config>|Config> module: | |
| 10260 | 12040 | |
| 10261 | 12041 | =end original |
| 10262 | 12042 | |
| 10263 | あるいは C<Config> モジュールからプログラムで: | |
| 12043 | あるいは L<C<Config>|Config> モジュールからプログラムで: | |
| 10264 | 12044 | |
| 10265 | 12045 | use Config; |
| 10266 | 12046 | print $Config{shortsize}, "\n"; |
| 10267 | 12047 | print $Config{intsize}, "\n"; |
| 10268 | 12048 | print $Config{longsize}, "\n"; |
| 10269 | 12049 | print $Config{longlongsize}, "\n"; |
| 10270 | 12050 | |
| 10271 | 12051 | =begin original |
| 10272 | 12052 | |
| 10273 | C<$Config{longlongsize}> is undefined on systems without | |
| 12053 | C<$Config{longlongsize}> is undefined on systems without | |
| 10274 | 12054 | long long support. |
| 10275 | 12055 | |
| 10276 | 12056 | =end original |
| 10277 | 12057 | |
| 10278 | 12058 | システムが long long に対応していない場合は C<$Config{longlongsize}> は |
| 10279 | 12059 | 未定義値になります。 |
| 10280 | 12060 | |
| 10281 | 12061 | =item * |
| 10282 | 12062 | |
| 10283 | 12063 | =begin original |
| 10284 | 12064 | |
| 10285 | 12065 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are |
| 10286 | 12066 | inherently non-portable between processors and operating systems because |
| 10287 | 12067 | they obey native byteorder and endianness. For example, a 4-byte integer |
| 10288 | 12068 | 0x12345678 (305419896 decimal) would be ordered natively (arranged in and |
| 10289 | 12069 | handled by the CPU registers) into bytes as |
| 10290 | 12070 | |
| 10291 | 12071 | =end original |
| 10292 | 12072 | |
| 10293 | 12073 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は |
| 10294 | 12074 | ネイティブなバイト順序とエンディアンに従っているため、 |
| 10295 | 12075 | 本質的にプロセッサ間や OS 間で移植性がありません。 |
| 10296 | 12076 | 例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は |
| 10297 | 12077 | 内部では(CPU レジスタによって変換され扱われる形では) |
| 10298 | 12078 | 以下のようなバイト列に並べられます: |
| 10299 | 12079 | |
| 10300 | 12080 | 0x12 0x34 0x56 0x78 # big-endian |
| 10301 | 12081 | 0x78 0x56 0x34 0x12 # little-endian |
| 10302 | 12082 | |
| 10303 | 12083 | =begin original |
| 10304 | 12084 | |
| 10305 | 12085 | Basically, Intel and VAX CPUs are little-endian, while everybody else, |
| 10306 | 12086 | including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are |
| 10307 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) | |
| 12087 | big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used) | |
| 10308 | 12088 | them in little-endian mode, but SGI/Cray uses them in big-endian mode. |
| 10309 | 12089 | |
| 10310 | 12090 | =end original |
| 10311 | 12091 | |
| 10312 | 12092 | 基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、 |
| 10313 | 12093 | Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては |
| 10314 | 12094 | ビッグエンディアンです。 |
| 10315 | 12095 | Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで |
| 10316 | 12096 | 使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで |
| 10317 | 12097 | 使っています。 |
| 10318 | 12098 | |
| 10319 | 12099 | =begin original |
| 10320 | 12100 | |
| 10321 | 12101 | The names I<big-endian> and I<little-endian> are comic references to the |
| 10322 | 12102 | egg-eating habits of the little-endian Lilliputians and the big-endian |
| 10323 | 12103 | Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>. |
| 10324 | 12104 | This entered computer lingo via the paper "On Holy Wars and a Plea for |
| 10325 | 12105 | Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980. |
| 10326 | 12106 | |
| 10327 | 12107 | =end original |
| 10328 | 12108 | |
| 10329 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は | |
| 12109 | I<ビッグエンディアン> と I<リトルエンディアン> の名前は、 | |
| 10330 | 古典 | |
| 12110 | ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> での、卵を | |
| 12111 | 小さい方からむくリリパット国と大きい方からむくブレフスキュ国から | |
| 10331 | 12112 | 取られています。 |
| 10332 | 12113 | "On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137, |
| 10333 | 12114 | April 1, 1980 の文書からコンピュータ用語として取り入れられました。 |
| 10334 | 12115 | |
| 10335 | 12116 | =begin original |
| 10336 | 12117 | |
| 10337 | 12118 | Some systems may have even weirder byte orders such as |
| 10338 | 12119 | |
| 10339 | 12120 | =end original |
| 10340 | 12121 | |
| 10341 | 12122 | 以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません: |
| 10342 | 12123 | |
| 10343 | 12124 | 0x56 0x78 0x12 0x34 |
| 10344 | 12125 | 0x34 0x12 0x78 0x56 |
| 10345 | 12126 | |
| 10346 | 12127 | =begin original |
| 10347 | 12128 | |
| 12129 | These are called mid-endian, middle-endian, mixed-endian, or just weird. | |
| 12130 | ||
| 12131 | =end original | |
| 12132 | ||
| 12133 | これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと | |
| 12134 | 呼ばれます。 | |
| 12135 | ||
| 12136 | =begin original | |
| 12137 | ||
| 10348 | 12138 | You can determine your system endianness with this incantation: |
| 10349 | 12139 | |
| 10350 | 12140 | =end original |
| 10351 | 12141 | |
| 10352 | 12142 | システムの設定は以下のようにして調べられます: |
| 10353 | 12143 | |
| 10354 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); | |
| 12144 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); | |
| 10355 | 12145 | |
| 10356 | 12146 | =begin original |
| 10357 | 12147 | |
| 10358 | 12148 | The byteorder on the platform where Perl was built is also available |
| 10359 | 12149 | via L<Config>: |
| 10360 | 12150 | |
| 10361 | 12151 | =end original |
| 10362 | 12152 | |
| 10363 | 12153 | Perl がビルドされたプラットフォームでのバイト順序は |
| 10364 | 12154 | L<Config> 経由か: |
| 10365 | 12155 | |
| 10366 | 12156 | use Config; |
| 10367 | 12157 | print "$Config{byteorder}\n"; |
| 10368 | 12158 | |
| 10369 | 12159 | =begin original |
| 10370 | 12160 | |
| 10371 | 12161 | or from the command line: |
| 10372 | 12162 | |
| 10373 | 12163 | =end original |
| 10374 | 12164 | |
| 10375 | 12165 | あるいはコマンドラインで: |
| 10376 | 12166 | |
| 10377 | 12167 | $ perl -V:byteorder |
| 10378 | 12168 | |
| 10379 | 12169 | =begin original |
| 10380 | 12170 | |
| 10381 | 12171 | Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321"> |
| 10382 | and C<"87654321"> are big-endian. | |
| 12172 | and C<"87654321"> are big-endian. Systems with multiarchitecture binaries | |
| 12173 | will have C<"ffff">, signifying that static information doesn't work, | |
| 12174 | one must use runtime probing. | |
| 10383 | 12175 | |
| 10384 | 12176 | =end original |
| 10385 | 12177 | |
| 10386 | 12178 | C<"1234"> と C<"12345678"> はリトルエンディアンです; |
| 10387 | 12179 | C<"4321"> と C<"87654321"> はビッグエンディアンです。 |
| 12180 | マルチアーキテクチャバイナリを持つシステムは | |
| 12181 | C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が | |
| 12182 | あることを示します。 | |
| 10388 | 12183 | |
| 10389 | 12184 | =begin original |
| 10390 | 12185 | |
| 10391 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, | |
| 12186 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, | |
| 10392 | 12187 | and C<V> or else use the C<< > >> and C<< < >> modifiers described |
| 10393 | 12188 | immediately below. See also L<perlport>. |
| 10394 | 12189 | |
| 10395 | 12190 | =end original |
| 10396 | 12191 | |
| 10397 | 12192 | 移植性のあるパック化された整数がほしい場合は、 |
| 10398 | 12193 | C<n>, C<N>, C<v>, C<V> フォーマットを使うか、 |
| 10399 | 12194 | 直後で説明する C<< > >> と C<< < >> の修飾子が使えます。 |
| 10400 | 12195 | L<perlport> も参照してください。 |
| 10401 | 12196 | |
| 10402 | 12197 | =item * |
| 10403 | 12198 | |
| 10404 | 12199 | =begin original |
| 10405 | 12200 | |
| 12201 | Also floating point numbers have endianness. Usually (but not always) | |
| 12202 | this agrees with the integer endianness. Even though most platforms | |
| 12203 | these days use the IEEE 754 binary format, there are differences, | |
| 12204 | especially if the long doubles are involved. You can see the | |
| 12205 | C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>, | |
| 12206 | C<longdblsize>): the "kind" values are enums, unlike C<byteorder>. | |
| 12207 | ||
| 12208 | =end original | |
| 12209 | ||
| 12210 | また、浮動小数点数にもエンディアンがあります。 | |
| 12211 | 通常は(但し常にではありません)これは整数のエンディアンと同じです。 | |
| 12212 | 最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも | |
| 12213 | 関わらず、(特に long double 関連で) 相違点があります。 | |
| 12214 | C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>, | |
| 12215 | C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、 | |
| 12216 | 順序値です。 | |
| 12217 | ||
| 12218 | =begin original | |
| 12219 | ||
| 12220 | Portability-wise the best option is probably to keep to the IEEE 754 | |
| 12221 | 64-bit doubles, and of agreed-upon endianness. Another possibility | |
| 12222 | is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>. | |
| 12223 | ||
| 12224 | =end original | |
| 12225 | ||
| 12226 | 移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した | |
| 12227 | エンディアンを維持することです。 | |
| 12228 | もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の | |
| 12229 | C<"%a"> 型式です。 | |
| 12230 | ||
| 12231 | =item * | |
| 12232 | ||
| 12233 | =begin original | |
| 12234 | ||
| 10406 | 12235 | Starting with Perl 5.10.0, integer and floating-point formats, along with |
| 10407 | the C<p> and C<P> formats and C<()> groups, may all be followed by the | |
| 12236 | the C<p> and C<P> formats and C<()> groups, may all be followed by the | |
| 10408 | 12237 | C<< > >> or C<< < >> endianness modifiers to respectively enforce big- |
| 10409 | or little-endian byte-order. These modifiers are especially useful | |
| 12238 | or little-endian byte-order. These modifiers are especially useful | |
| 10410 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, | |
| 12239 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, | |
| 10411 | 12240 | 64-bit integers, or floating-point values. |
| 10412 | 12241 | |
| 10413 | 12242 | =end original |
| 10414 | 12243 | |
| 10415 | 12244 | Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、 |
| 10416 | 12245 | 全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の |
| 10417 | 12246 | エンディアン修飾子をつけることで、それぞれ |
| 10418 | 12247 | ビッグエンディアンとリトルエンディアンに強制させることができます。 |
| 10419 | 12248 | C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に |
| 10420 | 12249 | 対応していないので、これは特に有用です。 |
| 10421 | 12250 | |
| 10422 | 12251 | =begin original |
| 10423 | 12252 | |
| 10424 | 12253 | Here are some concerns to keep in mind when using an endianness modifier: |
| 10425 | 12254 | |
| 10426 | 12255 | =end original |
| 10427 | 12256 | |
| 10428 | 12257 | エンディアン修飾子を使うときに心に留めておくべきことを記します: |
| 10429 | 12258 | |
| 10430 | 12259 | =over |
| 10431 | 12260 | |
| 10432 | =item * | |
| 12261 | =item * | |
| 10433 | 12262 | |
| 10434 | 12263 | =begin original |
| 10435 | 12264 | |
| 10436 | Exchanging signed integers between different platforms works only | |
| 12265 | Exchanging signed integers between different platforms works only | |
| 10437 | 12266 | when all platforms store them in the same format. Most platforms store |
| 10438 | 12267 | signed integers in two's-complement notation, so usually this is not an issue. |
| 10439 | 12268 | |
| 10440 | 12269 | =end original |
| 10441 | 12270 | |
| 10442 | 12271 | 異なったプラットフォームで符号付き整数を交換することは、全ての |
| 10443 | 12272 | プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。 |
| 10444 | 12273 | ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、 |
| 10445 | 12274 | 普通はこれは問題になりません。 |
| 10446 | 12275 | |
| 10447 | =item * | |
| 12276 | =item * | |
| 10448 | 12277 | |
| 10449 | 12278 | =begin original |
| 10450 | 12279 | |
| 10451 | 12280 | The C<< > >> or C<< < >> modifiers can only be used on floating-point |
| 10452 | 12281 | formats on big- or little-endian machines. Otherwise, attempting to |
| 10453 | 12282 | use them raises an exception. |
| 10454 | 12283 | |
| 10455 | 12284 | =end original |
| 10456 | 12285 | |
| 10457 | 12286 | C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの |
| 10458 | 12287 | マシンでの浮動小数点フォーマットでのみ使えます。 |
| 10459 | 12288 | それ以外では、そのようなことをすると例外が発生します。 |
| 10460 | 12289 | |
| 10461 | =item * | |
| 12290 | =item * | |
| 10462 | 12291 | |
| 10463 | 12292 | =begin original |
| 10464 | 12293 | |
| 10465 | 12294 | Forcing big- or little-endian byte-order on floating-point values for |
| 10466 | 12295 | data exchange can work only if all platforms use the same |
| 10467 | 12296 | binary representation such as IEEE floating-point. Even if all |
| 10468 | 12297 | platforms are using IEEE, there may still be subtle differences. Being able |
| 10469 | 12298 | to use C<< > >> or C<< < >> on floating-point values can be useful, |
| 10470 | 12299 | but also dangerous if you don't know exactly what you're doing. |
| 10471 | 12300 | It is not a general way to portably store floating-point values. |
| 10472 | 12301 | |
| 10473 | 12302 | =end original |
| 10474 | 12303 | |
| 10475 | 12304 | データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル |
| 10476 | 12305 | エンディアンに強制することは、全てのプラットフォームが |
| 10477 | 12306 | IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ |
| 10478 | 12307 | うまくいきます。 |
| 10479 | 12308 | たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが |
| 10480 | 12309 | あるかもしれません。 |
| 10481 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が | |
| 12310 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、 | |
| 10482 | ||
| 12311 | もし自分が何をしているかを正確に理解していなければ、危険です。 | |
| 10483 | 危険です。 | |
| 10484 | 12312 | 移植性のある浮動小数点数の保存のための一般的な方法はありません。 |
| 10485 | 12313 | |
| 10486 | =item * | |
| 12314 | =item * | |
| 10487 | 12315 | |
| 10488 | 12316 | =begin original |
| 10489 | 12317 | |
| 10490 | 12318 | When using C<< > >> or C<< < >> on a C<()> group, this affects |
| 10491 | 12319 | all types inside the group that accept byte-order modifiers, |
| 10492 | 12320 | including all subgroups. It is silently ignored for all other |
| 10493 | 12321 | types. You are not allowed to override the byte-order within a group |
| 10494 | 12322 | that already has a byte-order modifier suffix. |
| 10495 | 12323 | |
| 10496 | 12324 | =end original |
| 10497 | 12325 | |
| 10498 | 12326 | C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを |
| 10499 | 12327 | 含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。 |
| 10500 | 12328 | その他の型については沈黙のうちに無視されます。 |
| 10501 | 12329 | 既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは |
| 10502 | 12330 | できません。 |
| 10503 | 12331 | |
| 10504 | 12332 | =back |
| 10505 | 12333 | |
| 10506 | 12334 | =item * |
| 10507 | 12335 | |
| 10508 | 12336 | =begin original |
| 10509 | 12337 | |
| 10510 | 12338 | Real numbers (floats and doubles) are in native machine format only. |
| 10511 | 12339 | Due to the multiplicity of floating-point formats and the lack of a |
| 10512 | 12340 | standard "network" representation for them, no facility for interchange has been |
| 10513 | 12341 | made. This means that packed floating-point data written on one machine |
| 10514 | 12342 | may not be readable on another, even if both use IEEE floating-point |
| 10515 | 12343 | arithmetic (because the endianness of the memory representation is not part |
| 10516 | 12344 | of the IEEE spec). See also L<perlport>. |
| 10517 | 12345 | |
| 10518 | 12346 | =end original |
| 10519 | 12347 | |
| 10520 | 12348 | 実数 (float と double) は、機種依存のフォーマットしかありません。 |
| 10521 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
| 12349 | いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが | |
| 10522 | ||
| 12350 | ないため、データ交換のための機能は用意してありません。 | |
| 10523 | 用意してありません。 | |
| 10524 | 12351 | つまり、あるマシンで pack した浮動小数点数は、別のマシンでは |
| 10525 | 12352 | 読めないかもしれないということです; たとえ双方で IEEE フォーマットの |
| 10526 | 12353 | 浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の |
| 10527 | 12354 | バイト順序までは、規定されていないからです)。 |
| 10528 | 12355 | L<perlport> も参照してください。 |
| 10529 | 12356 | |
| 10530 | 12357 | =begin original |
| 10531 | 12358 | |
| 10532 | 12359 | If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >> |
| 10533 | 12360 | modifiers to force big- or little-endian byte-order on floating-point values. |
| 10534 | 12361 | |
| 10535 | 12362 | =end original |
| 10536 | 12363 | |
| 10537 | 12364 | もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の |
| 10538 | 12365 | バイト順をビッグエンディアンやリトルエンディアンに強制するために、 |
| 10539 | 12366 | C<< > >> と C<< < >> の修飾子が使えます。 |
| 10540 | 12367 | |
| 10541 | 12368 | =begin original |
| 10542 | 12369 | |
| 10543 | 12370 | Because Perl uses doubles (or long doubles, if configured) internally for |
| 10544 | all numeric calculation, converting from double into float and thence | |
| 12371 | all numeric calculation, converting from double into float and thence | |
| 10545 | 12372 | to double again loses precision, so C<unpack("f", pack("f", $foo)>) |
| 10546 | 12373 | will not in general equal $foo. |
| 10547 | 12374 | |
| 10548 | 12375 | =end original |
| 10549 | 12376 | |
| 10550 | Perl では、すべての数値演算のために、内部的に double (または | |
| 12377 | Perl では、すべての数値演算のために、内部的に double (または設定によっては | |
| 10551 | ||
| 12378 | long double) を使用しているので、double から float へ変換し、それから再び | |
| 10552 | double | |
| 12379 | double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
| 10553 | 精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
| 10554 | 12380 | 一般には $foo と同じではありません。 |
| 10555 | 12381 | |
| 10556 | 12382 | =item * |
| 10557 | 12383 | |
| 10558 | 12384 | =begin original |
| 10559 | 12385 | |
| 10560 | 12386 | Pack and unpack can operate in two modes: character mode (C<C0> mode) where |
| 10561 | the packed string is processed per character, and UTF-8 mode (C<U0> mode) | |
| 12387 | the packed string is processed per character, and UTF-8 byte mode (C<U0> mode) | |
| 10562 | 12388 | where the packed string is processed in its UTF-8-encoded Unicode form on |
| 10563 | 12389 | a byte-by-byte basis. Character mode is the default |
| 10564 | 12390 | unless the format string starts with C<U>. You |
| 10565 | can always switch mode mid-format with an explicit | |
| 12391 | can always switch mode mid-format with an explicit | |
| 10566 | C<C0> or C<U0> in the format. This mode remains in effect until the next | |
| 12392 | C<C0> or C<U0> in the format. This mode remains in effect until the next | |
| 10567 | 12393 | mode change, or until the end of the C<()> group it (directly) applies to. |
| 10568 | 12394 | |
| 10569 | 12395 | =end original |
| 10570 | 12396 | |
| 10571 | 12397 | pack と unpack は二つのモードで操作します: pack された文字列を文字単位で |
| 10572 | 12398 | 処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、 |
| 10573 | 12399 | その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。 |
| 10574 | 12400 | 文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。 |
| 10575 | 12401 | モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも |
| 10576 | 12402 | 切り替えられます。 |
| 10577 | モードは次のモードに切り替えられるか、(直接)適用された () グループが | |
| 12403 | モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが | |
| 10578 | 12404 | 終了するまで有効です。 |
| 10579 | 12405 | |
| 10580 | 12406 | =begin original |
| 10581 | 12407 | |
| 10582 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode | |
| 12408 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode | |
| 10583 | 12409 | bytes is not necessarily obvious. Probably only the first of these |
| 10584 | 12410 | is what you want: |
| 10585 | 12411 | |
| 10586 | 12412 | =end original |
| 10587 | 12413 | |
| 10588 | 12414 | Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに |
| 10589 | 12415 | C<U0> を使うというのは必ずしも明白ではありません。 |
| 10590 | 12416 | おそらく、これらのうち最初のものだけが望みのものでしょう: |
| 10591 | 12417 | |
| 10592 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 12418 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 10593 | 12419 | perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)' |
| 10594 | 12420 | 03B1.03C9 |
| 10595 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 12421 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 10596 | 12422 | perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
| 10597 | 12423 | CE.B1.CF.89 |
| 10598 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 12424 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 10599 | 12425 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)' |
| 10600 | 12426 | CE.B1.CF.89 |
| 10601 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 12427 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 10602 | 12428 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' |
| 10603 | 12429 | C3.8E.C2.B1.C3.8F.C2.89 |
| 10604 | 12430 | |
| 10605 | 12431 | =begin original |
| 10606 | 12432 | |
| 10607 | 12433 | Those examples also illustrate that you should not try to use |
| 10608 | C<pack>/C<unpack> | |
| 12434 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a | |
| 12435 | substitute for the L<Encode> module. | |
| 10609 | 12436 | |
| 10610 | 12437 | =end original |
| 10611 | 12438 | |
| 10612 | これらの例は、C<pack>/ | |
| 12439 | これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/ | |
| 12440 | L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして | |
| 10613 | 12441 | 使おうとするべきではないということも示しています。 |
| 10614 | 12442 | |
| 10615 | 12443 | =item * |
| 10616 | 12444 | |
| 10617 | 12445 | =begin original |
| 10618 | 12446 | |
| 10619 | 12447 | You must yourself do any alignment or padding by inserting, for example, |
| 10620 | enough C<"x">es while packing. There is no way for | |
| 12448 | enough C<"x">es while packing. There is no way for | |
| 10621 | ||
| 12449 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 12450 | to know where characters are going to or coming from, so they | |
| 10622 | 12451 | handle their output and input as flat sequences of characters. |
| 10623 | 12452 | |
| 10624 | 12453 | =end original |
| 10625 | 12454 | |
| 10626 | 12455 | pack するときに、例えば十分な数の C<"x"> を挿入することによって |
| 10627 | 12456 | アライメントやパッディングを行うのは全て自分でしなければなりません。 |
| 10628 | ||
| 12457 | L<C<pack>|/pack TEMPLATE,LIST> や L<C<unpack>|/unpack TEMPLATE,EXPR> は、 | |
| 10629 | ||
| 12458 | 文字列がどこへ行くかやどこから来たかを | |
| 10630 | 文字列として扱います。 | |
| 12459 | 知る方法はないので、出力と入力をフラットな文字列として扱います。 | |
| 10631 | 12460 | |
| 10632 | 12461 | =item * |
| 10633 | 12462 | |
| 10634 | 12463 | =begin original |
| 10635 | 12464 | |
| 10636 | 12465 | A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may |
| 10637 | take a repeat count either as postfix, or for | |
| 12466 | take a repeat count either as postfix, or for | |
| 12467 | L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</> | |
| 10638 | 12468 | template character. Within each repetition of a group, positioning with |
| 10639 | 12469 | C<@> starts over at 0. Therefore, the result of |
| 10640 | 12470 | |
| 10641 | 12471 | =end original |
| 10642 | 12472 | |
| 10643 | 12473 | C<()> のグループはかっこで囲われた副テンプレートです。 |
| 10644 | グループは繰り返し数を取ることができます; 接尾辞によるか、 | |
| 12474 | グループは繰り返し数を取ることができます; 接尾辞によるか、 | |
| 10645 | C</> テンプレート文字によります。 | |
| 12475 | L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。 | |
| 10646 | 12476 | グループの繰り返し毎に、C<@> の位置は 0 になります。 |
| 10647 | 12477 | 従って、以下の結果は: |
| 10648 | 12478 | |
| 10649 | 12479 | pack("@1A((@2A)@3A)", qw[X Y Z]) |
| 10650 | 12480 | |
| 10651 | 12481 | =begin original |
| 10652 | 12482 | |
| 10653 | 12483 | is the string C<"\0X\0\0YZ">. |
| 10654 | 12484 | |
| 10655 | 12485 | =end original |
| 10656 | 12486 | |
| 10657 | 12487 | 文字列 C<"\0X\0\0YZ"> です。 |
| 10658 | 12488 | |
| 10659 | 12489 | =item * |
| 10660 | 12490 | |
| 10661 | 12491 | =begin original |
| 10662 | 12492 | |
| 10663 | 12493 | C<x> and C<X> accept the C<!> modifier to act as alignment commands: they |
| 10664 | 12494 | jump forward or back to the closest position aligned at a multiple of C<count> |
| 10665 | characters. For example, to pack | |
| 12495 | characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or | |
| 12496 | L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like | |
| 10666 | 12497 | |
| 10667 | 12498 | =end original |
| 10668 | 12499 | |
| 10669 | 12500 | C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます: |
| 10670 | 12501 | これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。 |
| 10671 | 例えば、以下のような構造体を pack | |
| 12502 | 例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または | |
| 12503 | L<C<unpack>|/unpack TEMPLATE,EXPR> するには | |
| 10672 | 12504 | |
| 10673 | 12505 | struct { |
| 10674 | 12506 | char c; /* one signed, 8-bit character */ |
| 10675 | double d; | |
| 12507 | double d; | |
| 10676 | 12508 | char cc[2]; |
| 10677 | 12509 | } |
| 10678 | 12510 | |
| 10679 | 12511 | =begin original |
| 10680 | 12512 | |
| 10681 | 12513 | one may need to use the template C<c x![d] d c[2]>. This assumes that |
| 10682 | 12514 | doubles must be aligned to the size of double. |
| 10683 | 12515 | |
| 10684 | 12516 | =end original |
| 10685 | 12517 | |
| 10686 | 12518 | C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。 |
| 10687 | 12519 | これは double が double のサイズでアライメントされていることを |
| 10688 | 12520 | 仮定しています。 |
| 10689 | 12521 | |
| 10690 | 12522 | =begin original |
| 10691 | 12523 | |
| 10692 | 12524 | For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1; |
| 10693 | 12525 | both are no-ops. |
| 10694 | 12526 | |
| 10695 | 12527 | =end original |
| 10696 | 12528 | |
| 10697 | アライメントコマンドに対しては、C<count> に 0 を指定するのは | |
| 12529 | アライメントコマンドに対しては、C<count> に 0 を指定するのは | |
| 10698 | 指定するのと等価です; どちらも何もしません。 | |
| 12530 | C<count> に 1 を指定するのと等価です; どちらも何もしません。 | |
| 10699 | 12531 | |
| 10700 | 12532 | =item * |
| 10701 | 12533 | |
| 10702 | 12534 | =begin original |
| 10703 | 12535 | |
| 10704 | 12536 | C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to |
| 10705 | 12537 | represent signed 16-/32-bit integers in big-/little-endian order. |
| 10706 | 12538 | This is portable only when all platforms sharing packed data use the |
| 10707 | 12539 | same binary representation for signed integers; for example, when all |
| 10708 | 12540 | platforms use two's-complement representation. |
| 10709 | 12541 | |
| 10710 | 12542 | =end original |
| 10711 | 12543 | |
| 10712 | C<n>, C<N>, C<v>, C<V> は | |
| 12544 | C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または | |
| 10713 | ビッグ/リトルエンディアンの順序で符号付き 16 または | |
| 10714 | 12545 | 32 ビット整数で表現するための C<!> 修飾子を受け入れます。 |
| 10715 | 12546 | これは pack されたデータを共有する全てのプラットフォームが |
| 10716 | 12547 | 符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります; |
| 10717 | 12548 | 例えば、全てのプラットフォームで 2 の補数表現を使う場合です。 |
| 10718 | 12549 | |
| 10719 | 12550 | =item * |
| 10720 | 12551 | |
| 10721 | 12552 | =begin original |
| 10722 | 12553 | |
| 10723 | 12554 | Comments can be embedded in a TEMPLATE using C<#> through the end of line. |
| 10724 | 12555 | White space can separate pack codes from each other, but modifiers and |
| 10725 | 12556 | repeat counts must follow immediately. Breaking complex templates into |
| 10726 | 12557 | individual line-by-line components, suitably annotated, can do as much to |
| 10727 | 12558 | improve legibility and maintainability of pack/unpack formats as C</x> can |
| 10728 | 12559 | for complicated pattern matches. |
| 10729 | 12560 | |
| 10730 | 12561 | =end original |
| 10731 | 12562 | |
| 10732 | 12563 | TEMPLATE の中の C<#> から行末まではコメントです。 |
| 10733 | 12564 | 空白は pack コードをそれぞれ分けるために使えますが、修飾子と |
| 10734 | 12565 | 繰り返し数は直後に置かなければなりません。 |
| 10735 | 12566 | 複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、 |
| 10736 | 12567 | 複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack |
| 10737 | 12568 | フォーマットの読みやすさと保守性が向上します。 |
| 10738 | 12569 | |
| 10739 | 12570 | =item * |
| 10740 | 12571 | |
| 10741 | 12572 | =begin original |
| 10742 | 12573 | |
| 10743 | If TEMPLATE requires more arguments than pack | |
| 12574 | If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST> | |
| 12575 | is given, L<C<pack>|/pack TEMPLATE,LIST> | |
| 10744 | 12576 | assumes additional C<""> arguments. If TEMPLATE requires fewer arguments |
| 10745 | 12577 | than given, extra arguments are ignored. |
| 10746 | 12578 | |
| 10747 | 12579 | =end original |
| 10748 | 12580 | |
| 10749 | TEMPLATE が要求する引数の数が pack | |
| 12581 | TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に | |
| 10750 | ||
| 12582 | 与えている数より多い場合、 | |
| 12583 | L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。 | |
| 10751 | 12584 | TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。 |
| 10752 | 12585 | |
| 12586 | =item * | |
| 12587 | ||
| 12588 | =begin original | |
| 12589 | ||
| 12590 | Attempting to pack the special floating point values C<Inf> and C<NaN> | |
| 12591 | (infinity, also in negative, and not-a-number) into packed integer values | |
| 12592 | (like C<"L">) is a fatal error. The reason for this is that there simply | |
| 12593 | isn't any sensible mapping for these special values into integers. | |
| 12594 | ||
| 12595 | =end original | |
| 12596 | ||
| 12597 | 特殊浮動小数点値 C<Inf> と C<NaN> | |
| 12598 | ((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると | |
| 12599 | 致命的エラーとなります。 | |
| 12600 | この理由は、単に特殊値を整数に割り当てられないからです。 | |
| 12601 | ||
| 10753 | 12602 | =back |
| 10754 | 12603 | |
| 10755 | 12604 | =begin original |
| 10756 | 12605 | |
| 10757 | 12606 | Examples: |
| 10758 | 12607 | |
| 10759 | 12608 | =end original |
| 10760 | 12609 | |
| 10761 | 12610 | 例: |
| 10762 | 12611 | |
| 10763 | 12612 | $foo = pack("WWWW",65,66,67,68); |
| 10764 | 12613 | # foo eq "ABCD" |
| 10765 | 12614 | $foo = pack("W4",65,66,67,68); |
| 10766 | 12615 | # same thing |
| 10767 | 12616 | $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9); |
| 10768 | 12617 | # same thing with Unicode circled letters. |
| 10769 | 12618 | $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9); |
| 10770 | 12619 | # same thing with Unicode circled letters. You don't get the |
| 10771 | 12620 | # UTF-8 bytes because the U at the start of the format caused |
| 10772 | 12621 | # a switch to U0-mode, so the UTF-8 bytes get joined into |
| 10773 | 12622 | # characters |
| 10774 | 12623 | $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9); |
| 10775 | 12624 | # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9" |
| 10776 | 12625 | # This is the UTF-8 encoding of the string in the |
| 10777 | 12626 | # previous example |
| 10778 | 12627 | |
| 10779 | 12628 | $foo = pack("ccxxcc",65,66,67,68); |
| 10780 | 12629 | # foo eq "AB\0\0CD" |
| 10781 | 12630 | |
| 10782 | 12631 | # NOTE: The examples above featuring "W" and "c" are true |
| 10783 | 12632 | # only on ASCII and ASCII-derived systems such as ISO Latin 1 |
| 10784 | 12633 | # and UTF-8. On EBCDIC systems, the first example would be |
| 10785 | 12634 | # $foo = pack("WWWW",193,194,195,196); |
| 10786 | 12635 | |
| 10787 | 12636 | $foo = pack("s2",1,2); |
| 10788 | 12637 | # "\001\000\002\000" on little-endian |
| 10789 | 12638 | # "\000\001\000\002" on big-endian |
| 10790 | 12639 | |
| 10791 | 12640 | $foo = pack("a4","abcd","x","y","z"); |
| 10792 | 12641 | # "abcd" |
| 10793 | 12642 | |
| 10794 | 12643 | $foo = pack("aaaa","abcd","x","y","z"); |
| 10795 | 12644 | # "axyz" |
| 10796 | 12645 | |
| 10797 | 12646 | $foo = pack("a14","abcdefg"); |
| 10798 | 12647 | # "abcdefg\0\0\0\0\0\0\0" |
| 10799 | 12648 | |
| 10800 | 12649 | $foo = pack("i9pl", gmtime); |
| 10801 | 12650 | # a real struct tm (on my system anyway) |
| 10802 | 12651 | |
| 10803 | 12652 | $utmp_template = "Z8 Z8 Z16 L"; |
| 10804 | 12653 | $utmp = pack($utmp_template, @utmp1); |
| 10805 | 12654 | # a struct utmp (BSDish) |
| 10806 | 12655 | |
| 10807 | 12656 | @utmp2 = unpack($utmp_template, $utmp); |
| 10808 | 12657 | # "@utmp1" eq "@utmp2" |
| 10809 | 12658 | |
| 10810 | 12659 | sub bintodec { |
| 10811 | 12660 | unpack("N", pack("B32", substr("0" x 32 . shift, -32))); |
| 10812 | 12661 | } |
| 10813 | 12662 | |
| 10814 | 12663 | $foo = pack('sx2l', 12, 34); |
| 10815 | 12664 | # short 12, two zero bytes padding, long 34 |
| 10816 | 12665 | $bar = pack('s@4l', 12, 34); |
| 10817 | 12666 | # short 12, zero fill to position 4, long 34 |
| 10818 | 12667 | # $foo eq $bar |
| 10819 | 12668 | $baz = pack('s.l', 12, 4, 34); |
| 10820 | 12669 | # short 12, zero fill to position 4, long 34 |
| 10821 | 12670 | |
| 10822 | 12671 | $foo = pack('nN', 42, 4711); |
| 10823 | 12672 | # pack big-endian 16- and 32-bit unsigned integers |
| 10824 | 12673 | $foo = pack('S>L>', 42, 4711); |
| 10825 | 12674 | # exactly the same |
| 10826 | 12675 | $foo = pack('s<l<', -42, 4711); |
| 10827 | 12676 | # pack little-endian 16- and 32-bit signed integers |
| 10828 | 12677 | $foo = pack('(sl)<', -42, 4711); |
| 10829 | 12678 | # exactly the same |
| 10830 | 12679 | |
| 10831 | 12680 | =begin original |
| 10832 | 12681 | |
| 10833 | The same template may generally also be used in | |
| 12682 | The same template may generally also be used in | |
| 12683 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
| 10834 | 12684 | |
| 10835 | 12685 | =end original |
| 10836 | 12686 | |
| 10837 | 一般には、 | |
| 12687 | 一般的には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも | |
| 10838 | ||
| 12688 | 使用できます。 | |
| 10839 | 12689 | |
| 10840 | 12690 | =item package NAMESPACE |
| 10841 | 12691 | |
| 10842 | 12692 | =item package NAMESPACE VERSION |
| 10843 | 12693 | X<package> X<module> X<namespace> X<version> |
| 10844 | 12694 | |
| 10845 | 12695 | =item package NAMESPACE BLOCK |
| 10846 | 12696 | |
| 10847 | 12697 | =item package NAMESPACE VERSION BLOCK |
| 10848 | 12698 | X<package> X<module> X<namespace> X<version> |
| 10849 | 12699 | |
| 10850 | 12700 | =for Pod::Functions declare a separate global namespace |
| 10851 | 12701 | |
| 10852 | 12702 | =begin original |
| 10853 | 12703 | |
| 10854 | 12704 | Declares the BLOCK or the rest of the compilation unit as being in the |
| 10855 | 12705 | given namespace. The scope of the package declaration is either the |
| 10856 | 12706 | supplied code BLOCK or, in the absence of a BLOCK, from the declaration |
| 10857 | 12707 | itself through the end of current scope (the enclosing block, file, or |
| 10858 | C<eval>). That is, the forms without a BLOCK are | |
| 12708 | L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are | |
| 10859 | of the current scope, just like the | |
| 12709 | operative through the end of the current scope, just like the | |
| 10860 | ||
| 12710 | L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and | |
| 10861 | ||
| 12711 | L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers | |
| 12712 | in this scope will be in the given namespace, except where overridden by | |
| 12713 | another L<C<package>|/package NAMESPACE> declaration or | |
| 10862 | 12714 | when they're one of the special identifiers that qualify into C<main::>, |
| 10863 | 12715 | like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables. |
| 10864 | 12716 | |
| 10865 | 12717 | =end original |
| 10866 | 12718 | |
| 10867 | 12719 | BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。 |
| 10868 | 12720 | パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から |
| 10869 | 現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。 | |
| 12721 | 現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。 | |
| 10870 | つまり、BLOCK なしの形式は、C<my>, C<state> | |
| 12722 | つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, | |
| 10871 | 現在のスコープの末尾にまで作用します。 | |
| 12723 | L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。 | |
| 10872 | 12724 | このスコープ内の、全ての完全修飾されていない動的識別子は、他の |
| 10873 | C<package> 宣言によって上書きされるか、 | |
| 12725 | L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、 | |
| 10874 | 12726 | C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に |
| 10875 | 12727 | 割り当てられる特殊変数でない限り、指定された |
| 10876 | 12728 | 名前空間になります。 |
| 10877 | 12729 | |
| 10878 | 12730 | =begin original |
| 10879 | 12731 | |
| 10880 | 12732 | A package statement affects dynamic variables only, including those |
| 10881 | you've used C<local> on, but I<not> lexically-scop | |
| 12733 | you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped | |
| 10882 | ||
| 12734 | variables, which are created with L<C<my>|/my VARLIST>, | |
| 10883 | ||
| 12735 | L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it | |
| 10884 | ||
| 12736 | would be the first declaration in a file included by | |
| 12737 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>. | |
| 12738 | You can switch into a | |
| 12739 | package in more than one place, since this only determines which default | |
| 10885 | 12740 | symbol table the compiler uses for the rest of that block. You can refer to |
| 10886 | 12741 | identifiers in other packages than the current one by prefixing the identifier |
| 10887 | 12742 | with the package name and a double colon, as in C<$SomePack::var> |
| 10888 | 12743 | or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main> |
| 10889 | package | |
| 12744 | package is assumed. That is, C<$::sail> is equivalent to | |
| 10890 | 12745 | C<$main::sail> (as well as to C<$main'sail>, still seen in ancient |
| 10891 | 12746 | code, mostly from Perl 4). |
| 10892 | 12747 | |
| 10893 | 12748 | =end original |
| 10894 | 12749 | |
| 10895 | package 文は動的変数にのみ影響します(C<local> で使ったものも | |
| 12750 | package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも | |
| 10896 | 含みます)が、C<my>, C<state> | |
| 12751 | 含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, | |
| 12752 | L<C<our>|/our VARLIST> のいずれかで作成された | |
| 10897 | 12753 | レキシカルなスコープの変数には I<影響しません>。 |
| 10898 | 典型的にはこれは C<require> | |
| 12754 | 典型的にはこれは L<C<require>|/require VERSION> や | |
| 12755 | L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの | |
| 10899 | 12756 | 最初に宣言されます。 |
| 10900 | 12757 | パッケージを複数の場所で切り替えることができます; |
| 10901 | 12758 | なぜならこれは単にコンパイラがこのブロックの残りに対してどの |
| 10902 | 12759 | シンボルテーブルを使うかにのみ影響するからです。 |
| 10903 | 12760 | 他のパッケージの識別子は、C<$SomePack::var> や |
| 10904 | 12761 | C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と |
| 10905 | 12762 | コロン二つをつけることで参照できます。 |
| 10906 | 12763 | パッケージ名が省略された場合、C<main> パッケージが仮定されます。 |
| 10907 | 12764 | つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、 |
| 10908 | 12765 | 古いコードでは C<$main'sail> もまだ見られます)。 |
| 10909 | 12766 | |
| 10910 | 12767 | =begin original |
| 10911 | 12768 | |
| 10912 | If VERSION is provided, C<package> | |
| 12769 | If VERSION is provided, L<C<package>|/package NAMESPACE> sets the | |
| 12770 | C<$VERSION> variable in the given | |
| 10913 | 12771 | namespace to a L<version> object with the VERSION provided. VERSION must be a |
| 10914 | 12772 | "strict" style version number as defined by the L<version> module: a positive |
| 10915 | 12773 | decimal number (integer or decimal-fraction) without exponentiation or else a |
| 10916 | 12774 | dotted-decimal v-string with a leading 'v' character and at least three |
| 10917 | 12775 | components. You should set C<$VERSION> only once per package. |
| 10918 | 12776 | |
| 10919 | 12777 | =end original |
| 10920 | 12778 | |
| 10921 | VERSION が指定されると、C<package> は与えられた | |
| 12779 | VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた | |
| 12780 | 名前空間の C<$VERSION> 変数に、 | |
| 10922 | 12781 | 指定された VERSION の L<version> オブジェクトをセットします。 |
| 10923 | 12782 | VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で |
| 10924 | 12783 | なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 |
| 10925 | 12784 | さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から |
| 10926 | 12785 | 構成されるドット付き 10 進v-文字列です。 |
| 10927 | 12786 | C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。 |
| 10928 | 12787 | |
| 10929 | 12788 | =begin original |
| 10930 | 12789 | |
| 10931 | 12790 | See L<perlmod/"Packages"> for more information about packages, modules, |
| 10932 | 12791 | and classes. See L<perlsub> for other scoping issues. |
| 10933 | 12792 | |
| 10934 | 12793 | =end original |
| 10935 | 12794 | |
| 10936 | 12795 | パッケージ、モジュール、クラスに関するさらなる情報については |
| 10937 | 12796 | L<perlmod/"Packages"> を参照してください。 |
| 10938 | 12797 | その他のスコープに関する話題については L<perlsub> を参照してください。 |
| 10939 | 12798 | |
| 10940 | 12799 | =item __PACKAGE__ |
| 10941 | 12800 | X<__PACKAGE__> |
| 10942 | 12801 | |
| 10943 | 12802 | =for Pod::Functions +5.004 the current package |
| 10944 | 12803 | |
| 10945 | 12804 | =begin original |
| 10946 | 12805 | |
| 10947 | 12806 | A special token that returns the name of the package in which it occurs. |
| 10948 | 12807 | |
| 10949 | 12808 | =end original |
| 10950 | 12809 | |
| 10951 | 12810 | これが書いてあるパッケージの名前を返す特殊トークン。 |
| 10952 | 12811 | |
| 10953 | 12812 | =item pipe READHANDLE,WRITEHANDLE |
| 10954 | 12813 | X<pipe> |
| 10955 | 12814 | |
| 10956 | 12815 | =for Pod::Functions open a pair of connected filehandles |
| 10957 | 12816 | |
| 10958 | 12817 | =begin original |
| 10959 | 12818 | |
| 10960 | 12819 | Opens a pair of connected pipes like the corresponding system call. |
| 10961 | 12820 | Note that if you set up a loop of piped processes, deadlock can occur |
| 10962 | 12821 | unless you are very careful. In addition, note that Perl's pipes use |
| 10963 | IO buffering, so you may need to set C<$ | |
| 12822 | IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> | |
| 10964 | after each command, depending on the | |
| 12823 | to flush your WRITEHANDLE after each command, depending on the | |
| 12824 | application. | |
| 10965 | 12825 | |
| 10966 | 12826 | =end original |
| 10967 | 12827 | |
| 10968 | 対応するシステムコールと同じように、 | |
| 12828 | 対応するシステムコールと同じように、接続されたパイプのペアを開きます。 | |
| 10969 | 接続されたパイプのペアをオープンします。 | |
| 10970 | 12829 | パイプでプロセスをループにするときには、よほど気を付けないと、 |
| 10971 | 12830 | デッドロックが起こり得ます。 |
| 10972 | さらに、Perl のパイプでは、IO のバッファリングを使 | |
| 12831 | さらに、Perl のパイプでは、IO のバッファリングを使ので、 | |
| 10973 | 12832 | アプリケーションによっては、コマンドごとに WRITEHANDLE を |
| 10974 | フラッシュするように、C<$|> を設定することが | |
| 12833 | フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが | |
| 12834 | 必要になるかもしれません。 | |
| 10975 | 12835 | |
| 10976 | 12836 | =begin original |
| 10977 | 12837 | |
| 10978 | 12838 | Returns true on success. |
| 10979 | 12839 | |
| 10980 | 12840 | =end original |
| 10981 | 12841 | |
| 10982 | 12842 | 成功時には真を返します。 |
| 10983 | 12843 | |
| 10984 | 12844 | =begin original |
| 10985 | 12845 | |
| 10986 | 12846 | See L<IPC::Open2>, L<IPC::Open3>, and |
| 10987 | 12847 | L<perlipc/"Bidirectional Communication with Another Process"> |
| 10988 | 12848 | for examples of such things. |
| 10989 | 12849 | |
| 10990 | 12850 | =end original |
| 10991 | 12851 | |
| 10992 | 12852 | これらに関する例については、L<IPC::Open2>, L<IPC::Open3>, |
| 10993 | 12853 | L<perlipc/"Bidirectional Communication with Another Process"> を |
| 10994 | 12854 | 参照してください。 |
| 10995 | 12855 | |
| 10996 | 12856 | =begin original |
| 10997 | 12857 | |
| 10998 | 12858 | On systems that support a close-on-exec flag on files, that flag is set |
| 10999 | on all newly opened file descriptors whose | |
| 12859 | on all newly opened file descriptors whose | |
| 11000 | ||
| 12860 | L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of | |
| 12861 | L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>. | |
| 11001 | 12862 | |
| 11002 | 12863 | =end original |
| 11003 | 12864 | |
| 11004 | 12865 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 11005 | 12866 | 新しくオープンされたファイル記述子のうち、 |
| 11006 | C<fileno> が現在の $^F | |
| 12867 | L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値 | |
| 12868 | (デフォルトでは C<STDERR> の 2) | |
| 11007 | 12869 | I<よりも大きい> ものに対してフラグがセットされます。 |
| 11008 | 12870 | L<perlvar/$^F> を参照してください。 |
| 11009 | 12871 | |
| 11010 | 12872 | =item pop ARRAY |
| 11011 | 12873 | X<pop> X<stack> |
| 11012 | 12874 | |
| 11013 | =item pop EXPR | |
| 11014 | ||
| 11015 | 12875 | =item pop |
| 11016 | 12876 | |
| 11017 | 12877 | =for Pod::Functions remove the last element from an array and return it |
| 11018 | 12878 | |
| 11019 | 12879 | =begin original |
| 11020 | 12880 | |
| 11021 | ||
| 12881 | Removes and returns the B<last> element of the array, shortening the array by | |
| 11022 | 12882 | one element. |
| 11023 | 12883 | |
| 11024 | 12884 | =end original |
| 11025 | 12885 | |
| 11026 | 配列の最後の値を | |
| 12886 | 配列の B<最後の> 値を削除して返し、配列の大きさを 1 だけ小さくします。 | |
| 11027 | 12887 | |
| 12888 | my @arr = ('cat', 'dog', 'mouse'); | |
| 12889 | my $item = pop(@arr); # 'mouse' | |
| 12890 | ||
| 12891 | # @arr is now ('cat', 'dog') | |
| 12892 | ||
| 11028 | 12893 | =begin original |
| 11029 | 12894 | |
| 11030 | Returns | |
| 12895 | Returns C<undef> if the array is empty. | |
| 11031 | happen at other times. If ARRAY is omitted, pops the C<@ARGV> array in the | |
| 11032 | main program, but the C<@_> array in subroutines, just like C<shift>. | |
| 11033 | 12896 | |
| 11034 | 12897 | =end original |
| 11035 | 12898 | |
| 11036 | ||
| 12899 | 配列が空なら C<undef> を返します。 | |
| 11037 | しかしこれは他の場合にも起こり得ます。 | |
| 11038 | ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV> が | |
| 11039 | 使われますが、サブルーチンでは C<@_> が使われます。 | |
| 11040 | 12900 | |
| 11041 | 12901 | =begin original |
| 11042 | 12902 | |
| 11043 | ||
| 12903 | B<Note:> C<pop> may also return C<undef> if the last element in the array | |
| 11044 | ||
| 12904 | is C<undef>. | |
| 11045 | automatically. This aspect of C<pop> is considered highly experimental. | |
| 11046 | The exact behaviour may change in a future version of Perl. | |
| 11047 | 12905 | |
| 11048 | 12906 | =end original |
| 11049 | 12907 | |
| 11050 | ||
| 12908 | B<Note:> C<pop> may also return C<undef> if the last element in the array | |
| 11051 | ||
| 12909 | is C<undef>. | |
| 11052 | ||
| 12910 | (TBT) | |
| 11053 | C<pop> のこの動作は高度に実験的であると考えられています。 | |
| 11054 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 11055 | 12911 | |
| 12912 | my @arr = ('one', 'two', undef); | |
| 12913 | my $item = pop(@arr); # undef | |
| 12914 | ||
| 11056 | 12915 | =begin original |
| 11057 | 12916 | |
| 11058 | ||
| 12917 | If ARRAY is omitted, C<pop> operates on the L<C<@ARGV>|perlvar/@ARGV> array | |
| 11059 | ||
| 12918 | in the main program, but the L<C<@_>|perlvar/@_> array in subroutines. C<pop> | |
| 11060 | ||
| 12919 | will operate on the C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, | |
| 11061 | ||
| 12920 | C<CHECK {}> blocks. | |
| 11062 | 12921 | |
| 11063 | 12922 | =end original |
| 11064 | 12923 | |
| 11065 | ||
| 12924 | ARRAY が省略されると、C<pop> は、メインプログラムでは | |
| 11066 | ||
| 12925 | L<C<@ARGV>|perlvar/@ARGV> が使われますが、 | |
| 11067 | ||
| 12926 | サブルーチンでは L<C<@_>|perlvar/@_> が使われます。 | |
| 11068 | ||
| 12927 | C<pop> | |
| 12928 | will operate on the C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, | |
| 12929 | C<CHECK {}> blocks. | |
| 12930 | (TBT) | |
| 11069 | 12931 | |
| 11070 | ||
| 12932 | =begin original | |
| 11071 | 12933 | |
| 12934 | Starting with Perl 5.14, an experimental feature allowed | |
| 12935 | L<C<pop>|/pop ARRAY> to take a | |
| 12936 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 12937 | removed as of Perl 5.24. | |
| 12938 | ||
| 12939 | =end original | |
| 12940 | ||
| 12941 | Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという | |
| 12942 | 実験的機能がありました。 | |
| 12943 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 12944 | ||
| 11072 | 12945 | =item pos SCALAR |
| 11073 | 12946 | X<pos> X<match, position> |
| 11074 | 12947 | |
| 11075 | 12948 | =item pos |
| 11076 | 12949 | |
| 11077 | 12950 | =for Pod::Functions find or set the offset for the last/next m//g search |
| 11078 | 12951 | |
| 11079 | 12952 | =begin original |
| 11080 | 12953 | |
| 11081 | 12954 | Returns the offset of where the last C<m//g> search left off for the |
| 11082 | variable in question (C<$_> is used when the variable is not | |
| 12955 | variable in question (L<C<$_>|perlvar/$_> is used when the variable is not | |
| 11083 | specified). | |
| 12956 | specified). This offset is in characters unless the | |
| 12957 | (no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in | |
| 12958 | which case the offset is in bytes. Note that 0 is a valid match offset. | |
| 12959 | L<C<undef>|/undef EXPR> indicates | |
| 11084 | 12960 | that the search position is reset (usually due to match failure, but |
| 11085 | 12961 | can also be because no match has yet been run on the scalar). |
| 11086 | 12962 | |
| 11087 | 12963 | =end original |
| 11088 | 12964 | |
| 11089 | 12965 | 対象の変数に対して、前回の C<m//g> が終了した場所の |
| 11090 | オフセットを返します(変数が指定されなかった場合は C<$_> が | |
| 12966 | オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_> が | |
| 12967 | 使われます)。 | |
| 12968 | オフセットは、(もはや勧められない) L<C<use bytes>|bytes> プラグマが有効の | |
| 12969 | 場合(この場合はバイト単位です)を除いて、文字単位です。 | |
| 11091 | 12970 | 0 は有効なマッチオフセットであることに注意してください。 |
| 11092 | C<undef> は検索位置がリセットされることを意味します (通常は | |
| 12971 | L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は | |
| 11093 | 原因ですが、このスカラ値にまだマッチングが | |
| 12972 | マッチ失敗が原因ですが、このスカラ値にまだマッチングが | |
| 12973 | 行われていないためかもしれません)。 | |
| 11094 | 12974 | |
| 11095 | 12975 | =begin original |
| 11096 | 12976 | |
| 11097 | C<pos> directly accesses the location used by the regexp | |
| 12977 | L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp | |
| 11098 | store the offset, so assigning to C<pos> will | |
| 12978 | engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will | |
| 11099 | so will also influence the C<\G> zero-width | |
| 12979 | change that offset, and so will also influence the C<\G> zero-width | |
| 11100 | expressions. Both of these effects take place for | |
| 12980 | assertion in regular expressions. Both of these effects take place for | |
| 11101 | you can't affect the position with | |
| 12981 | the next match, so you can't affect the position with | |
| 11102 | ||
| 12982 | L<C<pos>|/pos SCALAR> during the current match, such as in | |
| 12983 | C<(?{pos() = 5})> or C<s//pos() = 5/e>. | |
| 11103 | 12984 | |
| 11104 | 12985 | =end original |
| 11105 | 12986 | |
| 11106 | C<pos> は正規表現エンジンがオフセットを保存するために使う場所を | |
| 12987 | L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を | |
| 11107 | アクセスするので、C<pos> への代入はオフセットを変更し、 | |
| 12988 | 直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、 | |
| 11108 | 正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 | |
| 12989 | そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 | |
| 11109 | 12990 | これらの効果の両方は次のマッチングのために行われるので、 |
| 11110 | 12991 | C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の |
| 11111 | C<pos> の位置には影響を与えません。 | |
| 12992 | L<C<pos>|/pos SCALAR> の位置には影響を与えません。 | |
| 11112 | 12993 | |
| 11113 | 12994 | =begin original |
| 11114 | 12995 | |
| 11115 | Setting C<pos> also resets the I<matched with | |
| 12996 | Setting L<C<pos>|/pos SCALAR> also resets the I<matched with | |
| 12997 | zero-length> flag, described | |
| 11116 | 12998 | under L<perlre/"Repeated Patterns Matching a Zero-length Substring">. |
| 11117 | 12999 | |
| 11118 | 13000 | =end original |
| 11119 | 13001 | |
| 11120 | C<pos> を設定すると、 | |
| 13002 | L<C<pos>|/pos SCALAR> を設定すると、 | |
| 11121 | 13003 | L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に |
| 11122 | 13004 | 記述されている、I<長さ 0 でマッチング> フラグもリセットされます。 |
| 11123 | 13005 | |
| 11124 | 13006 | =begin original |
| 11125 | 13007 | |
| 11126 | 13008 | Because a failed C<m//gc> match doesn't reset the offset, the return |
| 11127 | from C<pos> won't change either in this case. See | |
| 13009 | from L<C<pos>|/pos SCALAR> won't change either in this case. See | |
| 11128 | L<perlop>. | |
| 13010 | L<perlre> and L<perlop>. | |
| 11129 | 13011 | |
| 11130 | 13012 | =end original |
| 11131 | 13013 | |
| 11132 | 13014 | C<m//gc> マッチに失敗してもオフセットはリセットしないので、 |
| 11133 | C<pos> からの返り値はどちらの場合も変更されません。 | |
| 13015 | L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。 | |
| 11134 | 13016 | L<perlre> と L<perlop> を参照してください。 |
| 11135 | 13017 | |
| 11136 | 13018 | =item print FILEHANDLE LIST |
| 11137 | 13019 | X<print> |
| 11138 | 13020 | |
| 11139 | 13021 | =item print FILEHANDLE |
| 11140 | 13022 | |
| 11141 | 13023 | =item print LIST |
| 11142 | 13024 | |
| 11143 | 13025 | =item print |
| 11144 | 13026 | |
| 11145 | 13027 | =for Pod::Functions output a list to a filehandle |
| 11146 | 13028 | |
| 11147 | 13029 | =begin original |
| 11148 | 13030 | |
| 11149 | 13031 | Prints a string or a list of strings. Returns true if successful. |
| 11150 | 13032 | FILEHANDLE may be a scalar variable containing the name of or a reference |
| 11151 | 13033 | to the filehandle, thus introducing one level of indirection. (NOTE: If |
| 11152 | 13034 | FILEHANDLE is a variable and the next token is a term, it may be |
| 11153 | 13035 | misinterpreted as an operator unless you interpose a C<+> or put |
| 11154 | 13036 | parentheses around the arguments.) If FILEHANDLE is omitted, prints to the |
| 11155 | last selected (see L</select>) output handle. If | |
| 13037 | last selected (see L<C<select>|/select FILEHANDLE>) output handle. If | |
| 11156 | C<$_> to the currently selected | |
| 13038 | LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected | |
| 11157 | p | |
| 13039 | output handle. To use FILEHANDLE alone to print the content of | |
| 13040 | L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like | |
| 11158 | 13041 | C<FH>, not an indirect one like C<$fh>. To set the default output handle |
| 11159 | 13042 | to something other than STDOUT, use the select operation. |
| 11160 | 13043 | |
| 11161 | 13044 | =end original |
| 11162 | 13045 | |
| 11163 | 13046 | 文字列か文字列のリストを出力します。 |
| 11164 | 13047 | 成功時には真を返します。 |
| 11165 | 13048 | FILEHANDLE は、ファイルハンドル名またはそのリファレンスが |
| 11166 | 13049 | 入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。 |
| 11167 | 13050 | (注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、 |
| 11168 | 13051 | 間に C<+> を置くか、引数の前後を括弧で括らなければ、 |
| 11169 | 13052 | 誤って解釈されることがあります。) |
| 11170 | FILEHANDLE を省略した場合には、最後に選択された | |
| 13053 | FILEHANDLE を省略した場合には、最後に選択された | |
| 11171 | チャネルに出力します。 | |
| 13054 | (L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。 | |
| 11172 | LIST を省略すると、C<$_> が現在選択されている出力ハンドルに | |
| 13055 | LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに | |
| 11173 | ||
| 13056 | 出力されます。 | |
| 11174 | C<$ | |
| 13057 | L<C<$_>|perlvar/$_> の内容を表示するために FILEHANDLE のみを使用するには、 | |
| 13058 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
| 11175 | 13059 | ファイルハンドルを使わなければなりません。 |
| 11176 | 13060 | デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を |
| 11177 | 13061 | 使ってください。 |
| 11178 | 13062 | |
| 11179 | 13063 | =begin original |
| 11180 | 13064 | |
| 11181 | The current value of C<$,> (if any) is printed between | |
| 13065 | The current value of L<C<$,>|perlvar/$,> (if any) is printed between | |
| 11182 | current value of C<$\> (if any) is | |
| 13066 | each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is | |
| 11183 | printed | |
| 13067 | printed after the entire LIST has been printed. Because print takes a | |
| 11184 | ||
| 13068 | LIST, anything in the LIST is evaluated in list context, including any | |
| 11185 | ||
| 13069 | subroutines whose return lists you pass to | |
| 13070 | L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print | |
| 13071 | keyword with a left | |
| 11186 | 13072 | parenthesis unless you want the corresponding right parenthesis to |
| 11187 | 13073 | terminate the arguments to the print; put parentheses around all arguments |
| 11188 | 13074 | (or interpose a C<+>, but that doesn't look as good). |
| 11189 | 13075 | |
| 11190 | 13076 | =end original |
| 11191 | 13077 | |
| 11192 | C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 | |
| 13078 | L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 | |
| 11193 | LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が | |
| 13079 | LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が | |
| 13080 | 出力されます。 | |
| 11194 | 13081 | print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで |
| 11195 | 評価されます; C<print> に渡した、リストを返す | |
| 13082 | 評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す | |
| 13083 | サブルーチンも含みます。 | |
| 11196 | 13084 | また、すべての引数を括弧で括るのでなければ、print というキーワードの |
| 11197 | 13085 | 次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください |
| 11198 | 13086 | (あるいは "print" と引数の間に C<+> を書きますが、これはあまり |
| 11199 | 13087 | よくありません)。 |
| 11200 | 13088 | |
| 11201 | 13089 | =begin original |
| 11202 | 13090 | |
| 11203 | 13091 | If you're storing handles in an array or hash, or in general whenever |
| 11204 | 13092 | you're using any expression more complex than a bareword handle or a plain, |
| 11205 | 13093 | unsubscripted scalar variable to retrieve it, you will have to use a block |
| 11206 | 13094 | returning the filehandle value instead, in which case the LIST may not be |
| 11207 | 13095 | omitted: |
| 11208 | 13096 | |
| 11209 | 13097 | =end original |
| 11210 | 13098 | |
| 11211 | 13099 | もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや |
| 11212 | 13100 | 普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す |
| 11213 | 13101 | ブロックを使う必要があります; この場合 LIST は省略できません: |
| 11214 | 13102 | |
| 11215 | 13103 | print { $files[$i] } "stuff\n"; |
| 11216 | print { $OK ? STDOUT : STDERR } "stuff\n"; | |
| 13104 | print { $OK ? *STDOUT : *STDERR } "stuff\n"; | |
| 11217 | 13105 | |
| 11218 | 13106 | =begin original |
| 11219 | 13107 | |
| 11220 | 13108 | Printing to a closed pipe or socket will generate a SIGPIPE signal. See |
| 11221 | 13109 | L<perlipc> for more on signal handling. |
| 11222 | 13110 | |
| 11223 | 13111 | =end original |
| 11224 | 13112 | |
| 11225 | 13113 | 閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。 |
| 11226 | 13114 | さらなるシグナル操作については L<perlipc> を参照してください。 |
| 11227 | 13115 | |
| 11228 | 13116 | =item printf FILEHANDLE FORMAT, LIST |
| 11229 | 13117 | X<printf> |
| 11230 | 13118 | |
| 11231 | 13119 | =item printf FILEHANDLE |
| 11232 | 13120 | |
| 11233 | 13121 | =item printf FORMAT, LIST |
| 11234 | 13122 | |
| 11235 | 13123 | =item printf |
| 11236 | 13124 | |
| 11237 | 13125 | =for Pod::Functions output a formatted list to a filehandle |
| 11238 | 13126 | |
| 11239 | 13127 | =begin original |
| 11240 | 13128 | |
| 11241 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that | |
| 13129 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that | |
| 11242 | (the output record separator) is not appended. T | |
| 13130 | L<C<$\>|perlvar/$\> (the output record separator) is not appended. The | |
| 11243 | LIST are actually parsed as a single list. The firs | |
| 13131 | FORMAT and the LIST are actually parsed as a single list. The first | |
| 11244 | of the list will be interpreted as the | |
| 13132 | argument of the list will be interpreted as the | |
| 11245 | ||
| 13133 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that | |
| 11246 | ||
| 13134 | C<printf(@_)> will use C<$_[0]> as the format. See | |
| 11247 | explanation of the format | |
| 13135 | L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format | |
| 11248 | C<use locale ':not_characters'>) | |
| 13136 | argument. If C<use locale> (including C<use locale ':not_characters'>) | |
| 11249 | POSIX::setlocale | |
| 13137 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been | |
| 11250 | ||
| 13138 | called, the character used for the decimal separator in formatted | |
| 11251 | lo | |
| 13139 | floating-point numbers is affected by the C<LC_NUMERIC> locale setting. | |
| 13140 | See L<perllocale> and L<POSIX>. | |
| 11252 | 13141 | |
| 11253 | 13142 | =end original |
| 11254 | 13143 | |
| 11255 | C<$\>(出力レコードセパレータ)を追加しないことを除けば、 | |
| 13144 | L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、 | |
| 11256 | 13145 | C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。 |
| 11257 | 13146 | FORMAT と LIST は実際には単一のリストとしてパースされます。 |
| 11258 | リストの最初の要素は、C<printf> | |
| 13147 | リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST> | |
| 13148 | フォーマットと解釈されます。 | |
| 11259 | 13149 | これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。 |
| 11260 | 13150 | フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を |
| 11261 | 13151 | 参照してください。 |
| 11262 | (C<use locale ':not_characters'> を含む) C<use locale> が効 | |
| 13152 | (C<use locale ':not_characters'> を含む) C<use locale> が有効で、 | |
| 11263 | POSIX::setlocale | |
| 13153 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、 | |
| 11264 | 小数点に使われる文字は LC_NUMERIC ロケール設定の影響を受けます。 | |
| 13154 | 小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。 | |
| 11265 | 13155 | L<perllocale> と L<POSIX> を参照してください。 |
| 11266 | 13156 | |
| 11267 | 13157 | =begin original |
| 11268 | 13158 | |
| 11269 | For historical reasons, if you omit the list, C<$_> | |
| 13159 | For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is | |
| 11270 | ||
| 13160 | used as the format; | |
| 13161 | to use FILEHANDLE without a list, you must use a bareword filehandle like | |
| 11271 | 13162 | C<FH>, not an indirect one like C<$fh>. However, this will rarely do what |
| 11272 | you want; if $_ contains formatting codes, they will b | |
| 13163 | you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be | |
| 11273 | empty string and a warning will be emitted if | |
| 13164 | replaced with the empty string and a warning will be emitted if | |
| 11274 | use C<print> | |
| 13165 | L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if | |
| 13166 | you want to print the contents of L<C<$_>|perlvar/$_>. | |
| 11275 | 13167 | |
| 11276 | 13168 | =end original |
| 11277 | 13169 | |
| 11278 | 歴史的な理由により、リストを省略すると、フォーマットとして | |
| 13170 | 歴史的な理由により、リストを省略すると、フォーマットとして | |
| 11279 | ||
| 13171 | L<C<$_>|perlvar/$_> が使われます; | |
| 11280 | ||
| 13172 | リストなしで FILEHANDLE を使用するには、C<$fh> のような | |
| 13173 | 間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
| 11281 | 13174 | ファイルハンドルを使わなければなりません。 |
| 11282 | 13175 | しかし、これがあなたが求めていることをすることはまれです; |
| 11283 | $_ がフォーマッティングコードの場合、空文字列に置き換えられ、 | |
| 13176 | L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、 | |
| 11284 | 警告が出力されます。 | |
| 13177 | L<warnings> が有効なら警告が出力されます。 | |
| 11285 | $_ の内容を表示したい場合は、単に | |
| 13178 | L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に | |
| 13179 | L<C<print>|/print FILEHANDLE LIST> を使ってください。 | |
| 11286 | 13180 | |
| 11287 | 13181 | =begin original |
| 11288 | 13182 | |
| 11289 | Don't fall into the trap of using a | |
| 13183 | Don't fall into the trap of using a | |
| 11290 | C<print> | |
| 13184 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple | |
| 11291 | ||
| 13185 | L<C<print>|/print FILEHANDLE LIST> would do. The | |
| 13186 | L<C<print>|/print FILEHANDLE LIST> is more efficient and less error | |
| 13187 | prone. | |
| 11292 | 13188 | |
| 11293 | 13189 | =end original |
| 11294 | 13190 | |
| 11295 | 単純な C<print> | |
| 13191 | 単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで | |
| 13192 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう | |
| 11296 | 13193 | 罠にかからないようにしてください。 |
| 11297 | C<print> はより効率的で、間違いが起こりにくいです。 | |
| 13194 | L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。 | |
| 11298 | 13195 | |
| 11299 | 13196 | =item prototype FUNCTION |
| 11300 | 13197 | X<prototype> |
| 11301 | 13198 | |
| 13199 | =item prototype | |
| 13200 | ||
| 11302 | 13201 | =for Pod::Functions +5.002 get the prototype (if any) of a subroutine |
| 11303 | 13202 | |
| 11304 | 13203 | =begin original |
| 11305 | 13204 | |
| 11306 | Returns the prototype of a function as a string (or | |
| 13205 | Returns the prototype of a function as a string (or | |
| 13206 | L<C<undef>|/undef EXPR> if the | |
| 11307 | 13207 | function has no prototype). FUNCTION is a reference to, or the name of, |
| 11308 | the function whose prototype you want to retrieve. | |
| 13208 | the function whose prototype you want to retrieve. If FUNCTION is omitted, | |
| 13209 | L<C<$_>|perlvar/$_> is used. | |
| 11309 | 13210 | |
| 11310 | 13211 | =end original |
| 11311 | 13212 | |
| 11312 | 13213 | 関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は |
| 11313 | C<undef> を返します)。 | |
| 13214 | L<C<undef>|/undef EXPR> を返します)。 | |
| 11314 | 13215 | FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。 |
| 13216 | FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。 | |
| 11315 | 13217 | |
| 11316 | 13218 | =begin original |
| 11317 | 13219 | |
| 11318 | 13220 | If FUNCTION is a string starting with C<CORE::>, the rest is taken as a |
| 11319 | 13221 | name for a Perl builtin. If the builtin's arguments |
| 11320 | 13222 | cannot be adequately expressed by a prototype |
| 11321 | (such as C<system>), prototype | |
| 13223 | (such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION> | |
| 13224 | returns L<C<undef>|/undef EXPR>, because the builtin | |
| 11322 | 13225 | does not really behave like a Perl function. Otherwise, the string |
| 11323 | 13226 | describing the equivalent prototype is returned. |
| 11324 | 13227 | |
| 11325 | 13228 | =end original |
| 11326 | 13229 | |
| 11327 | 13230 | FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として |
| 11328 | 13231 | 扱われます。 |
| 11329 | このビルドインの引数が(C<system> のように)プロトタイプとして | |
| 13232 | このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして | |
| 11330 | 記述できない場合、prototype | |
| 13233 | 適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は | |
| 13234 | L<C<undef>|/undef EXPR> を返します; | |
| 11331 | 13235 | なぜならビルドインは実際に Perl 関数のように振舞わないからです。 |
| 11332 | 13236 | それ以外では、等価なプロトタイプを表現した文字列が返されます。 |
| 11333 | 13237 | |
| 11334 | 13238 | =item push ARRAY,LIST |
| 11335 | 13239 | X<push> X<stack> |
| 11336 | 13240 | |
| 11337 | =item push EXPR,LIST | |
| 11338 | ||
| 11339 | 13241 | =for Pod::Functions append one or more elements to an array |
| 11340 | 13242 | |
| 11341 | 13243 | =begin original |
| 11342 | 13244 | |
| 11343 | ||
| 13245 | Adds one or more items to the B<end> of an array. | |
| 11344 | ARRAY. The length of ARRAY increases by the length of LIST. Has the same | |
| 11345 | effect as | |
| 11346 | 13246 | |
| 11347 | 13247 | =end original |
| 11348 | 13248 | |
| 11349 | ||
| 13249 | 一つまたは複数の要素を配列の B<末尾に> 追加します。 | |
| 11350 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。 | |
| 11351 | これは、 | |
| 11352 | 13250 | |
| 11353 | | |
| 13251 | my @animals = ("cat"); | |
| 11354 | | |
| 13252 | push(@animals, "mouse"); # ("cat", "mouse") | |
| 11355 | } | |
| 11356 | 13253 | |
| 13254 | my @colors = ("red"); | |
| 13255 | push(@colors, ("blue", "green")); # ("red", "blue", "green") | |
| 13256 | ||
| 11357 | 13257 | =begin original |
| 11358 | 13258 | |
| 11359 | ||
| 13259 | Returns the number of elements in the array following the completed | |
| 11360 | ||
| 13260 | L<C<push>|/push ARRAY,LIST>. | |
| 11361 | 13261 | |
| 11362 | 13262 | =end original |
| 11363 | 13263 | |
| 11364 | ||
| 13264 | L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。 | |
| 11365 | C<push> の処理終了後の配列の要素数を返します。 | |
| 11366 | 13265 | |
| 11367 | ||
| 13266 | my $color_count = push(@colors, ("yellow", "purple")); | |
| 11368 | 13267 | |
| 11369 | ||
| 13268 | say "There are $color_count colors in the updated array"; | |
| 11370 | reference to an unblessed array. The argument will be dereferenced | |
| 11371 | automatically. This aspect of C<push> is considered highly experimental. | |
| 11372 | The exact behaviour may change in a future version of Perl. | |
| 11373 | 13269 | |
| 11374 | =end original | |
| 11375 | ||
| 11376 | Perl 5.14 から、C<push> はスカラの EXPR を取ることができるようになりました; | |
| 11377 | これは bless されていない配列へのリファレンスでなければなりません。 | |
| 11378 | 引数は自動的にデリファレンスされます。 | |
| 11379 | C<push> のこの動作は高度に実験的であると考えられています。 | |
| 11380 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 11381 | ||
| 11382 | 13270 | =begin original |
| 11383 | 13271 | |
| 11384 | ||
| 13272 | Starting with Perl 5.14, an experimental feature allowed | |
| 11385 | ||
| 13273 | L<C<push>|/push ARRAY,LIST> to take a | |
| 11386 | ||
| 13274 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 11387 | ||
| 13275 | removed as of Perl 5.24. | |
| 11388 | 13276 | |
| 11389 | 13277 | =end original |
| 11390 | 13278 | |
| 11391 | ||
| 13279 | Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという | |
| 11392 | ||
| 13280 | 実験的機能がありました。 | |
| 11393 | ||
| 13281 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 11394 | 書いてください: | |
| 11395 | 13282 | |
| 11396 | use 5.014; # so push/pop/etc work on scalars (experimental) | |
| 11397 | ||
| 11398 | 13283 | =item q/STRING/ |
| 11399 | 13284 | |
| 11400 | 13285 | =for Pod::Functions singly quote a string |
| 11401 | 13286 | |
| 11402 | 13287 | =item qq/STRING/ |
| 11403 | 13288 | |
| 11404 | 13289 | =for Pod::Functions doubly quote a string |
| 11405 | 13290 | |
| 11406 | 13291 | =item qw/STRING/ |
| 11407 | 13292 | |
| 11408 | 13293 | =for Pod::Functions quote a list of words |
| 11409 | 13294 | |
| 11410 | 13295 | =item qx/STRING/ |
| 11411 | 13296 | |
| 11412 | 13297 | =for Pod::Functions backquote quote a string |
| 11413 | 13298 | |
| 11414 | 13299 | =begin original |
| 11415 | 13300 | |
| 11416 | 13301 | Generalized quotes. See L<perlop/"Quote-Like Operators">. |
| 11417 | 13302 | |
| 11418 | 13303 | =end original |
| 11419 | 13304 | |
| 11420 | 13305 | 汎用のクォートです。 |
| 11421 | 13306 | L<perlop/"Quote-Like Operators"> を参照してください。 |
| 11422 | 13307 | |
| 11423 | 13308 | =item qr/STRING/ |
| 11424 | 13309 | |
| 11425 | 13310 | =for Pod::Functions +5.005 compile pattern |
| 11426 | 13311 | |
| 11427 | 13312 | =begin original |
| 11428 | 13313 | |
| 11429 | 13314 | Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">. |
| 11430 | 13315 | |
| 11431 | 13316 | =end original |
| 11432 | 13317 | |
| 11433 | 13318 | 正規表現風のクォートです。 |
| 11434 | 13319 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
| 11435 | 13320 | |
| 11436 | 13321 | =item quotemeta EXPR |
| 11437 | 13322 | X<quotemeta> X<metacharacter> |
| 11438 | 13323 | |
| 11439 | 13324 | =item quotemeta |
| 11440 | 13325 | |
| 11441 | 13326 | =for Pod::Functions quote regular expression magic characters |
| 11442 | 13327 | |
| 11443 | 13328 | =begin original |
| 11444 | 13329 | |
| 11445 | 13330 | Returns the value of EXPR with all the ASCII non-"word" |
| 11446 | 13331 | characters backslashed. (That is, all ASCII characters not matching |
| 11447 | 13332 | C</[A-Za-z_0-9]/> will be preceded by a backslash in the |
| 11448 | 13333 | returned string, regardless of any locale settings.) |
| 11449 | 13334 | This is the internal function implementing |
| 11450 | 13335 | the C<\Q> escape in double-quoted strings. |
| 11451 | 13336 | (See below for the behavior on non-ASCII code points.) |
| 11452 | 13337 | |
| 11453 | 13338 | =end original |
| 11454 | 13339 | |
| 11455 | 13340 | EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで |
| 11456 | 13341 | エスケープしたものを返します。 |
| 11457 | 13342 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には |
| 11458 | 13343 | ロケールに関わらずバックスラッシュが前置されます。) |
| 11459 | 13344 | これは、ダブルクォート文字列での C<\Q> エスケープを実装するための |
| 11460 | 13345 | 内部関数です。 |
| 11461 | 13346 | (非 ASCII 符号位置での振る舞いについては以下を参照してください。) |
| 11462 | 13347 | |
| 11463 | 13348 | =begin original |
| 11464 | 13349 | |
| 11465 | If EXPR is omitted, uses C<$_>. | |
| 13350 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 11466 | 13351 | |
| 11467 | 13352 | =end original |
| 11468 | 13353 | |
| 11469 | EXPR が省略されると、C<$_> を使います。 | |
| 13354 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 11470 | 13355 | |
| 11471 | 13356 | =begin original |
| 11472 | 13357 | |
| 11473 | 13358 | quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into |
| 11474 | 13359 | regular expressions, because by default an interpolated variable will be |
| 11475 | 13360 | considered a mini-regular expression. For example: |
| 11476 | 13361 | |
| 11477 | 13362 | =end original |
| 11478 | 13363 | |
| 11479 | 13364 | クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに |
| 11480 | 13365 | 便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として |
| 11481 | 13366 | 扱われるからです。 |
| 11482 | 13367 | 例えば: |
| 11483 | 13368 | |
| 11484 | 13369 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
| 11485 | 13370 | my $substring = 'quick.*?fox'; |
| 11486 | 13371 | $sentence =~ s{$substring}{big bad wolf}; |
| 11487 | 13372 | |
| 11488 | 13373 | =begin original |
| 11489 | 13374 | |
| 11490 | 13375 | Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>. |
| 11491 | 13376 | |
| 11492 | 13377 | =end original |
| 11493 | 13378 | |
| 11494 | 13379 | とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。 |
| 11495 | 13380 | |
| 11496 | 13381 | =begin original |
| 11497 | 13382 | |
| 11498 | 13383 | On the other hand: |
| 11499 | 13384 | |
| 11500 | 13385 | =end original |
| 11501 | 13386 | |
| 11502 | 13387 | 一方: |
| 11503 | 13388 | |
| 11504 | 13389 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
| 11505 | 13390 | my $substring = 'quick.*?fox'; |
| 11506 | 13391 | $sentence =~ s{\Q$substring\E}{big bad wolf}; |
| 11507 | 13392 | |
| 11508 | 13393 | =begin original |
| 11509 | 13394 | |
| 11510 | 13395 | Or: |
| 11511 | 13396 | |
| 11512 | 13397 | =end original |
| 11513 | 13398 | |
| 11514 | 13399 | あるいは: |
| 11515 | 13400 | |
| 11516 | 13401 | my $sentence = 'The quick brown fox jumped over the lazy dog'; |
| 11517 | 13402 | my $substring = 'quick.*?fox'; |
| 11518 | 13403 | my $quoted_substring = quotemeta($substring); |
| 11519 | 13404 | $sentence =~ s{$quoted_substring}{big bad wolf}; |
| 11520 | 13405 | |
| 11521 | 13406 | =begin original |
| 11522 | 13407 | |
| 11523 | 13408 | Will both leave the sentence as is. |
| 11524 | Normally, when accepting literal string | |
| 13409 | Normally, when accepting literal string input from the user, | |
| 11525 | ||
| 13410 | L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used. | |
| 11526 | 13411 | |
| 11527 | 13412 | =end original |
| 11528 | 13413 | |
| 11529 | 13414 | とすると、両方ともそのままです。 |
| 11530 | 13415 | 普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、 |
| 11531 | 必ず quotemeta | |
| 13416 | 必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。 | |
| 11532 | 13417 | |
| 11533 | 13418 | =begin original |
| 11534 | 13419 | |
| 13420 | Beware that if you put literal backslashes (those not inside | |
| 13421 | interpolated variables) between C<\Q> and C<\E>, double-quotish | |
| 13422 | backslash interpolation may lead to confusing results. If you | |
| 13423 | I<need> to use literal backslashes within C<\Q...\E>, | |
| 13424 | consult L<perlop/"Gory details of parsing quoted constructs">. | |
| 13425 | ||
| 13426 | =end original | |
| 13427 | ||
| 13428 | リテラルな逆スラッシュ (変数置換の中でないもの) を C<\Q> と C<\E> の間に | |
| 13429 | 置くと、ダブルクォート風逆スラッシュ変数置換は混乱した結果を | |
| 13430 | 引き起こすことがあることに注意してください。 | |
| 13431 | C<\Q...\E> の中でリテラルな逆スラッシュを使うことが I<必要> なら、 | |
| 13432 | L<perlop/"Gory details of parsing quoted constructs"> を参照してください。 | |
| 13433 | ||
| 13434 | =begin original | |
| 13435 | ||
| 13436 | Because the result of S<C<"\Q I<STRING> \E">> has all metacharacters | |
| 13437 | quoted, there is no way to insert a literal C<$> or C<@> inside a | |
| 13438 | C<\Q\E> pair. If protected by C<\>, C<$> will be quoted to become | |
| 13439 | C<"\\\$">; if not, it is interpreted as the start of an interpolated | |
| 13440 | scalar. | |
| 13441 | ||
| 13442 | =end original | |
| 13443 | ||
| 13444 | S<C<"\Q I<STRING> \E">> の結果では全てのメタ文字がクォートされているので、 | |
| 13445 | C<\Q\E> の組の中にリテラルな C<$> や C<@> を挿入する方法はありません。 | |
| 13446 | C<\> で保護すると、C<$> は C<"\\\$"> になってクォートされます; | |
| 13447 | 保護しないと、変数展開されるスカラの開始として解釈されます。 | |
| 13448 | ||
| 13449 | =begin original | |
| 13450 | ||
| 11535 | 13451 | In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded |
| 11536 | 13452 | strings, but not quoted in UTF-8 strings. |
| 11537 | 13453 | |
| 11538 | 13454 | =end original |
| 11539 | 13455 | |
| 11540 | 13456 | Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた |
| 11541 | 13457 | 文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。 |
| 11542 | 13458 | |
| 11543 | 13459 | =begin original |
| 11544 | 13460 | |
| 11545 | 13461 | Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for |
| 11546 | 13462 | quoting non-ASCII characters; the quoting of ASCII characters is |
| 11547 | 13463 | unchanged. |
| 11548 | 13464 | |
| 11549 | 13465 | =end original |
| 11550 | 13466 | |
| 11551 | 13467 | Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で |
| 11552 | 13468 | 定義された戦略を採用しました; ASCII 文字のクォートは変わりません。 |
| 11553 | 13469 | |
| 11554 | 13470 | =begin original |
| 11555 | 13471 | |
| 11556 | 13472 | Also unchanged is the quoting of non-UTF-8 strings when outside the |
| 11557 | scope of a | |
| 13473 | scope of a | |
| 13474 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>, | |
| 13475 | which is to quote all | |
| 11558 | 13476 | characters in the upper Latin1 range. This provides complete backwards |
| 11559 | 13477 | compatibility for old programs which do not use Unicode. (Note that |
| 11560 | 13478 | C<unicode_strings> is automatically enabled within the scope of a |
| 11561 | 13479 | S<C<use v5.12>> or greater.) |
| 11562 | 13480 | |
| 11563 | 13481 | =end original |
| 11564 | 13482 | |
| 11565 | また、 | |
| 13483 | また、 | |
| 11566 | ||
| 13484 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の | |
| 11567 | クォート | |
| 13485 | 範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の | |
| 11568 | ||
| 13486 | 全ての文字をクォートします。 | |
| 11569 | 提供します。 | |
| 13487 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。 | |
| 11570 | 13488 | (C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは |
| 11571 | 13489 | 自動的に有効になることに注意してください。) |
| 11572 | 13490 | |
| 11573 | 13491 | =begin original |
| 11574 | 13492 | |
| 11575 | Within the scope of C<use locale>, all non-ASCII Latin1 code | |
| 13493 | Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code | |
| 13494 | points | |
| 11576 | 13495 | are quoted whether the string is encoded as UTF-8 or not. As mentioned |
| 11577 | 13496 | above, locale does not affect the quoting of ASCII-range characters. |
| 11578 | 13497 | This protects against those locales where characters such as C<"|"> are |
| 11579 | 13498 | considered to be word characters. |
| 11580 | 13499 | |
| 11581 | 13500 | =end original |
| 11582 | 13501 | |
| 11583 | C<use locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は | |
| 13502 | L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は | |
| 11584 | 13503 | 文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。 |
| 11585 | 13504 | 上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。 |
| 11586 | 13505 | これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。 |
| 11587 | 13506 | |
| 11588 | 13507 | =begin original |
| 11589 | 13508 | |
| 11590 | 13509 | Otherwise, Perl quotes non-ASCII characters using an adaptation from |
| 11591 | Unicode (see L<http://www.unicode.org/reports/tr31/>). | |
| 13510 | Unicode (see L<https://www.unicode.org/reports/tr31/>). | |
| 11592 | 13511 | The only code points that are quoted are those that have any of the |
| 11593 | 13512 | Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space, |
| 11594 | 13513 | Default_Ignorable_Code_Point, or General_Category=Control. |
| 11595 | 13514 | |
| 11596 | 13515 | =end original |
| 11597 | 13516 | |
| 11598 | 13517 | さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします |
| 11599 | (L<http://www.unicode.org/reports/tr31/> 参照)。 | |
| 13518 | (L<https://www.unicode.org/reports/tr31/> 参照)。 | |
| 11600 | 13519 | クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです: |
| 11601 | 13520 | Pattern_Syntax, Pattern_White_Space, White_Space, |
| 11602 | 13521 | Default_Ignorable_Code_Point, or General_Category=Control。 |
| 11603 | 13522 | |
| 11604 | 13523 | =begin original |
| 11605 | 13524 | |
| 11606 | 13525 | Of these properties, the two important ones are Pattern_Syntax and |
| 11607 | 13526 | Pattern_White_Space. They have been set up by Unicode for exactly this |
| 11608 | 13527 | purpose of deciding which characters in a regular expression pattern |
| 11609 | 13528 | should be quoted. No character that can be in an identifier has these |
| 11610 | 13529 | properties. |
| 11611 | 13530 | |
| 11612 | 13531 | =end original |
| 11613 | 13532 | |
| 11614 | 13533 | これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。 |
| 11615 | 13534 | これらはまさに正規表現中パターン中のどの文字をクォートするべきかを |
| 11616 | 13535 | 決定するという目的のために Unicode によって設定されています。 |
| 11617 | 13536 | 識別子になる文字はこれらの特性はありません。 |
| 11618 | 13537 | |
| 11619 | 13538 | =begin original |
| 11620 | 13539 | |
| 11621 | 13540 | Perl promises, that if we ever add regular expression pattern |
| 11622 | 13541 | metacharacters to the dozen already defined |
| 11623 | 13542 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the |
| 11624 | 13543 | Pattern_Syntax property. Perl also promises, that if we ever add |
| 11625 | 13544 | characters that are considered to be white space in regular expressions |
| 11626 | 13545 | (currently mostly affected by C</x>), they will all have the |
| 11627 | 13546 | Pattern_White_Space property. |
| 11628 | 13547 | |
| 11629 | 13548 | =end original |
| 11630 | 13549 | |
| 11631 | 13550 | Perl は、正規表現メタ文字として既に定義されている |
| 11632 | 13551 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、 |
| 11633 | 13552 | Pattern_Syntax 特性を持つものだけを使うことを約束します。 |
| 11634 | 13553 | Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と |
| 11635 | 13554 | 考えられる文字に追加するときは、Pattern_White_Space 特性を |
| 11636 | 13555 | 持つものであることを約束します。 |
| 11637 | 13556 | |
| 11638 | 13557 | =begin original |
| 11639 | 13558 | |
| 11640 | 13559 | Unicode promises that the set of code points that have these two |
| 11641 | 13560 | properties will never change, so something that is not quoted in v5.16 |
| 11642 | 13561 | will never need to be quoted in any future Perl release. (Not all the |
| 11643 | 13562 | code points that match Pattern_Syntax have actually had characters |
| 11644 | 13563 | assigned to them; so there is room to grow, but they are quoted |
| 11645 | 13564 | whether assigned or not. Perl, of course, would never use an |
| 11646 | 13565 | unassigned code point as an actual metacharacter.) |
| 11647 | 13566 | |
| 11648 | 13567 | =end original |
| 11649 | 13568 | |
| 11650 | 13569 | Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを |
| 11651 | 13570 | 約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも |
| 11652 | 13571 | クォートする必要はありません。 |
| 11653 | 13572 | (Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている |
| 11654 | 13573 | 文字を持っているわけではありません; したがって拡張する余地がありますが、 |
| 11655 | 13574 | 割り当てられているかどうかに関わらずクォートされます。 |
| 11656 | 13575 | Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは |
| 11657 | 13576 | ありません。) |
| 11658 | 13577 | |
| 11659 | 13578 | =begin original |
| 11660 | 13579 | |
| 11661 | 13580 | Quoting characters that have the other 3 properties is done to enhance |
| 11662 | 13581 | the readability of the regular expression and not because they actually |
| 11663 | 13582 | need to be quoted for regular expression purposes (characters with the |
| 11664 | 13583 | White_Space property are likely to be indistinguishable on the page or |
| 11665 | 13584 | screen from those with the Pattern_White_Space property; and the other |
| 11666 | 13585 | two properties contain non-printing characters). |
| 11667 | 13586 | |
| 11668 | 13587 | =end original |
| 11669 | 13588 | |
| 11670 | 13589 | その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために |
| 11671 | 13590 | 行われ、実際には正規表現の目的でクォートする必要があるからではありません |
| 11672 | 13591 | (White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と |
| 11673 | 13592 | おそらく区別が付かないでしょう; そして残りの |
| 11674 | 13593 | 二つの特性は非表示文字を含んでいます). |
| 11675 | 13594 | |
| 11676 | 13595 | =item rand EXPR |
| 11677 | 13596 | X<rand> X<random> |
| 11678 | 13597 | |
| 11679 | 13598 | =item rand |
| 11680 | 13599 | |
| 11681 | 13600 | =for Pod::Functions retrieve the next pseudorandom number |
| 11682 | 13601 | |
| 11683 | 13602 | =begin original |
| 11684 | 13603 | |
| 11685 | 13604 | Returns a random fractional number greater than or equal to C<0> and less |
| 11686 | 13605 | than the value of EXPR. (EXPR should be positive.) If EXPR is |
| 11687 | 13606 | omitted, the value C<1> is used. Currently EXPR with the value C<0> is |
| 11688 | 13607 | also special-cased as C<1> (this was undocumented before Perl 5.8.0 |
| 11689 | 13608 | and is subject to change in future versions of Perl). Automatically calls |
| 11690 | C<srand> unless C<srand> has already been | |
| 13609 | L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been | |
| 13610 | called. See also L<C<srand>|/srand EXPR>. | |
| 11691 | 13611 | |
| 11692 | 13612 | =end original |
| 11693 | 13613 | |
| 11694 | 13614 | C<0> 以上 EXPR の値未満の小数の乱数値を返します。 |
| 11695 | 13615 | (EXPR は正の数である必要があります。) |
| 11696 | 13616 | EXPR が省略されると、C<1> が使われます。 |
| 11697 | 13617 | 現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます |
| 11698 | 13618 | (これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では |
| 11699 | 13619 | 変更される可能性があります)。 |
| 11700 | C<srand> が既に呼ばれている場合以外は、自動的に | |
| 13620 | L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に | |
| 11701 | 呼び出します。 | |
| 13621 | L<C<srand>|/srand EXPR> 関数を呼び出します。 | |
| 11702 | C<srand> も参照してください。 | |
| 13622 | L<C<srand>|/srand EXPR> も参照してください。 | |
| 11703 | 13623 | |
| 11704 | 13624 | =begin original |
| 11705 | 13625 | |
| 11706 | Apply C<int | |
| 13626 | Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR> | |
| 11707 | integers instead of random fractional numbers. For | |
| 13627 | if you want random integers instead of random fractional numbers. For | |
| 13628 | example, | |
| 11708 | 13629 | |
| 11709 | 13630 | =end original |
| 11710 | 13631 | |
| 11711 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 | |
| 13632 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 | |
| 11712 | 返された値に C<int | |
| 13633 | L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を | |
| 13634 | 適用してください。 | |
| 11713 | 13635 | 例えば: |
| 11714 | 13636 | |
| 11715 | 13637 | int(rand(10)) |
| 11716 | 13638 | |
| 11717 | 13639 | =begin original |
| 11718 | 13640 | |
| 11719 | 13641 | returns a random integer between C<0> and C<9>, inclusive. |
| 11720 | 13642 | |
| 11721 | 13643 | =end original |
| 11722 | 13644 | |
| 11723 | 13645 | これは C<0> から C<9> の値をランダムに返します。 |
| 11724 | 13646 | |
| 11725 | 13647 | =begin original |
| 11726 | 13648 | |
| 11727 | 13649 | (Note: If your rand function consistently returns numbers that are too |
| 11728 | 13650 | large or too small, then your version of Perl was probably compiled |
| 11729 | 13651 | with the wrong number of RANDBITS.) |
| 11730 | 13652 | |
| 11731 | 13653 | =end original |
| 11732 | 13654 | |
| 11733 | 13655 | (注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを |
| 11734 | 13656 | 返すようなら、お使いになっている Perl が、 |
| 11735 | 13657 | 良くない RANDBITS を使ってコンパイルされている可能性があります。) |
| 11736 | 13658 | |
| 11737 | 13659 | =begin original |
| 11738 | 13660 | |
| 11739 | B<C<rand | |
| 13661 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
| 11740 | 13662 | on it in security-sensitive situations.> As of this writing, a |
| 11741 | 13663 | number of third-party CPAN modules offer random number generators |
| 11742 | 13664 | intended by their authors to be cryptographically secure, |
| 11743 | 13665 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
| 11744 | 13666 | and L<Math::TrulyRandom>. |
| 11745 | 13667 | |
| 11746 | 13668 | =end original |
| 11747 | 13669 | |
| 11748 | B<C<rand | |
| 13670 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
| 11749 | 13671 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
| 11750 | 13672 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
| 11751 | 13673 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
| 11752 | 13674 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
| 11753 | 13675 | L<Math::TrulyRandom> などです。 |
| 11754 | 13676 | |
| 11755 | 13677 | =item read FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 11756 | 13678 | X<read> X<file, read> |
| 11757 | 13679 | |
| 11758 | 13680 | =item read FILEHANDLE,SCALAR,LENGTH |
| 11759 | 13681 | |
| 11760 | 13682 | =for Pod::Functions fixed-length buffered input from a filehandle |
| 11761 | 13683 | |
| 11762 | 13684 | =begin original |
| 11763 | 13685 | |
| 11764 | 13686 | Attempts to read LENGTH I<characters> of data into variable SCALAR |
| 11765 | 13687 | from the specified FILEHANDLE. Returns the number of characters |
| 11766 | 13688 | actually read, C<0> at end of file, or undef if there was an error (in |
| 11767 | the latter case C<$!> is also set). SCALAR will be grown | |
| 13689 | the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown | |
| 13690 | or shrunk | |
| 11768 | 13691 | so that the last character actually read is the last character of the |
| 11769 | 13692 | scalar after the read. |
| 11770 | 13693 | |
| 11771 | 13694 | =end original |
| 11772 | 13695 | |
| 11773 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の | |
| 13696 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを | |
| 11774 | ||
| 13697 | 読み込みます。 | |
| 11775 | 実際に読み込まれた文字数、 | |
| 13698 | 実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の | |
| 11776 | ||
| 13699 | いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。 | |
| 11777 | ||
| 13700 | SCALAR は伸び縮みするので、読み込み後は、実際に読み込んだ最後の文字がスカラの | |
| 11778 | ||
| 13701 | 最後の文字になります。 | |
| 11779 | 読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。 | |
| 11780 | 13702 | |
| 11781 | 13703 | =begin original |
| 11782 | 13704 | |
| 11783 | 13705 | An OFFSET may be specified to place the read data at some place in the |
| 11784 | 13706 | string other than the beginning. A negative OFFSET specifies |
| 11785 | 13707 | placement at that many characters counting backwards from the end of |
| 11786 | 13708 | the string. A positive OFFSET greater than the length of SCALAR |
| 11787 | 13709 | results in the string being padded to the required size with C<"\0"> |
| 11788 | 13710 | bytes before the result of the read is appended. |
| 11789 | 13711 | |
| 11790 | 13712 | =end original |
| 11791 | 13713 | |
| 11792 | OFFSET を指定すると、文字列の先頭以外の場所から | |
| 13714 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 | |
| 11793 | できます。 | |
| 11794 | 13715 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
| 11795 | 13716 | 位置を指定します。 |
| 11796 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
| 13717 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が | |
| 11797 | ||
| 13718 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 | |
| 11798 | パッディングされます。 | |
| 11799 | 13719 | |
| 11800 | 13720 | =begin original |
| 11801 | 13721 | |
| 11802 | 13722 | The call is implemented in terms of either Perl's or your system's native |
| 11803 | fread(3) library function | |
| 13723 | L<fread(3)> library function, via the L<PerlIO> layers applied to the | |
| 13724 | handle. To get a true L<read(2)> system call, see | |
| 11804 | 13725 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>. |
| 11805 | 13726 | |
| 11806 | 13727 | =end original |
| 11807 | 13728 | |
| 11808 | この関数は、Perl か システムの fread(3) ライブラリ関数を使って | |
| 13729 | この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って、 | |
| 11809 | ||
| 13730 | ハンドルに適用されている L<PerlIO> 層経由で実装されています。 | |
| 13731 | 本当の L<read(2)> システムコールを利用するには、 | |
| 11810 | 13732 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。 |
| 11811 | 13733 | |
| 11812 | 13734 | =begin original |
| 11813 | 13735 | |
| 11814 | 13736 | Note the I<characters>: depending on the status of the filehandle, |
| 11815 | 13737 | either (8-bit) bytes or characters are read. By default, all |
| 11816 | 13738 | filehandles operate on bytes, but for example if the filehandle has |
| 11817 | been opened with the C<:utf8> I/O layer (see | |
| 13739 | been opened with the C<:utf8> I/O layer (see | |
| 11818 | ||
| 13740 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> | |
| 11819 | ||
| 13741 | pragma), the I/O will operate on UTF8-encoded Unicode | |
| 13742 | characters, not bytes. Similarly for the C<:encoding> layer: | |
| 11820 | 13743 | in that case pretty much any characters can be read. |
| 11821 | 13744 | |
| 11822 | 13745 | =end original |
| 11823 | 13746 | |
| 11824 | 13747 | I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか |
| 11825 | 13748 | 文字が読み込まれます。 |
| 11826 | 13749 | デフォルトでは全てのファイルハンドルはバイトを処理しますが、 |
| 11827 | 例えばファイルハンドルが C<:utf8> I/O 層 | |
| 13750 | 例えばファイルハンドルが C<:utf8> I/O 層 | |
| 11828 | L<open> を参照してください) で | |
| 13751 | (L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください) で | |
| 13752 | 開かれた場合、I/O はバイトではなく、 | |
| 11829 | 13753 | UTF8 エンコードされた Unicode 文字を操作します。 |
| 11830 | C<:encoding> | |
| 13754 | C<:encoding> 層も同様です: | |
| 11831 | 13755 | この場合、ほとんど大体全ての文字が読み込めます。 |
| 11832 | 13756 | |
| 11833 | 13757 | =item readdir DIRHANDLE |
| 11834 | 13758 | X<readdir> |
| 11835 | 13759 | |
| 11836 | 13760 | =for Pod::Functions get a directory from a directory handle |
| 11837 | 13761 | |
| 11838 | 13762 | =begin original |
| 11839 | 13763 | |
| 11840 | Returns the next directory entry for a directory opened by | |
| 13764 | Returns the next directory entry for a directory opened by | |
| 13765 | L<C<opendir>|/opendir DIRHANDLE,EXPR>. | |
| 11841 | 13766 | If used in list context, returns all the rest of the entries in the |
| 11842 | 13767 | directory. If there are no more entries, returns the undefined value in |
| 11843 | 13768 | scalar context and the empty list in list context. |
| 11844 | 13769 | |
| 11845 | 13770 | =end original |
| 11846 | 13771 | |
| 11847 | C<opendir> でオープンしたディレクトリで、 | |
| 13772 | L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の | |
| 11848 | ||
| 13773 | ディレクトリエントリを返します。 | |
| 11849 | リストコンテキストで用いると、 | |
| 13774 | リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて | |
| 11850 | ||
| 13775 | 返します。 | |
| 11851 | 13776 | エントリが残っていない場合には、スカラコンテキストでは未定義値を、 |
| 11852 | 13777 | リストコンテキストでは空リストを返します。 |
| 11853 | 13778 | |
| 11854 | 13779 | =begin original |
| 11855 | 13780 | |
| 11856 | If you're planning to filetest the return values out of a | |
| 13781 | If you're planning to filetest the return values out of a | |
| 11857 | better prepend the directory in | |
| 13782 | L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in | |
| 11858 | ||
| 13783 | question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there, | |
| 13784 | it would have been testing the wrong file. | |
| 11859 | 13785 | |
| 11860 | 13786 | =end original |
| 11861 | 13787 | |
| 11862 | C<readdir> の返り値をファイルテストに使おうと | |
| 13788 | L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと | |
| 11863 | 頭にディレクトリをつける必要があります。 | |
| 13789 | 計画しているなら、頭にディレクトリをつける必要があります。 | |
| 11864 | さもなければ、ここでは C<chdir> はしないので、 | |
| 13790 | さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、 | |
| 11865 | 13791 | 間違ったファイルをテストしてしまうことになるでしょう。 |
| 11866 | 13792 | |
| 11867 | opendir(my $dh, $some_dir) || die " | |
| 13793 | opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!"; | |
| 11868 | @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); | |
| 13794 | my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh); | |
| 11869 | 13795 | closedir $dh; |
| 11870 | 13796 | |
| 11871 | 13797 | =begin original |
| 11872 | 13798 | |
| 11873 | As of Perl 5.12 you can use a bare C<readdir> | |
| 13799 | As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a | |
| 11874 | which will set C<$_> on every iteration. | |
| 13800 | C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
| 13801 | If either a C<readdir> expression or an explicit assignment of a | |
| 13802 | C<readdir> expression to a scalar is used as a C<while>/C<for> condition, | |
| 13803 | then the condition actually tests for definedness of the expression's | |
| 13804 | value, not for its regular truth value. | |
| 11875 | 13805 | |
| 11876 | 13806 | =end original |
| 11877 | 13807 | |
| 11878 | Perl 5.12 から裸の C<readdir> を C<while> で | |
| 13808 | Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で | |
| 11879 | この場合繰り返し毎に C<$_> にセットされます。 | |
| 13809 | 使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。 | |
| 13810 | C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が | |
| 13811 | C<while>/C<for> の条件部として使われた場合、 | |
| 13812 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 13813 | テストします。 | |
| 11880 | 13814 | |
| 11881 | opendir(my $dh, $some_dir) || die; | |
| 13815 | opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!"; | |
| 11882 | while(readdir $dh) { | |
| 13816 | while (readdir $dh) { | |
| 11883 | 13817 | print "$some_dir/$_\n"; |
| 11884 | 13818 | } |
| 11885 | 13819 | closedir $dh; |
| 11886 | 13820 | |
| 11887 | 13821 | =begin original |
| 11888 | 13822 | |
| 11889 | 13823 | To avoid confusing would-be users of your code who are running earlier |
| 11890 | 13824 | versions of Perl with mysterious failures, put this sort of thing at the |
| 11891 | 13825 | top of your file to signal that your code will work I<only> on Perls of a |
| 11892 | 13826 | recent vintage: |
| 11893 | 13827 | |
| 11894 | 13828 | =end original |
| 11895 | 13829 | |
| 11896 | 13830 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
| 11897 | 13831 | 失敗で混乱することを避けるために、コードが最近のバージョンの Perl で |
| 11898 | 13832 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
| 11899 | 13833 | 書いてください: |
| 11900 | 13834 | |
| 11901 | use 5. | |
| 13835 | use v5.12; # so readdir assigns to $_ in a lone while test | |
| 11902 | 13836 | |
| 11903 | 13837 | =item readline EXPR |
| 11904 | 13838 | |
| 11905 | 13839 | =item readline |
| 11906 | 13840 | X<readline> X<gets> X<fgets> |
| 11907 | 13841 | |
| 11908 | 13842 | =for Pod::Functions fetch a record from a file |
| 11909 | 13843 | |
| 11910 | 13844 | =begin original |
| 11911 | 13845 | |
| 11912 | 13846 | Reads from the filehandle whose typeglob is contained in EXPR (or from |
| 11913 | 13847 | C<*ARGV> if EXPR is not provided). In scalar context, each call reads and |
| 11914 | 13848 | returns the next line until end-of-file is reached, whereupon the |
| 11915 | subsequent call returns C<undef>. In list context, reads | |
| 13849 | subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads | |
| 11916 | is reached and returns a list of lines. Note that the | |
| 13850 | until end-of-file is reached and returns a list of lines. Note that the | |
| 11917 | used here is whatever you may have defined with | |
| 13851 | notion of "line" used here is whatever you may have defined with | |
| 11918 | C<$INPUT_RECORD_SEPARATOR> | |
| 13852 | L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in | |
| 13853 | L<English>). See L<perlvar/"$/">. | |
| 11919 | 13854 | |
| 11920 | 13855 | =end original |
| 11921 | 13856 | |
| 11922 | 13857 | 型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている |
| 11923 | 13858 | ファイルハンドルから読み込みます。 |
| 11924 | 13859 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの |
| 11925 | 最後まで読み込んだら、以後の呼び出しでは C<undef> を返します。 | |
| 13860 | 最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。 | |
| 11926 | 13861 | リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。 |
| 11927 | ここでの「行」とは、C<$/> または | |
| 13862 | ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または | |
| 13863 | L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で | |
| 11928 | 13864 | 定義されることに注意してください。 |
| 11929 | 13865 | L<perlvar/"$/"> を参照してください。 |
| 11930 | 13866 | |
| 11931 | 13867 | =begin original |
| 11932 | 13868 | |
| 11933 | When C<$/> is set to C<undef> | |
| 13869 | When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>, | |
| 11934 | ||
| 13870 | when L<C<readline>|/readline EXPR> is in scalar context (i.e., file | |
| 11935 | returns C<''> the first | |
| 13871 | slurp mode), and when an empty file is read, it returns C<''> the first | |
| 13872 | time, followed by L<C<undef>|/undef EXPR> subsequently. | |
| 11936 | 13873 | |
| 11937 | 13874 | =end original |
| 11938 | 13875 | |
| 11939 | C<$/> に C<undef> を設定した場合は、 | |
| 13876 | L<C<$E<sol>>|perlvar/$E<sol>> に L<C<undef>|/undef EXPR> を設定した場合は、 | |
| 11940 | (つまりファイル吸い込み | |
| 13877 | L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み | |
| 11941 | 空のファイルを読み込んだ場合は、最初は C<''> を返し、 | |
| 13878 | モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、 | |
| 11942 | それ以降は C<undef> を返します。 | |
| 13879 | それ以降は L<C<undef>|/undef EXPR> を返します。 | |
| 11943 | 13880 | |
| 11944 | 13881 | =begin original |
| 11945 | 13882 | |
| 11946 | 13883 | This is the internal function implementing the C<< <EXPR> >> |
| 11947 | 13884 | operator, but you can use it directly. The C<< <EXPR> >> |
| 11948 | 13885 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
| 11949 | 13886 | |
| 11950 | 13887 | =end original |
| 11951 | 13888 | |
| 11952 | 13889 | これは C<< <EXPR> >> 演算子を実装している内部関数ですが、 |
| 11953 | 13890 | 直接使うこともできます。 |
| 11954 | 13891 | C<< <EXPR> >> 演算子についてのさらなる詳細については |
| 11955 | 13892 | L<perlop/"I/O Operators"> で議論されています。 |
| 11956 | 13893 | |
| 11957 | $line = <STDIN>; | |
| 13894 | my $line = <STDIN>; | |
| 11958 | $line = readline( | |
| 13895 | my $line = readline(STDIN); # same thing | |
| 11959 | 13896 | |
| 11960 | 13897 | =begin original |
| 11961 | 13898 | |
| 11962 | If C<readline> encounters an operating system error, | |
| 13899 | If L<C<readline>|/readline EXPR> encounters an operating system error, | |
| 11963 | with the corresponding error message. | |
| 13900 | L<C<$!>|perlvar/$!> will be set with the corresponding error message. | |
| 11964 | C<$!> when you are reading from | |
| 13901 | It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from | |
| 11965 | tty or a socket. The following | |
| 13902 | filehandles you don't trust, such as a tty or a socket. The following | |
| 11966 | ||
| 13903 | example uses the operator form of L<C<readline>|/readline EXPR> and dies | |
| 13904 | if the result is not defined. | |
| 11967 | 13905 | |
| 11968 | 13906 | =end original |
| 11969 | 13907 | |
| 11970 | C<readline> が OS のシステムエラーになると、 | |
| 13908 | L<C<readline>|/readline EXPR> が OS のシステムエラーになると、 | |
| 11971 | セットされます。 | |
| 13909 | L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。 | |
| 11972 | 13910 | tty やソケットといった、信頼できないファイルハンドルから読み込む時には |
| 11973 | C<$!> をチェックするのが助けになります。 | |
| 13911 | L<C<$!>|perlvar/$!> をチェックするのが助けになります。 | |
| 11974 | 以下の例は演算子の形の C<readline> を使っており、結果が | |
| 13912 | 以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が | |
| 11975 | 13913 | 未定義の場合は die します。 |
| 11976 | 13914 | |
| 11977 | 13915 | while ( ! eof($fh) ) { |
| 11978 | defined( $_ = | |
| 13916 | defined( $_ = readline $fh ) or die "readline failed: $!"; | |
| 11979 | 13917 | ... |
| 11980 | 13918 | } |
| 11981 | 13919 | |
| 11982 | 13920 | =begin original |
| 11983 | 13921 | |
| 11984 | Note that you | |
| 13922 | Note that you can't handle L<C<readline>|/readline EXPR> errors | |
| 11985 | C<ARGV> filehandle. In that case, you have to open | |
| 13923 | that way with the C<ARGV> filehandle. In that case, you have to open | |
| 11986 | C<@ARGV> yourself since | |
| 13924 | each element of L<C<@ARGV>|perlvar/@ARGV> yourself since | |
| 13925 | L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently. | |
| 11987 | 13926 | |
| 11988 | 13927 | =end original |
| 11989 | 13928 | |
| 11990 | C<readline> のエラーは C<ARGV> ファイルハンドルの方法では | |
| 13929 | L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では | |
| 11991 | 注意してください。 | |
| 13930 | 扱えないことに注意してください。 | |
| 11992 | この場合、C<eof> は C<ARGV> を異なった方法で扱うので、 | |
| 13931 | この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、 | |
| 11993 | C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。 | |
| 13932 | L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。 | |
| 11994 | 13933 | |
| 11995 | 13934 | foreach my $arg (@ARGV) { |
| 11996 | 13935 | open(my $fh, $arg) or warn "Can't open $arg: $!"; |
| 11997 | 13936 | |
| 11998 | 13937 | while ( ! eof($fh) ) { |
| 11999 | defined( $_ = | |
| 13938 | defined( $_ = readline $fh ) | |
| 12000 | 13939 | or die "readline failed for $arg: $!"; |
| 12001 | 13940 | ... |
| 12002 | 13941 | } |
| 12003 | 13942 | } |
| 12004 | 13943 | |
| 13944 | =begin original | |
| 13945 | ||
| 13946 | Like the C<< <EXPR> >> operator, if a C<readline> expression is | |
| 13947 | used as the condition of a C<while> or C<for> loop, then it will be | |
| 13948 | implicitly assigned to C<$_>. If either a C<readline> expression or | |
| 13949 | an explicit assignment of a C<readline> expression to a scalar is used | |
| 13950 | as a C<while>/C<for> condition, then the condition actually tests for | |
| 13951 | definedness of the expression's value, not for its regular truth value. | |
| 13952 | ||
| 13953 | =end original | |
| 13954 | ||
| 13955 | C<< <EXPR> >> 演算子と同様、 | |
| 13956 | C<readline> 式が C<while> や C<for> ループの条件として使われた場合、 | |
| 13957 | これは暗黙に C<$_> に代入されます。 | |
| 13958 | C<readline> 式または C<readline> 式からスカラへの明示的な代入が | |
| 13959 | C<while>/C<for> の条件部として使われた場合、 | |
| 13960 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 13961 | テストします。 | |
| 13962 | ||
| 12005 | 13963 | =item readlink EXPR |
| 12006 | 13964 | X<readlink> |
| 12007 | 13965 | |
| 12008 | 13966 | =item readlink |
| 12009 | 13967 | |
| 12010 | 13968 | =for Pod::Functions determine where a symbolic link is pointing |
| 12011 | 13969 | |
| 12012 | 13970 | =begin original |
| 12013 | 13971 | |
| 12014 | 13972 | Returns the value of a symbolic link, if symbolic links are |
| 12015 | 13973 | implemented. If not, raises an exception. If there is a system |
| 12016 | error, returns the undefined value and sets C<$!> (errno). | |
| 13974 | error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno). | |
| 12017 | omitted, uses C<$_>. | |
| 13975 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 12018 | 13976 | |
| 12019 | 13977 | =end original |
| 12020 | 13978 | |
| 12021 | シンボリックリンクが実装されていれば、 | |
| 13979 | シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。 | |
| 12022 | シンボリックリンクの値を返します。 | |
| 12023 | 13980 | 実装されていないときには、例外が発生します。 |
| 12024 | 13981 | 何らかのシステムエラーが検出されると、未定義値を返し、 |
| 12025 | C<$!> (errno) を設定します。 | |
| 13982 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 12026 | EXPR が省略されると、C<$_> を使います。 | |
| 13983 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 12027 | 13984 | |
| 12028 | 13985 | =begin original |
| 12029 | 13986 | |
| 12030 | 13987 | Portability issues: L<perlport/readlink>. |
| 12031 | 13988 | |
| 12032 | 13989 | =end original |
| 12033 | 13990 | |
| 12034 | 13991 | 移植性の問題: L<perlport/readlink>。 |
| 12035 | 13992 | |
| 12036 | 13993 | =item readpipe EXPR |
| 12037 | 13994 | |
| 12038 | 13995 | =item readpipe |
| 12039 | 13996 | X<readpipe> |
| 12040 | 13997 | |
| 12041 | 13998 | =for Pod::Functions execute a system command and collect standard output |
| 12042 | 13999 | |
| 12043 | 14000 | =begin original |
| 12044 | 14001 | |
| 12045 | 14002 | EXPR is executed as a system command. |
| 12046 | 14003 | The collected standard output of the command is returned. |
| 12047 | 14004 | In scalar context, it comes back as a single (potentially |
| 12048 | 14005 | multi-line) string. In list context, returns a list of lines |
| 12049 | (however you've defined lines with C<$ | |
| 14006 | (however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or | |
| 14007 | C<$INPUT_RECORD_SEPARATOR> in L<English>)). | |
| 12050 | 14008 | This is the internal function implementing the C<qx/EXPR/> |
| 12051 | 14009 | operator, but you can use it directly. The C<qx/EXPR/> |
| 12052 | operator is discussed in more detail in L<perlop/"I/ | |
| 14010 | operator is discussed in more detail in L<perlop/"C<qx/I<STRING>/>">. | |
| 12053 | If EXPR is omitted, uses C<$_>. | |
| 14011 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 12054 | 14012 | |
| 12055 | 14013 | =end original |
| 12056 | 14014 | |
| 12057 | 14015 | EXPR がシステムコマンドとして実行されます。 |
| 12058 | 14016 | コマンドの標準出力の内容が返されます。 |
| 12059 | 14017 | スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。 |
| 12060 | 14018 | リストコンテキストでは、行のリストを返します |
| 12061 | (但し、行は C<$/> または | |
| 14019 | (但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュールでは | |
| 12062 | ||
| 14020 | C<$INPUT_RECORD_SEPARATOR> で定義されます)。 | |
| 12063 | 直接使うことも出来ます。 | |
| 14021 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。 | |
| 12064 | C<qx/EXPR/> 演算子は L<perlop/"I/ | |
| 14022 | C<qx/EXPR/> 演算子は L<perlop/"C<qx/I<STRING>/>"> でより詳細に | |
| 12065 | 14023 | 述べられています。 |
| 12066 | EXPR が省略されると、C<$_> を使います。 | |
| 14024 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 12067 | 14025 | |
| 12068 | 14026 | =item recv SOCKET,SCALAR,LENGTH,FLAGS |
| 12069 | 14027 | X<recv> |
| 12070 | 14028 | |
| 12071 | 14029 | =for Pod::Functions receive a message over a Socket |
| 12072 | 14030 | |
| 12073 | 14031 | =begin original |
| 12074 | 14032 | |
| 12075 | 14033 | Receives a message on a socket. Attempts to receive LENGTH characters |
| 12076 | 14034 | of data into variable SCALAR from the specified SOCKET filehandle. |
| 12077 | 14035 | SCALAR will be grown or shrunk to the length actually read. Takes the |
| 12078 | 14036 | same flags as the system call of the same name. Returns the address |
| 12079 | 14037 | of the sender if SOCKET's protocol supports this; returns an empty |
| 12080 | 14038 | string otherwise. If there's an error, returns the undefined value. |
| 12081 | This call is actually implemented in terms of recvfrom(2) system call. | |
| 14039 | This call is actually implemented in terms of the L<recvfrom(2)> system call. | |
| 12082 | 14040 | See L<perlipc/"UDP: Message Passing"> for examples. |
| 12083 | 14041 | |
| 12084 | 14042 | =end original |
| 12085 | 14043 | |
| 12086 | 14044 | ソケット上のメッセージを受信します。 |
| 12087 | 14045 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に |
| 12088 | 14046 | LENGTH 文字のデータを読み込もうとします。 |
| 12089 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
| 14047 | SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。 | |
| 12090 | 小さくなったりします。 | |
| 12091 | 14048 | 同名のシステムコールと同じフラグが指定できます。 |
| 12092 | 14049 | SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。 |
| 12093 | 14050 | エラー発生時には、未定義値を返します。 |
| 12094 | 実際には、C のrecvfrom(2) を呼びます。 | |
| 14051 | 実際には、C の L<recvfrom(2)> を呼びます。 | |
| 12095 | 14052 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
| 12096 | 14053 | |
| 12097 | 14054 | =begin original |
| 12098 | 14055 | |
| 12099 | Note th | |
| 14056 | Note that if the socket has been marked as C<:utf8>, C<recv> will | |
| 12100 | ||
| 14057 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
| 12101 | ||
| 14058 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 12102 | binmode() to operate with the C<:encoding(utf8)> I/O layer (see the | |
| 12103 | C<open> pragma, L<open>), the I/O will operate on UTF8-encoded Unicode | |
| 12104 | characters, not bytes. Similarly for the C<:encoding> pragma: in that | |
| 12105 | case pretty much any characters can be read. | |
| 12106 | 14059 | |
| 12107 | 14060 | =end original |
| 12108 | 14061 | |
| 12109 | ||
| 14062 | ソケットが C<:utf8> としてマークされている場合、 | |
| 12110 | ||
| 14063 | C<recv> は例外を投げることに注意してください。 | |
| 12111 | ||
| 14064 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 12112 | ||
| 14065 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
| 12113 | L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく、 | |
| 12114 | UTF8 エンコードされた Unicode 文字を操作します。 | |
| 12115 | C<:encoding> プラグマも同様です: | |
| 12116 | この場合、ほとんど大体全ての文字が読み込めます。 | |
| 12117 | 14066 | |
| 12118 | 14067 | =item redo LABEL |
| 12119 | 14068 | X<redo> |
| 12120 | 14069 | |
| 12121 | 14070 | =item redo EXPR |
| 12122 | 14071 | |
| 12123 | 14072 | =item redo |
| 12124 | 14073 | |
| 12125 | 14074 | =for Pod::Functions start this loop iteration over again |
| 12126 | 14075 | |
| 12127 | 14076 | =begin original |
| 12128 | 14077 | |
| 12129 | The C<redo> command restarts the loop block without | |
| 14078 | The L<C<redo>|/redo LABEL> command restarts the loop block without | |
| 12130 | conditional again. The C<continue> | |
| 14079 | evaluating the conditional again. The L<C<continue>|/continue BLOCK> | |
| 14080 | block, if any, is not executed. If | |
| 12131 | 14081 | the LABEL is omitted, the command refers to the innermost enclosing |
| 12132 | 14082 | loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a |
| 12133 | 14083 | label name to be computed at run time, and is otherwise identical to C<redo |
| 12134 | LABEL>. Programs that want to lie to themselves about what was just input | |
| 14084 | LABEL>. Programs that want to lie to themselves about what was just input | |
| 12135 | 14085 | normally use this command: |
| 12136 | 14086 | |
| 12137 | 14087 | =end original |
| 12138 | 14088 | |
| 12139 | C<redo> コマンドは、条件を再評価しないで、ループブロックの | |
| 14089 | L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの | |
| 12140 | 実行を開始します。 | |
| 14090 | 始めからもう一度実行を開始します。 | |
| 12141 | C<continue> ブロックがあっても、実行されません。 | |
| 14091 | L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。 | |
| 12142 | 14092 | LABEL が省略されると、コマンドは一番内側のループを参照します。 |
| 12143 | 14093 | Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が |
| 12144 | 14094 | 使えます; それ以外は C<redo LABEL> と同一です。 |
| 12145 | 14095 | このコマンドは通常、自分への入力を欺くために使用します: |
| 12146 | 14096 | |
| 12147 | 14097 | # a simpleminded Pascal comment stripper |
| 12148 | 14098 | # (warning: assumes no { or } in strings) |
| 12149 | 14099 | LINE: while (<STDIN>) { |
| 12150 | 14100 | while (s|({.*}.*){.*}|$1 |) {} |
| 12151 | 14101 | s|{.*}| |; |
| 12152 | 14102 | if (s|{.*| |) { |
| 12153 | $front = $_; | |
| 14103 | my $front = $_; | |
| 12154 | 14104 | while (<STDIN>) { |
| 12155 | 14105 | if (/}/) { # end of comment? |
| 12156 | 14106 | s|^|$front\{|; |
| 12157 | 14107 | redo LINE; |
| 12158 | 14108 | } |
| 12159 | 14109 | } |
| 12160 | 14110 | } |
| 12161 | 14111 | print; |
| 12162 | 14112 | } |
| 12163 | 14113 | |
| 12164 | 14114 | =begin original |
| 12165 | 14115 | |
| 12166 | C<redo> cannot | |
| 14116 | L<C<redo>|/redo LABEL> cannot return a value from a block that typically | |
| 12167 | C<eval {}>, C<sub {}>, or C<do {}> | |
| 14117 | returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform | |
| 12168 | ||
| 14118 | its flow control behavior, which precludes any return value. It should not be | |
| 14119 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 14120 | operation. | |
| 12169 | 14121 | |
| 12170 | 14122 | =end original |
| 12171 | 14123 | |
| 12172 | C<redo> は C<eval {}>, C<sub {}>, C<do {}> | |
| 14124 | L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった | |
| 12173 | ブロックを | |
| 14125 | 典型的には値を返すブロックから値を返せません。 | |
| 14126 | これは、返り値を不可能にするフロー制御の振る舞いを実行します。 | |
| 14127 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 12174 | 14128 | 使うべきではありません。 |
| 12175 | 14129 | |
| 12176 | 14130 | =begin original |
| 12177 | 14131 | |
| 12178 | 14132 | Note that a block by itself is semantically identical to a loop |
| 12179 | that executes once. Thus C<redo> inside such a block | |
| 14133 | that executes once. Thus L<C<redo>|/redo LABEL> inside such a block | |
| 12180 | turn it into a looping construct. | |
| 14134 | will effectively turn it into a looping construct. | |
| 12181 | 14135 | |
| 12182 | 14136 | =end original |
| 12183 | 14137 | |
| 12184 | 14138 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
| 12185 | 14139 | 注意してください。 |
| 12186 | 従って、ブロックの中で C<redo> を使うことで効果的に | |
| 14140 | 従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に | |
| 12187 | 14141 | ループ構造に変換します。 |
| 12188 | 14142 | |
| 12189 | 14143 | =begin original |
| 12190 | 14144 | |
| 12191 | See also L</continue> for an illustration of how | |
| 14145 | See also L<C<continue>|/continue BLOCK> for an illustration of how | |
| 12192 | C< | |
| 14146 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and | |
| 14147 | L<C<redo>|/redo LABEL> work. | |
| 12193 | 14148 | |
| 12194 | 14149 | =end original |
| 12195 | 14150 | |
| 12196 | C<last>, C<next>, C<redo> が | |
| 14151 | L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が | |
| 12197 | L</continue> も参照してください。 | |
| 14152 | どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。 | |
| 12198 | 14153 | |
| 12199 | 14154 | =begin original |
| 12200 | 14155 | |
| 12201 | 14156 | Unlike most named operators, this has the same precedence as assignment. |
| 12202 | 14157 | It is also exempt from the looks-like-a-function rule, so |
| 12203 | 14158 | C<redo ("foo")."bar"> will cause "bar" to be part of the argument to |
| 12204 | C<redo>. | |
| 14159 | L<C<redo>|/redo LABEL>. | |
| 12205 | 14160 | |
| 12206 | 14161 | =end original |
| 12207 | 14162 | |
| 12208 | 14163 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 |
| 12209 | 14164 | また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と |
| 12210 | すると "bar" は C<redo> への引数の一部となります。 | |
| 14165 | すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。 | |
| 12211 | 14166 | |
| 12212 | 14167 | =item ref EXPR |
| 12213 | 14168 | X<ref> X<reference> |
| 12214 | 14169 | |
| 12215 | 14170 | =item ref |
| 12216 | 14171 | |
| 12217 | 14172 | =for Pod::Functions find out the type of thing being referenced |
| 12218 | 14173 | |
| 12219 | 14174 | =begin original |
| 12220 | 14175 | |
| 12221 | ||
| 14176 | Examines the value of EXPR, expecting it to be a reference, and returns | |
| 12222 | string other | |
| 14177 | a string giving information about the reference and the type of referent. | |
| 12223 | is not specified, C<$_> will be used. | |
| 14178 | If EXPR is not specified, L<C<$_>|perlvar/$_> will be used. | |
| 12224 | type of thing the reference is a reference to. | |
| 12225 | Builtin types include: | |
| 12226 | 14179 | |
| 12227 | 14180 | =end original |
| 12228 | 14181 | |
| 12229 | E | |
| 14182 | Examines the value of | |
| 12230 | ||
| 14183 | リファレンスと想定される EXPR の値を調べて、 | |
| 12231 | ||
| 14184 | そのリファレンスとリファレンス先の型に関する情報を表す | |
| 12232 | 返 | |
| 14185 | 文字列を返します。 | |
| 12233 | ||
| 14186 | EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。 | |
| 12234 | 14187 | |
| 12235 | SCALAR | |
| 12236 | ARRAY | |
| 12237 | HASH | |
| 12238 | CODE | |
| 12239 | REF | |
| 12240 | GLOB | |
| 12241 | LVALUE | |
| 12242 | FORMAT | |
| 12243 | IO | |
| 12244 | VSTRING | |
| 12245 | Regexp | |
| 12246 | ||
| 12247 | 14188 | =begin original |
| 12248 | 14189 | |
| 12249 | If the | |
| 14190 | If the operand is not a reference, then the empty string will be returned. | |
| 12250 | n | |
| 14191 | An empty string will only be returned in this situation. C<ref> is often | |
| 14192 | useful to just test whether a value is a reference, which can be done | |
| 14193 | by comparing the result to the empty string. It is a common mistake | |
| 14194 | to use the result of C<ref> directly as a truth value: this goes wrong | |
| 14195 | because C<0> (which is false) can be returned for a reference. | |
| 12251 | 14196 | |
| 12252 | 14197 | =end original |
| 12253 | 14198 | |
| 12254 | ||
| 14199 | オペランドがリファレンスでない場合、空文字列が返されます。 | |
| 12255 | ||
| 14200 | 空文字列はこの場合にのみ返されます。 | |
| 12256 | ||
| 14201 | 結果を空文字列を比較することでできるので、 | |
| 12257 | C<ref> は | |
| 14202 | C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。 | |
| 14203 | C<ref> の結果を直接真の値として使うのは良くある誤りです: | |
| 14204 | リファレンスの場合に (偽である) C<0> が返されることがあるので、 | |
| 14205 | これは誤りです。 | |
| 12258 | 14206 | |
| 12259 | ||
| 14207 | =begin original | |
| 12260 | print "r is a reference to a hash.\n"; | |
| 12261 | } | |
| 12262 | unless (ref($r)) { | |
| 12263 | print "r is not a reference at all.\n"; | |
| 12264 | } | |
| 12265 | 14208 | |
| 14209 | If the operand is a reference to a blessed object, then the name of | |
| 14210 | the class into which the referent is blessed will be returned. C<ref> | |
| 14211 | doesn't care what the physical type of the referent is; blessing takes | |
| 14212 | precedence over such concerns. Beware that exact comparison of C<ref> | |
| 14213 | results against a class name doesn't perform a class membership test: | |
| 14214 | a class's members also include objects blessed into subclasses, for | |
| 14215 | which C<ref> will return the name of the subclass. Also beware that | |
| 14216 | class names can clash with the built-in type names (described below). | |
| 14217 | ||
| 14218 | =end original | |
| 14219 | ||
| 14220 | オペランドが bless されたオブジェクトへのリファレンスの場合、 | |
| 14221 | リファレンス先が bless されているクラス名が返されます。 | |
| 14222 | C<ref> はリファレンス先の物理的な種類については気にしません; | |
| 14223 | bless されているかがそのような関心より優先されます。 | |
| 14224 | C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを | |
| 14225 | 実行しないことに注意してください: | |
| 14226 | C<ref> がサブクラスの名前を返す場合、 | |
| 14227 | あるクラスのメンバはサブクラスに bless されているオブジェクトを | |
| 14228 | 含んでいます。 | |
| 14229 | クラス名は(後述する)組み込みの型名と衝突することにも注意してください。 | |
| 14230 | ||
| 12266 | 14231 | =begin original |
| 12267 | 14232 | |
| 12268 | ||
| 14233 | If the operand is a reference to an unblessed object, then the return | |
| 12269 | ||
| 14234 | value indicates the type of object. If the unblessed referent is not | |
| 12270 | ||
| 14235 | a scalar, then the return value will be one of the strings C<ARRAY>, | |
| 12271 | ||
| 14236 | C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of | |
| 14237 | object it is. If the unblessed referent is a scalar, then the return | |
| 14238 | value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, | |
| 14239 | C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar | |
| 14240 | currently has. But note that C<qr//> scalars are created already | |
| 14241 | blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that | |
| 14242 | these built-in type names can also be used as | |
| 14243 | class names, so C<ref> returning one of these names doesn't unambiguously | |
| 14244 | indicate that the referent is of the kind to which the name refers. | |
| 12272 | 14245 | |
| 12273 | 14246 | =end original |
| 12274 | 14247 | |
| 12275 | ||
| 14248 | オペランドが bless されていないオブジェクトへのリファレンスの場合、 | |
| 12276 | ||
| 14249 | 返り値はオブジェクトの型を示します。 | |
| 12277 | ||
| 14250 | bless されていないリファレンス先がスカラではない場合、 | |
| 12278 | ||
| 14251 | 返り値はオブジェクトの種類を示す、 | |
| 12279 | ||
| 14252 | C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。 | |
| 14253 | bless されていないリファレンス先がスカラの場合、 | |
| 14254 | 返り値はそのスカラが現在保持している種類に依存して、 | |
| 14255 | C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の | |
| 14256 | いずれかの文字列です。 | |
| 14257 | しかし、C<qr//> は既に bless されて作成されるので、 | |
| 14258 | C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。 | |
| 14259 | これらの組み込み型名はまたクラス名として使われることができるので、 | |
| 14260 | C<ref> がこれらの名前の一つを返すことは、 | |
| 14261 | 明らかにリファレンス先がその名前が示している種類のものであることを | |
| 14262 | 示しているわけではないことに注意してください。 | |
| 12280 | 14263 | |
| 12281 | 14264 | =begin original |
| 12282 | 14265 | |
| 12283 | The | |
| 14266 | The ambiguity between built-in type names and class names significantly | |
| 12284 | ||
| 14267 | limits the utility of C<ref>. For unambiguous information, use | |
| 14268 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about | |
| 14269 | blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for | |
| 14270 | information about physical types. Use L<the C<isa> method|UNIVERSAL/C<< | |
| 14271 | $obj->isa( TYPE ) >>> for class membership tests, though one must be | |
| 14272 | sure of blessedness before attempting a method call. Alternatively, the | |
| 14273 | L<C<isa> operator|perlop/"Class Instance Operator"> can test class | |
| 14274 | membership without checking blessedness first. | |
| 12285 | 14275 | |
| 12286 | 14276 | =end original |
| 12287 | 14277 | |
| 12288 | ||
| 14278 | 組み込み型とクラス名の間の曖昧さは C<ref> の有用性を大きく制限しています。 | |
| 12289 | ||
| 14279 | 曖昧でない情報のためには、bless に関する情報については | |
| 14280 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、 | |
| 14281 | 物理的な型の情報については | |
| 14282 | L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。 | |
| 14283 | クラスの所属メンバテストには | |
| 14284 | L<the C<isa> method|UNIVERSAL/C<< | |
| 14285 | $obj->isa( TYPE ) >>> を使ってください; | |
| 14286 | 但し、メソッド呼び出しを試みる前に bless されていることを | |
| 14287 | 確認しなければなりません。 | |
| 14288 | あるいは、 | |
| 14289 | L<C<isa> operator|perlop/"Class Instance Operator"> は、 | |
| 14290 | 最初に bless されているかを確認することなくクラスメンバをテストできます。 | |
| 12290 | 14291 | |
| 12291 | 14292 | =begin original |
| 12292 | 14293 | |
| 12293 | See also L<perlref>. | |
| 14294 | See also L<perlref> and L<perlobj>. | |
| 12294 | 14295 | |
| 12295 | 14296 | =end original |
| 12296 | 14297 | |
| 12297 | L<perlref> も参照してください。 | |
| 14298 | L<perlref> と L<perlobj> も参照してください。 | |
| 12298 | 14299 | |
| 12299 | 14300 | =item rename OLDNAME,NEWNAME |
| 12300 | 14301 | X<rename> X<move> X<mv> X<ren> |
| 12301 | 14302 | |
| 12302 | 14303 | =for Pod::Functions change a filename |
| 12303 | 14304 | |
| 12304 | 14305 | =begin original |
| 12305 | 14306 | |
| 12306 | 14307 | Changes the name of a file; an existing file NEWNAME will be |
| 12307 | clobbered. Returns true for success | |
| 14308 | clobbered. Returns true for success; on failure returns false and sets | |
| 14309 | L<C<$!>|perlvar/$!>. | |
| 12308 | 14310 | |
| 12309 | 14311 | =end original |
| 12310 | 14312 | |
| 12311 | 14313 | ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、 |
| 12312 | 14314 | 上書きされるかもしれません。 |
| 12313 | 成功時には真を | |
| 14315 | 成功時には真を返します; 失敗時には偽を返し、 | |
| 14316 | L<C<$!>|perlvar/$!> を設定します。 | |
| 12314 | 14317 | |
| 12315 | 14318 | =begin original |
| 12316 | 14319 | |
| 12317 | 14320 | Behavior of this function varies wildly depending on your system |
| 12318 | 14321 | implementation. For example, it will usually not work across file system |
| 12319 | 14322 | boundaries, even though the system I<mv> command sometimes compensates |
| 12320 | 14323 | for this. Other restrictions include whether it works on directories, |
| 12321 | 14324 | open files, or pre-existing files. Check L<perlport> and either the |
| 12322 | rename(2) manpage or equivalent system documentation for details. | |
| 14325 | L<rename(2)> manpage or equivalent system documentation for details. | |
| 12323 | 14326 | |
| 12324 | 14327 | =end original |
| 12325 | 14328 | |
| 12326 | 14329 | この関数の振る舞いはシステムの実装に大きく依存して異なります。 |
| 12327 | 14330 | 例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません; |
| 12328 | 14331 | システムの I<mv> がこれを補完している場合でもそうです。 |
| 12329 | 14332 | その他の制限には、ディレクトリ、オープンしているファイル、既に存在している |
| 12330 | 14333 | ファイルに対して使えるか、といったことを含みます。 |
| 12331 | 詳しくは、L<perlport> および rename(2) man ページあるいは同様の | |
| 14334 | 詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の | |
| 12332 | 14335 | システムドキュメントを参照してください。 |
| 12333 | 14336 | |
| 12334 | 14337 | =begin original |
| 12335 | 14338 | |
| 12336 | For a platform independent C<move> function look at | |
| 14339 | For a platform independent L<C<move>|File::Copy/move> function look at | |
| 12337 | module. | |
| 14340 | the L<File::Copy> module. | |
| 12338 | 14341 | |
| 12339 | 14342 | =end original |
| 12340 | 14343 | |
| 12341 | プラットフォームに依存しない C<move> | |
| 14344 | プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については | |
| 12342 | 参照してください。 | |
| 14345 | L<File::Copy> モジュールを参照してください。 | |
| 12343 | 14346 | |
| 12344 | 14347 | =begin original |
| 12345 | 14348 | |
| 12346 | 14349 | Portability issues: L<perlport/rename>. |
| 12347 | 14350 | |
| 12348 | 14351 | =end original |
| 12349 | 14352 | |
| 12350 | 14353 | 移植性の問題: L<perlport/rename>。 |
| 12351 | 14354 | |
| 12352 | 14355 | =item require VERSION |
| 12353 | 14356 | X<require> |
| 12354 | 14357 | |
| 12355 | 14358 | =item require EXPR |
| 12356 | 14359 | |
| 12357 | 14360 | =item require |
| 12358 | 14361 | |
| 12359 | 14362 | =for Pod::Functions load in external functions from a library at runtime |
| 12360 | 14363 | |
| 12361 | 14364 | =begin original |
| 12362 | 14365 | |
| 12363 | 14366 | Demands a version of Perl specified by VERSION, or demands some semantics |
| 12364 | specified by EXPR or by C<$_> if EXPR is not supplied. | |
| 14367 | specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied. | |
| 12365 | 14368 | |
| 12366 | 14369 | =end original |
| 12367 | 14370 | |
| 12368 | 14371 | VERSION で指定される Perl のバージョンを要求するか、 |
| 12369 | EXPR (省略時には C<$_>) によって指定されるいくつかの動作を | |
| 14372 | EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を | |
| 14373 | 要求します。 | |
| 12370 | 14374 | |
| 12371 | 14375 | =begin original |
| 12372 | 14376 | |
| 12373 | VERSION may be either a | |
| 14377 | VERSION may be either a literal such as v5.24.1, which will be | |
| 12374 | compared to C<$ | |
| 14378 | compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>), | |
| 12375 | ||
| 14379 | or a numeric argument of the form 5.024001, which will be compared to | |
| 12376 | ||
| 14380 | L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than | |
| 12377 | ||
| 14381 | the version of the current Perl interpreter. Compare with | |
| 14382 | L<C<use>|/use Module VERSION LIST>, which can do a similar check at | |
| 14383 | compile time. | |
| 12378 | 14384 | |
| 12379 | 14385 | =end original |
| 12380 | 14386 | |
| 12381 | VERSION は | |
| 14387 | VERSION は、v5.24.1 のようなリテラル | |
| 12382 | (C<$^V> (また | |
| 14388 | (L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは | |
| 14389 | C<$PERL_VERSION>) と比較されます) か、 | |
| 14390 | 5.024001 の数値形式(L<C<$]>|perlvar/$]> と比較されます)で指定します。 | |
| 12383 | 14391 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します。 |
| 12384 | L</use> と似ていますが、これはコンパイル時に | |
| 14392 | L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に | |
| 14393 | チェックされます。 | |
| 12385 | 14394 | |
| 12386 | 14395 | =begin original |
| 12387 | 14396 | |
| 12388 | Specifying VERSION as a | |
| 14397 | Specifying VERSION as a numeric argument of the form 5.024001 should | |
| 12389 | avoided | |
| 14398 | generally be avoided as older less readable syntax compared to | |
| 12390 | ve | |
| 14399 | v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric | |
| 12391 | ||
| 14400 | form was the only supported syntax, which is why you might see it in | |
| 14401 | older code. | |
| 12392 | 14402 | |
| 12393 | 14403 | =end original |
| 12394 | 14404 | |
| 12395 | VERSION に | |
| 14405 | VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; | |
| 12396 | ||
| 14406 | v5.24.1 に比べてより古く読みにくい文法だからです。 | |
| 12397 | ||
| 14407 | (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な | |
| 12398 | ||
| 14408 | 数値形式が唯一対応している文法でした; これが古いコードでこれを | |
| 14409 | 見るかも知れない理由です。 | |
| 12399 | 14410 | |
| 12400 | 14411 | =begin original |
| 12401 | 14412 | |
| 12402 | require v5. | |
| 14413 | require v5.24.1; # run time version check | |
| 12403 | require 5. | |
| 14414 | require 5.24.1; # ditto | |
| 12404 | require 5.0 | |
| 14415 | require 5.024_001; # ditto; older syntax compatible | |
| 12405 | | |
| 14416 | with perl 5.6 | |
| 12406 | 14417 | |
| 12407 | 14418 | =end original |
| 12408 | 14419 | |
| 12409 | require v5. | |
| 14420 | require v5.24.1; # 実行時バージョンチェック | |
| 12410 | require 5. | |
| 14421 | require 5.24.1; # 同様 | |
| 12411 | require 5.0 | |
| 14422 | require 5.024_001; # 同様; perl 5.6 と互換性のある古い文法 | |
| 12412 | 14423 | |
| 12413 | 14424 | =begin original |
| 12414 | 14425 | |
| 12415 | Otherwise, C<require> demands that a library file be | |
| 14426 | Otherwise, L<C<require>|/require VERSION> demands that a library file be | |
| 12416 | hasn't already been included. The file is included via | |
| 14427 | included if it hasn't already been included. The file is included via | |
| 12417 | mechanism, which is essentially just a variety of | |
| 14428 | the do-FILE mechanism, which is essentially just a variety of | |
| 14429 | L<C<eval>|/eval EXPR> with the | |
| 12418 | 14430 | caveat that lexical variables in the invoking script will be invisible |
| 12419 | to the included code. | |
| 14431 | to the included code. If it were implemented in pure Perl, it | |
| 14432 | would have semantics similar to the following: | |
| 12420 | 14433 | |
| 12421 | 14434 | =end original |
| 12422 | 14435 | |
| 12423 | それ以外の場合には、C<require> は、既に | |
| 14436 | それ以外の場合には、L<C<require>|/require VERSION> は、既に | |
| 12424 | ライブラリファイルを要求するものとなります。 | |
| 14437 | 読み込まれていないときに読み込むライブラリファイルを要求するものとなります。 | |
| 12425 | そのファイルは、基本的には C<eval> の一種である、 | |
| 14438 | そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、 | |
| 12426 | 読み込まれますが、起動したスクリプトのレキシカル変数は | |
| 14439 | do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は | |
| 12427 | 見えないという欠点があります。 | |
| 14440 | 読み込まれたコードから見えないという欠点があります。 | |
| 12428 | 意味的には、次のようなサブルーチンと | |
| 14441 | ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと | |
| 14442 | 同じようなものです: | |
| 12429 | 14443 | |
| 14444 | use Carp 'croak'; | |
| 14445 | use version; | |
| 14446 | ||
| 12430 | 14447 | sub require { |
| 12431 | my ($filename) = @_; | |
| 14448 | my ($filename) = @_; | |
| 12432 | if (e | |
| 14449 | if ( my $version = eval { version->parse($filename) } ) { | |
| 12433 | | |
| 14450 | if ( $version > $^V ) { | |
| 12434 | | |
| 14451 | my $vn = $version->normal; | |
| 12435 | | |
| 14452 | croak "Perl $vn required--this is only $^V, stopped"; | |
| 12436 | | |
| 14453 | } | |
| 12437 | | |
| 14454 | return 1; | |
| 12438 | | |
| 14455 | } | |
| 12439 | ||
| 12440 | | |
| 14457 | if (exists $INC{$filename}) { | |
| 12441 | | |
| 14458 | return 1 if $INC{$filename}; | |
| 12442 | | |
| 14459 | croak "Compilation failed in require"; | |
| 12443 | | |
| 14460 | } | |
| 12444 | ||
| 12445 | | |
| 14462 | local $INC; | |
| 12446 | | |
| 14463 | # this type of loop lets a hook overwrite $INC if they wish | |
| 12447 | | |
| 14464 | for($INC = 0; $INC < @INC; $INC++) { | |
| 12448 | | |
| 14465 | my $prefix = $INC[$INC]; | |
| 12449 | | |
| 14466 | if (!defined $prefix) { | |
| 12450 | | |
| 14467 | next; | |
| 12451 | | |
| 14468 | } | |
| 12452 | | |
| 14469 | if (ref $prefix) { | |
| 12453 | | |
| 14470 | #... do other stuff - see text below .... | |
| 12454 | | |
| 14471 | } | |
| 12455 | | |
| 14472 | # (see text below about possible appending of .pmc | |
| 12456 | | |
| 14473 | # suffix to $filename) | |
| 14474 | my $realfilename = "$prefix/$filename"; | |
| 14475 | next if ! -e $realfilename || -d _ || -b _; | |
| 14476 | $INC{$filename} = $realfilename; | |
| 14477 | my $result = do($realfilename); | |
| 14478 | # but run in caller's namespace | |
| 14479 | ||
| 14480 | if (!defined $result) { | |
| 14481 | $INC{$filename} = undef; | |
| 14482 | croak $@ ? "$@Compilation failed in require" | |
| 14483 | : "Can't locate $filename: $!\n"; | |
| 14484 | } | |
| 14485 | if (!$result) { | |
| 14486 | delete $INC{$filename}; | |
| 14487 | croak "$filename did not return true value"; | |
| 14488 | } | |
| 14489 | $! = 0; | |
| 14490 | return $result; | |
| 14491 | } | |
| 14492 | croak "Can't locate $filename in \@INC ..."; | |
| 12457 | 14493 | } |
| 12458 | 14494 | |
| 12459 | 14495 | =begin original |
| 12460 | 14496 | |
| 12461 | 14497 | Note that the file will not be included twice under the same specified |
| 12462 | 14498 | name. |
| 12463 | 14499 | |
| 12464 | 14500 | =end original |
| 12465 | 14501 | |
| 12466 | 14502 | ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。 |
| 12467 | 14503 | |
| 12468 | 14504 | =begin original |
| 12469 | 14505 | |
| 12470 | ||
| 14506 | Historically the file must return true as the last statement to indicate | |
| 12471 | 14507 | successful execution of any initialization code, so it's customary to |
| 12472 | 14508 | end such a file with C<1;> unless you're sure it'll return true |
| 12473 | 14509 | otherwise. But it's better just to put the C<1;>, in case you add more |
| 12474 | statements. | |
| 14510 | statements. As of 5.37.6 this requirement may be avoided by enabling | |
| 14511 | the 'module_true' feature, which is enabled by default in modern | |
| 14512 | version bundles. Thus code with C<use v5.37;> no longer needs to concern | |
| 14513 | itself with this issue. See L<feature> for more details. Note that this | |
| 14514 | affects the compilation unit within which the feature is used, and using | |
| 14515 | it before requiring a module will not change the behavior of existing | |
| 14516 | modules that do not themselves also use it. | |
| 12475 | 14517 | |
| 12476 | 14518 | =end original |
| 12477 | 14519 | |
| 12478 | 初期化コードの実行がうまくいったことを示すために、 | |
| 14520 | 歴史的に、初期化コードの実行がうまくいったことを示すために、ファイルは真を | |
| 12479 | ||
| 14521 | 返さなければならないので、真を返すようになっている自信がある場合を除いては、 | |
| 12480 | 真を返すようになっている自信がある場合を除いては、 | |
| 12481 | 14522 | ファイルの最後に C<1;> と書くのが習慣です。 |
| 12482 | 実行文を追加するような場合に備えて、C<1;> と書いておいた方が | |
| 14523 | しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。 | |
| 12483 | ||
| 14524 | As of 5.37.6 this requirement may be avoided by enabling | |
| 14525 | the 'module_true' feature, which is enabled by default in modern | |
| 14526 | version bundles. Thus code with C<use v5.37;> no longer needs to concern | |
| 14527 | itself with this issue. See L<feature> for more details. Note that this | |
| 14528 | affects the compilation unit within which the feature is used, and using | |
| 14529 | it before requiring a module will not change the behavior of existing | |
| 14530 | modules that do not themselves also use it. | |
| 14531 | (TBT) | |
| 12484 | 14532 | |
| 12485 | 14533 | =begin original |
| 12486 | 14534 | |
| 12487 | If EXPR is a bareword, | |
| 14535 | If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm> | |
| 12488 | replaces | |
| 14536 | extension and replaces C<::> with C</> in the filename for you, | |
| 12489 | 14537 | to make it easy to load standard modules. This form of loading of |
| 12490 | modules does not risk altering your namespace | |
| 14538 | modules does not risk altering your namespace, however it will autovivify | |
| 14539 | the stash for the required module. | |
| 12491 | 14540 | |
| 12492 | 14541 | =end original |
| 12493 | 14542 | |
| 12494 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
| 14543 | EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、 | |
| 12495 | ||
| 14544 | L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に | |
| 12496 | ||
| 14545 | 変えたものがファイル名であると仮定します。 | |
| 12497 | この形式のモジュールロードは、 | |
| 14546 | この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、 | |
| 12498 | ||
| 14547 | 要求されたモジュールのためのスタッシュが自動有効化されます。 | |
| 12499 | 14548 | |
| 12500 | 14549 | =begin original |
| 12501 | 14550 | |
| 12502 | 14551 | In other words, if you try this: |
| 12503 | 14552 | |
| 12504 | 14553 | =end original |
| 12505 | 14554 | |
| 12506 | 14555 | 言い換えると、以下のようにすると: |
| 12507 | 14556 | |
| 12508 | 14557 | require Foo::Bar; # a splendid bareword |
| 12509 | 14558 | |
| 12510 | 14559 | =begin original |
| 12511 | 14560 | |
| 12512 | The require function will actually look for the | |
| 14561 | The require function will actually look for the F<Foo/Bar.pm> file in the | |
| 12513 | directories specified in the C<@INC> array | |
| 14562 | directories specified in the L<C<@INC>|perlvar/@INC> array, and it will | |
| 14563 | autovivify the C<Foo::Bar::> stash at compile time. | |
| 12514 | 14564 | |
| 12515 | 14565 | =end original |
| 12516 | 14566 | |
| 12517 | require 関数は C<@INC> 配列で指定されたディレクトリにある | |
| 14567 | require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある | |
| 12518 | ||
| 14568 | F<Foo/Bar.pm> ファイルを探し、コンパイル時に | |
| 14569 | C<Foo::Bar::> のスタッシュを自動有効化します。 | |
| 12519 | 14570 | |
| 12520 | 14571 | =begin original |
| 12521 | 14572 | |
| 12522 | 14573 | But if you try this: |
| 12523 | 14574 | |
| 12524 | 14575 | =end original |
| 12525 | 14576 | |
| 12526 | 14577 | しかし、以下のようにすると: |
| 12527 | 14578 | |
| 12528 | $class = 'Foo::Bar'; | |
| 14579 | my $class = 'Foo::Bar'; | |
| 12529 | 14580 | require $class; # $class is not a bareword |
| 12530 | 14581 | #or |
| 12531 | 14582 | require "Foo::Bar"; # not a bareword because of the "" |
| 12532 | 14583 | |
| 12533 | 14584 | =begin original |
| 12534 | 14585 | |
| 12535 | The require function will look for the | |
| 14586 | The require function will look for the F<Foo::Bar> file in the | |
| 12536 | ||
| 14587 | L<C<@INC>|perlvar/@INC> array and | |
| 14588 | will complain about not finding F<Foo::Bar> there. In this case you can do: | |
| 12537 | 14589 | |
| 12538 | 14590 | =end original |
| 12539 | 14591 | |
| 12540 | require 関数は @INC 配列の | |
| 14592 | require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、 | |
| 12541 | おそらくそこに | |
| 14593 | おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。 | |
| 12542 | このような場合には、以下のように | |
| 14594 | このような場合には、以下のように: | |
| 12543 | 14595 | |
| 12544 | 14596 | eval "require $class"; |
| 12545 | 14597 | |
| 12546 | 14598 | =begin original |
| 12547 | 14599 | |
| 12548 | ||
| 14600 | or you could do | |
| 12549 | bareword argument, there is a little extra functionality going on behind | |
| 12550 | the scenes. Before C<require> looks for a "F<.pm>" extension, it will | |
| 12551 | first look for a similar filename with a "F<.pmc>" extension. If this file | |
| 12552 | is found, it will be loaded in place of any file ending in a "F<.pm>" | |
| 12553 | extension. | |
| 12554 | 14601 | |
| 12555 | 14602 | =end original |
| 12556 | 14603 | |
| 12557 | ||
| 14604 | あるいは次のようにも出来ます | |
| 12558 | ||
| 12559 | ||
| 14606 | require "Foo/Bar.pm"; | |
| 12560 | ||
| 12561 | ||
| 14608 | =begin original | |
| 14609 | ||
| 14610 | Neither of these forms will autovivify any stashes at compile time and | |
| 14611 | only have run time effects. | |
| 14612 | ||
| 14613 | =end original | |
| 14614 | ||
| 14615 | これらのどちらもコンパイル時にスタッシュを自動有効化せず、 | |
| 14616 | 実行時の効果のみを持ちます。 | |
| 14617 | ||
| 14618 | =begin original | |
| 14619 | ||
| 14620 | Now that you understand how L<C<require>|/require VERSION> looks for | |
| 14621 | files with a bareword argument, there is a little extra functionality | |
| 14622 | going on behind the scenes. Before L<C<require>|/require VERSION> looks | |
| 14623 | for a F<.pm> extension, it will first look for a similar filename with a | |
| 14624 | F<.pmc> extension. If this file is found, it will be loaded in place of | |
| 14625 | any file ending in a F<.pm> extension. This applies to both the explicit | |
| 14626 | C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form. | |
| 14627 | ||
| 14628 | =end original | |
| 14629 | ||
| 14630 | 引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを | |
| 14631 | 探すかを理解してください; 水面下でちょっとした追加の機能があります。 | |
| 14632 | L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず | |
| 14633 | 拡張子 F<.pmc> を持つファイルを探します。 | |
| 14634 | このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに | |
| 12562 | 14635 | 読み込まれます。 |
| 14636 | これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の | |
| 14637 | 両方に適用されます。 | |
| 12563 | 14638 | |
| 12564 | 14639 | =begin original |
| 12565 | 14640 | |
| 12566 | You can also insert hooks into the import facility by putting Perl | |
| 14641 | You can also insert hooks into the import facility by putting Perl | |
| 12567 | directly into the @INC | |
| 14642 | coderefs or objects directly into the L<C<@INC>|perlvar/@INC> array. | |
| 12568 | re | |
| 14643 | There are two types of hooks, INC filters, and INCDIR hooks, and there | |
| 14644 | are three forms of representing a hook: subroutine references, array | |
| 14645 | references, and blessed objects. | |
| 12569 | 14646 | |
| 12570 | 14647 | =end original |
| 12571 | 14648 | |
| 12572 | @INC 配列に直接 | |
| 14649 | L<C<@INC>|perlvar/@INC> 配列に直接コードリファレンスやオブジェクトを | |
| 12573 | 挿入できます。 | |
| 14650 | 入れることで、インポート機能にフックを挿入できます。 | |
| 12574 | ||
| 14651 | There are two types of hooks, INC filters, and INCDIR hooks, and there | |
| 12575 | ||
| 14652 | フックの表現方法は 3 種類あります: サブルーチンリファレンス、 | |
| 14653 | 配列リファレンス、bless されたオブジェクトです。 | |
| 14654 | (TBT) | |
| 12576 | 14655 | |
| 12577 | 14656 | =begin original |
| 12578 | 14657 | |
| 12579 | 14658 | Subroutine references are the simplest case. When the inclusion system |
| 12580 | walks through @INC and encounters a subroutine, | |
| 14659 | walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, unless | |
| 12581 | ||
| 14660 | this subroutine is blessed and supports an INCDIR hook this | |
| 12582 | s | |
| 14661 | subroutine will be assumed to be an INC hook will be called with two | |
| 12583 | ||
| 14662 | parameters, the first a reference to itself, and the second the name of | |
| 12584 | ||
| 14663 | the file to be included (e.g., F<Foo/Bar.pm>). The subroutine should | |
| 14664 | return either nothing or else a list of up to four values in the | |
| 14665 | following order: | |
| 12585 | 14666 | |
| 12586 | 14667 | =end original |
| 12587 | 14668 | |
| 12588 | 14669 | サブルーチンへのリファレンスは一番単純な場合です。 |
| 12589 | インクルード機能が @INC を走査してサブルーチンに | |
| 14670 | インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに | |
| 12590 | ||
| 14671 | 出会った場合、 | |
| 14672 | このサブルーチンが bless されていて INCDIR フックに対応していない限り、 | |
| 14673 | このサブルーチンは二つの引数と共に呼び出される INC フックであると | |
| 14674 | 仮定されます; | |
| 12591 | 14675 | 一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名 |
| 12592 | ( | |
| 14676 | (F<Foo/Bar.pm> など)です。 | |
| 12593 | サブルーチンは何も返さないか、以下の順で最大 | |
| 14677 | サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。 | |
| 12594 | 返します。 | |
| 12595 | 14678 | |
| 12596 | 14679 | =over |
| 12597 | 14680 | |
| 12598 | 14681 | =item 1 |
| 12599 | 14682 | |
| 12600 | 14683 | =begin original |
| 12601 | 14684 | |
| 12602 | A f | |
| 14685 | A reference to a scalar, containing any initial source code to prepend to | |
| 14686 | the file or generator output. | |
| 12603 | 14687 | |
| 12604 | 14688 | =end original |
| 12605 | 14689 | |
| 12606 | ファイル | |
| 14690 | ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む | |
| 14691 | スカラへのリファレンス。 | |
| 12607 | 14692 | |
| 12608 | 14693 | =item 2 |
| 12609 | 14694 | |
| 12610 | 14695 | =begin original |
| 12611 | 14696 | |
| 14697 | A filehandle, from which the file will be read. | |
| 14698 | ||
| 14699 | =end original | |
| 14700 | ||
| 14701 | ファイルが読み込まれるファイルハンドル。 | |
| 14702 | ||
| 14703 | =item 3 | |
| 14704 | ||
| 14705 | =begin original | |
| 14706 | ||
| 12612 | 14707 | A reference to a subroutine. If there is no filehandle (previous item), |
| 12613 | 14708 | then this subroutine is expected to generate one line of source code per |
| 12614 | call, writing the line into C<$_> and returning 1, then | |
| 14709 | call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then | |
| 12615 | file returning 0. If there is a filehandle, then th | |
| 14710 | finally at end of file returning 0. If there is a filehandle, then the | |
| 12616 | called to act as a simple source filter, with the | |
| 14711 | subroutine will be called to act as a simple source filter, with the | |
| 14712 | line as read in L<C<$_>|perlvar/$_>. | |
| 12617 | 14713 | Again, return 1 for each valid line, and 0 after all lines have been |
| 12618 | 14714 | returned. |
| 14715 | For historical reasons the subroutine will receive a meaningless argument | |
| 14716 | (in fact always the numeric value zero) as C<$_[0]>. | |
| 12619 | 14717 | |
| 12620 | 14718 | =end original |
| 12621 | 14719 | |
| 12622 | 14720 | サブルーチンへのリファレンス。 |
| 12623 | (一つ前のアイテムである)ファイルハンドルがない場合、 | |
| 14721 | (一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に | |
| 12624 | ||
| 14722 | 一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を | |
| 12625 | ||
| 14723 | 返し、それから最終的にファイル終端で 0 を返すものと想定されます。 | |
| 12626 | 想定されます。 | |
| 12627 | 14724 | ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして |
| 12628 | 振舞うように呼び出され、行は C<$_> から読み込まれます。 | |
| 14725 | 振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。 | |
| 12629 | 14726 | 再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。 |
| 14727 | 歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数 | |
| 14728 | (実際には常に数値 0) を受け取ります。 | |
| 12630 | 14729 | |
| 12631 | =item | |
| 14730 | =item 4 | |
| 12632 | 14731 | |
| 12633 | 14732 | =begin original |
| 12634 | 14733 | |
| 12635 | Optional state for the subroutine. The state is passed in as C<$_[1]>. | |
| 14734 | Optional state for the subroutine. The state is passed in as C<$_[1]>. | |
| 12636 | reference to the subroutine itself is passed in as C<$_[0]>. | |
| 12637 | 14735 | |
| 12638 | 14736 | =end original |
| 12639 | 14737 | |
| 12640 | 14738 | サブルーチンのための状態(オプション)。 |
| 12641 | 14739 | 状態は C<$_[1]> として渡されます。 |
| 12642 | サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。 | |
| 12643 | 14740 | |
| 12644 | 14741 | =back |
| 12645 | 14742 | |
| 12646 | 14743 | =begin original |
| 12647 | 14744 | |
| 12648 | ||
| 14745 | C<AUTOLOAD> cannot be used to resolve the C<INCDIR> method, C<INC> is | |
| 12649 | ||
| 14746 | checked first, and C<AUTOLOAD> would resolve that. | |
| 14747 | ||
| 14748 | =end original | |
| 14749 | ||
| 14750 | C<AUTOLOAD> cannot be used to resolve the C<INCDIR> method, C<INC> is | |
| 14751 | checked first, and C<AUTOLOAD> would resolve that. | |
| 14752 | (TBT) | |
| 14753 | ||
| 14754 | =begin original | |
| 14755 | ||
| 14756 | If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the | |
| 14757 | first 3 values above is returned, then L<C<require>|/require VERSION> | |
| 14758 | looks at the remaining elements of L<C<@INC>|perlvar/@INC>. | |
| 12650 | 14759 | Note that this filehandle must be a real filehandle (strictly a typeglob |
| 12651 | or reference to a typeglob, whether blessed or unblessed); tied filehandles | |
| 14760 | or reference to a typeglob, whether blessed or unblessed); tied filehandles | |
| 12652 | 14761 | will be ignored and processing will stop there. |
| 12653 | 14762 | |
| 12654 | 14763 | =end original |
| 12655 | 14764 | |
| 12656 | 空リスト、C<undef>、または上記の最初の三つの値のどれとも | |
| 14765 | 空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも | |
| 12657 | 返されると、C<require> | |
| 14766 | 一致しないものが返されると、L<C<require>|/require VERSION> は | |
| 14767 | L<C<@INC>|perlvar/@INC> の残りの要素を見ます。 | |
| 12658 | 14768 | このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの |
| 12659 | 14769 | リファレンス、bless されているかに関わらず)でなければなりません; |
| 12660 | 14770 | tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。 |
| 12661 | 14771 | |
| 12662 | 14772 | =begin original |
| 12663 | 14773 | |
| 12664 | If the hook is an | |
| 14774 | If the hook is an object, it should provide an C<INC> or C<INCDIR> | |
| 12665 | ||
| 14775 | method that will be called as above, the first parameter being the | |
| 12666 | ||
| 14776 | object itself. If it does not provide either method, and the object is | |
| 12667 | the | |
| 14777 | not CODE ref then an exception will be thrown, otherwise it will simply | |
| 14778 | be executed like an unblessed CODE ref would. Note that you must fully | |
| 14779 | qualify the method name when you declare an C<INC> sub (unlike the | |
| 14780 | C<INCDIR> sub), as the unqualified symbol C<INC> is always forced into | |
| 14781 | package C<main>. Here is a typical code layout for an C<INC> hook: | |
| 12668 | 14782 | |
| 12669 | 14783 | =end original |
| 12670 | 14784 | |
| 12671 | フックが | |
| 14785 | フックがオブジェクトの場合、C<INC> か C<INCDIR> メソッドを提供している | |
| 12672 | ||
| 14786 | 必要があります; | |
| 12673 | ||
| 14787 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 | |
| 12674 | ||
| 14788 | If it does not provide either method, and the object is | |
| 12675 | ||
| 14789 | not CODE ref then an exception will be thrown, otherwise it will simply | |
| 14790 | be executed like an unblessed CODE ref would. | |
| 14791 | 修飾されていない C<INC> シンボルは常にパッケージ C<main> に強制されるため、 | |
| 14792 | C<INC> サブルーチンを宣言する場合は、 | |
| 14793 | (C<INCDIR> サブルーチンと異なり) | |
| 14794 | 完全修飾しなければならないことに注意してください。 | |
| 14795 | 以下は C<INC> フックの典型的なコードレイアウトです: | |
| 14796 | (TBT) | |
| 12676 | 14797 | |
| 14798 | # In Foo.pm | |
| 14799 | package Foo; | |
| 14800 | sub new { ... } | |
| 14801 | sub Foo::INC { | |
| 14802 | my ($self, $filename) = @_; | |
| 14803 | ... | |
| 14804 | } | |
| 14805 | ||
| 14806 | # In the main program | |
| 14807 | push @INC, Foo->new(...); | |
| 14808 | ||
| 12677 | 14809 | =begin original |
| 12678 | 14810 | |
| 14811 | If the hook is an array reference, its first element must be a | |
| 14812 | subroutine reference or an object as described above. When the first | |
| 14813 | element is an object that supports an C<INC> or C<INCDIR> method then | |
| 14814 | the method will be called with the object as the first argument, the | |
| 14815 | filename requested as the second, and the hook array reference as the | |
| 14816 | the third. When the first element is a subroutine then it will be | |
| 14817 | called with the array as the first argument, and the filename as the | |
| 14818 | second, no third parameter will be passed in. In both forms you can | |
| 14819 | modify the contents of the array to provide state between calls, or | |
| 14820 | whatever you like. | |
| 14821 | ||
| 14822 | =end original | |
| 14823 | ||
| 14824 | フックが配列のリファレンスの場合、その最初の要素は前述の通り、 | |
| 14825 | サブルーチンリファレンスかオブジェクトでなければなりません。 | |
| 14826 | When the first | |
| 14827 | element is an object that supports an C<INC> or C<INCDIR> method then | |
| 14828 | the method will be called with the object as the first argument, the | |
| 14829 | filename requested as the second, and the hook array reference as the | |
| 14830 | the third. When the first element is a subroutine then it will be | |
| 14831 | called with the array as the first argument, and the filename as the | |
| 14832 | second, no third parameter will be passed in. In both forms you can | |
| 14833 | modify the contents of the array to provide state between calls, or | |
| 14834 | whatever you like. | |
| 14835 | (TBT) | |
| 14836 | ||
| 14837 | =begin original | |
| 14838 | ||
| 12679 | 14839 | In other words, you can write: |
| 12680 | 14840 | |
| 12681 | 14841 | =end original |
| 12682 | 14842 | |
| 12683 | 14843 | 言い換えると、以下のように書いたり: |
| 12684 | 14844 | |
| 12685 | 14845 | push @INC, \&my_sub; |
| 12686 | 14846 | sub my_sub { |
| 12687 | 14847 | my ($coderef, $filename) = @_; # $coderef is \&my_sub |
| 12688 | 14848 | ... |
| 12689 | 14849 | } |
| 12690 | 14850 | |
| 12691 | 14851 | =begin original |
| 12692 | 14852 | |
| 12693 | 14853 | or: |
| 12694 | 14854 | |
| 12695 | 14855 | =end original |
| 12696 | 14856 | |
| 12697 | または | |
| 14857 | または: | |
| 12698 | 14858 | |
| 12699 | 14859 | push @INC, [ \&my_sub, $x, $y, ... ]; |
| 12700 | 14860 | sub my_sub { |
| 12701 | 14861 | my ($arrayref, $filename) = @_; |
| 12702 | 14862 | # Retrieve $x, $y, ... |
| 12703 | my @parameters = @$arrayref | |
| 14863 | my (undef, @parameters) = @$arrayref; | |
| 12704 | 14864 | ... |
| 12705 | 14865 | } |
| 12706 | 14866 | |
| 12707 | 14867 | =begin original |
| 12708 | 14868 | |
| 12709 | ||
| 14869 | or: | |
| 12710 | called as above, the first parameter being the object itself. (Note that | |
| 12711 | you must fully qualify the sub's name, as unqualified C<INC> is always forced | |
| 12712 | into package C<main>.) Here is a typical code layout: | |
| 12713 | 14870 | |
| 12714 | 14871 | =end original |
| 12715 | 14872 | |
| 12716 | ||
| 14873 | または: | |
| 12717 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 | |
| 12718 | (修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、 | |
| 12719 | サブルーチン名は完全修飾する必要があることに注意してください。) | |
| 12720 | 以下は典型的なコードレイアウトです: | |
| 12721 | 14874 | |
| 12722 | | |
| 14875 | push @INC, [ HookObj->new(), $x, $y, ... ]; | |
| 12723 | | |
| 14876 | sub HookObj::INC { | |
| 12724 | s | |
| 14877 | my ($self, $filename, $arrayref)= @_; | |
| 12725 | | |
| 14878 | my (undef, @parameters) = @$arrayref; | |
| 12726 | my ($self, $filename) = @_; | |
| 12727 | 14879 | ... |
| 12728 | 14880 | } |
| 12729 | 14881 | |
| 12730 | # In the main program | |
| 12731 | push @INC, Foo->new(...); | |
| 12732 | ||
| 12733 | 14882 | =begin original |
| 12734 | 14883 | |
| 12735 | These hooks are also permitted to set the %INC entry | |
| 14884 | These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry | |
| 12736 | 14885 | corresponding to the files they have loaded. See L<perlvar/%INC>. |
| 14886 | Should an C<INC> hook not do this then perl will set the C<%INC> entry | |
| 14887 | to be the hook reference itself. | |
| 12737 | 14888 | |
| 12738 | 14889 | =end original |
| 12739 | 14890 | |
| 12740 | これらのフックは、読み込まれるファイルに対応する | |
| 14891 | これらのフックは、読み込まれるファイルに対応する | |
| 12741 | セットすることも許可します。 | |
| 14892 | L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。 | |
| 12742 | 14893 | L<perlvar/%INC> を参照してください。 |
| 14894 | Should an C<INC> hook not do this then perl will set the C<%INC> entry | |
| 14895 | to be the hook reference itself. | |
| 14896 | (TBT) | |
| 12743 | 14897 | |
| 12744 | 14898 | =begin original |
| 12745 | 14899 | |
| 12746 | ||
| 14900 | A hook may also be used to rewrite the C<@INC> array. While this might | |
| 14901 | sound strange, there are situations where it can be very useful to do | |
| 14902 | this. Such hooks usually just return undef and do not mix filtering and | |
| 14903 | C<@INC> modifications. While in older versions of perl having a hook | |
| 14904 | modify C<@INC> was fraught with issues and could even result in | |
| 14905 | segfaults or assert failures, as of 5.37.7 the logic has been made much | |
| 14906 | more robust and the hook now has control over the loop iteration if it | |
| 14907 | wishes to do so. | |
| 12747 | 14908 | |
| 12748 | 14909 | =end original |
| 12749 | 14910 | |
| 12750 | ||
| 14911 | A hook may also be used to rewrite the C<@INC> array. While this might | |
| 12751 | ||
| 14912 | sound strange, there are situations where it can be very useful to do | |
| 14913 | this. Such hooks usually just return undef and do not mix filtering and | |
| 14914 | C<@INC> modifications. While in older versions of perl having a hook | |
| 14915 | modify C<@INC> was fraught with issues and could even result in | |
| 14916 | segfaults or assert failures, as of 5.37.7 the logic has been made much | |
| 14917 | more robust and the hook now has control over the loop iteration if it | |
| 14918 | wishes to do so. | |
| 14919 | (TBT) | |
| 12752 | 14920 | |
| 14921 | =begin original | |
| 14922 | ||
| 14923 | There is a now a facility to control the iterator for the C<@INC> array | |
| 14924 | traversal that is performed during require. The C<$INC> variable will be | |
| 14925 | initialized with the index of the currently executing hook. Once the | |
| 14926 | hook returns the next slot in C<@INC> that will be checked will be the | |
| 14927 | integer successor of value in C<$INC> (or -1 if it is undef). For example | |
| 14928 | the following code | |
| 14929 | ||
| 14930 | =end original | |
| 14931 | ||
| 14932 | There is a now a facility to control the iterator for the C<@INC> array | |
| 14933 | traversal that is performed during require. The C<$INC> variable will be | |
| 14934 | initialized with the index of the currently executing hook. Once the | |
| 14935 | hook returns the next slot in C<@INC> that will be checked will be the | |
| 14936 | integer successor of value in C<$INC> (or -1 if it is undef). For example | |
| 14937 | the following code | |
| 14938 | (TBT) | |
| 14939 | ||
| 14940 | push @INC, sub { | |
| 14941 | splice @INC, $INC, 1; # remove this hook from @INC | |
| 14942 | unshift @INC, sub { warn "A" }; | |
| 14943 | undef $INC; # reset the $INC iterator so we | |
| 14944 | # execute the newly installed sub | |
| 14945 | # immediately. | |
| 14946 | }; | |
| 14947 | ||
| 14948 | =begin original | |
| 14949 | ||
| 14950 | would install a sub into C<@INC> that when executed as a hook (by for | |
| 14951 | instance a require of a file that does not exist), the hook will splice | |
| 14952 | itself out of C<@INC>, and add a new sub to the front that will warn | |
| 14953 | whenever someone does a require operation that requires an C<@INC> | |
| 14954 | search, and then immediately execute that hook. | |
| 14955 | ||
| 14956 | =end original | |
| 14957 | ||
| 14958 | would install a sub into C<@INC> that when executed as a hook (by for | |
| 14959 | instance a require of a file that does not exist), the hook will splice | |
| 14960 | itself out of C<@INC>, and add a new sub to the front that will warn | |
| 14961 | whenever someone does a require operation that requires an C<@INC> | |
| 14962 | search, and then immediately execute that hook. | |
| 14963 | (TBT) | |
| 14964 | ||
| 14965 | =begin original | |
| 14966 | ||
| 14967 | Prior to 5.37.7, there was no way to cause perl to use the newly | |
| 14968 | installed hook immediately, or to inspect any changed items in C<@INC> to | |
| 14969 | the left of the iterator, and so the warning would only be generated on | |
| 14970 | the second call to require. In more recent perl the presence of the last | |
| 14971 | statement which undefines C<$INC> will cause perl to restart the | |
| 14972 | traversal of the C<@INC> array at the beginning and execute the newly | |
| 14973 | installed sub immediately. | |
| 14974 | ||
| 14975 | =end original | |
| 14976 | ||
| 14977 | Prior to 5.37.7, there was no way to cause perl to use the newly | |
| 14978 | installed hook immediately, or to inspect any changed items in C<@INC> to | |
| 14979 | the left of the iterator, and so the warning would only be generated on | |
| 14980 | the second call to require. In more recent perl the presence of the last | |
| 14981 | statement which undefines C<$INC> will cause perl to restart the | |
| 14982 | traversal of the C<@INC> array at the beginning and execute the newly | |
| 14983 | installed sub immediately. | |
| 14984 | (TBT) | |
| 14985 | ||
| 14986 | =begin original | |
| 14987 | ||
| 14988 | Whatever value C<$INC> held, if any, will be restored at the end of the | |
| 14989 | require. Any changes made to C<$INC> during the lifetime of the hook | |
| 14990 | will be unrolled after the hook exits, and its value only has meaning | |
| 14991 | immediately after execution of the hook, thus setting C<$INC> to some | |
| 14992 | value prior to executing a C<require> will have no effect on how the | |
| 14993 | require executes at all. | |
| 14994 | ||
| 14995 | =end original | |
| 14996 | ||
| 14997 | Whatever value C<$INC> held, if any, will be restored at the end of the | |
| 14998 | require. Any changes made to C<$INC> during the lifetime of the hook | |
| 14999 | will be unrolled after the hook exits, and its value only has meaning | |
| 15000 | immediately after execution of the hook, thus setting C<$INC> to some | |
| 15001 | value prior to executing a C<require> will have no effect on how the | |
| 15002 | require executes at all. | |
| 15003 | (TBT) | |
| 15004 | ||
| 15005 | =begin original | |
| 15006 | ||
| 15007 | As of 5.37.7 C<@INC> values of undef will be silently ignored. | |
| 15008 | ||
| 15009 | =end original | |
| 15010 | ||
| 15011 | As of 5.37.7 C<@INC> values of undef will be silently ignored. | |
| 15012 | (TBT) | |
| 15013 | ||
| 15014 | =begin original | |
| 15015 | ||
| 15016 | The function C<require()> is difficult to wrap properly. Many modules | |
| 15017 | consult the stack to find information about their caller, and injecting | |
| 15018 | a new stack frame by wrapping C<require()> often breaks things. | |
| 15019 | Nevertheless it can be very helpful to have the ability to perform | |
| 15020 | actions before and after a C<require>, for instance for trace utilities | |
| 15021 | like C<Devel::TraceUse> or to measure time to load and the memory | |
| 15022 | consumption of the require graph. Because of the difficulties in safely | |
| 15023 | creating a C<require()> wrapper in 5.37.10 we introduced a new mechanism. | |
| 15024 | ||
| 15025 | =end original | |
| 15026 | ||
| 15027 | The function C<require()> is difficult to wrap properly. Many modules | |
| 15028 | consult the stack to find information about their caller, and injecting | |
| 15029 | a new stack frame by wrapping C<require()> often breaks things. | |
| 15030 | Nevertheless it can be very helpful to have the ability to perform | |
| 15031 | actions before and after a C<require>, for instance for trace utilities | |
| 15032 | like C<Devel::TraceUse> or to measure time to load and the memory | |
| 15033 | consumption of the require graph. Because of the difficulties in safely | |
| 15034 | creating a C<require()> wrapper in 5.37.10 we introduced a new mechanism. | |
| 15035 | (TBT) | |
| 15036 | ||
| 15037 | =begin original | |
| 15038 | ||
| 15039 | As of 5.37.10, prior to any other actions it performs, C<require> will | |
| 15040 | check if C<${^HOOK}{require__before}> contains a coderef, and if it does | |
| 15041 | it will be called with the filename form of the item being loaded. The hook | |
| 15042 | may modify C<$_[0]> to load a different filename, or it may throw a fatal | |
| 15043 | exception to cause the require to fail, which will be treated as though the | |
| 15044 | required code itself had thrown an exception. | |
| 15045 | ||
| 15046 | =end original | |
| 15047 | ||
| 15048 | As of 5.37.10, prior to any other actions it performs, C<require> will | |
| 15049 | check if C<${^HOOK}{require__before}> contains a coderef, and if it does | |
| 15050 | it will be called with the filename form of the item being loaded. The hook | |
| 15051 | may modify C<$_[0]> to load a different filename, or it may throw a fatal | |
| 15052 | exception to cause the require to fail, which will be treated as though the | |
| 15053 | required code itself had thrown an exception. | |
| 15054 | (TBT) | |
| 15055 | ||
| 15056 | =begin original | |
| 15057 | ||
| 15058 | The C<${^HOOK}{require__before}> hook may return a code reference, in | |
| 15059 | which case the code reference will be executed (in an eval with the | |
| 15060 | filname as a parameter) after the require completes. It will be executed | |
| 15061 | regardless of how the compilation completed, and even if the require | |
| 15062 | throws a fatal exception. The function may consult C<%INC> to determine | |
| 15063 | if the require failed or not. For instance the following code will print | |
| 15064 | some diagnostics before and after every C<require> statement. The | |
| 15065 | example also includes logic to chain the signal, so that multiple | |
| 15066 | signals can cooperate. Well behaved C<${^HOOK}{require__before}> | |
| 15067 | handlers should always take this into account. | |
| 15068 | ||
| 15069 | =end original | |
| 15070 | ||
| 15071 | The C<${^HOOK}{require__before}> hook may return a code reference, in | |
| 15072 | which case the code reference will be executed (in an eval with the | |
| 15073 | filname as a parameter) after the require completes. It will be executed | |
| 15074 | regardless of how the compilation completed, and even if the require | |
| 15075 | throws a fatal exception. The function may consult C<%INC> to determine | |
| 15076 | if the require failed or not. For instance the following code will print | |
| 15077 | some diagnostics before and after every C<require> statement. The | |
| 15078 | example also includes logic to chain the signal, so that multiple | |
| 15079 | signals can cooperate. Well behaved C<${^HOOK}{require__before}> | |
| 15080 | handlers should always take this into account. | |
| 15081 | (TBT) | |
| 15082 | ||
| 15083 | { | |
| 15084 | use Scalar::Util qw(reftype); | |
| 15085 | my $old_hook = ${^HOOK}{require__before}; | |
| 15086 | local ${^HOOK}{require__before} = sub { | |
| 15087 | my ($name) = @_; | |
| 15088 | my $old_hook_ret; | |
| 15089 | $old_hook_ret = $old_hook->($name) if $old_hook; | |
| 15090 | warn "Requiring: $name\n"; | |
| 15091 | return sub { | |
| 15092 | $old_hook_ret->() if ref($old_hook_ret) | |
| 15093 | && reftype($old_hook_ret) eq "CODE"; | |
| 15094 | warn sprintf "Finished requiring %s: %s\n", | |
| 15095 | $name, $INC{$name} ? "loaded" :"failed"; | |
| 15096 | }; | |
| 15097 | }; | |
| 15098 | require Whatever; | |
| 15099 | } | |
| 15100 | ||
| 15101 | =begin original | |
| 15102 | ||
| 15103 | This hook executes for ALL C<require> statements, unlike C<INC> and | |
| 15104 | C<INCDIR> hooks, which are only executed for relative file names, and it | |
| 15105 | executes first before any other special behaviour inside of require. | |
| 15106 | Note that the initial hook in C<${^HOOK}{require__before}> is *not* | |
| 15107 | executed inside of an eval, and throwing an exception will stop further | |
| 15108 | processing, but the after hook it may return is executed inside of an | |
| 15109 | eval, and any exceptions it throws will be silently ignored. This is | |
| 15110 | because it executes inside of the scope cleanup logic that is triggered | |
| 15111 | after the require completes, and an exception at this time would not | |
| 15112 | stop the module from being loaded, etc. | |
| 15113 | ||
| 15114 | =end original | |
| 15115 | ||
| 15116 | This hook executes for ALL C<require> statements, unlike C<INC> and | |
| 15117 | C<INCDIR> hooks, which are only executed for relative file names, and it | |
| 15118 | executes first before any other special behaviour inside of require. | |
| 15119 | Note that the initial hook in C<${^HOOK}{require__before}> is *not* | |
| 15120 | executed inside of an eval, and throwing an exception will stop further | |
| 15121 | processing, but the after hook it may return is executed inside of an | |
| 15122 | eval, and any exceptions it throws will be silently ignored. This is | |
| 15123 | because it executes inside of the scope cleanup logic that is triggered | |
| 15124 | after the require completes, and an exception at this time would not | |
| 15125 | stop the module from being loaded, etc. | |
| 15126 | (TBT) | |
| 15127 | ||
| 15128 | =begin original | |
| 15129 | ||
| 15130 | There is a similar hook that fires after require completes, | |
| 15131 | C<${^HOOK}{require__after}>, which will be called after each require statement | |
| 15132 | completes, either via an exception or successfully. It will be called with | |
| 15133 | the filename of the most recently executed require statement. It is executed | |
| 15134 | in an eval, and will not in any way affect execution. | |
| 15135 | ||
| 15136 | =end original | |
| 15137 | ||
| 15138 | There is a similar hook that fires after require completes, | |
| 15139 | C<${^HOOK}{require__after}>, which will be called after each require statement | |
| 15140 | completes, either via an exception or successfully. It will be called with | |
| 15141 | the filename of the most recently executed require statement. It is executed | |
| 15142 | in an eval, and will not in any way affect execution. | |
| 15143 | (TBT) | |
| 15144 | ||
| 15145 | =begin original | |
| 15146 | ||
| 15147 | For a yet-more-powerful import facility built around C<require>, see | |
| 15148 | L<C<use>|/use Module VERSION LIST> and L<perlmod>. | |
| 15149 | ||
| 15150 | =end original | |
| 15151 | ||
| 15152 | C<require> 関連で構築されている、より強力な import 機能については、 | |
| 15153 | この文書の L<C<use>|/use Module VERSION LIST> の項と、 | |
| 15154 | L<perlmod> を参照してください。 | |
| 15155 | ||
| 12753 | 15156 | =item reset EXPR |
| 12754 | 15157 | X<reset> |
| 12755 | 15158 | |
| 12756 | 15159 | =item reset |
| 12757 | 15160 | |
| 12758 | 15161 | =for Pod::Functions clear all variables of a given name |
| 12759 | 15162 | |
| 12760 | 15163 | =begin original |
| 12761 | 15164 | |
| 12762 | Generally used in a C<continue> block at the end of a | |
| 15165 | Generally used in a L<C<continue>|/continue BLOCK> block at the end of a | |
| 12763 | variables and reset C<??> searches so that they | |
| 15166 | loop to clear variables and reset C<m?pattern?> searches so that they | |
| 15167 | work again. The | |
| 12764 | 15168 | expression is interpreted as a list of single characters (hyphens |
| 12765 | allowed for ranges). All variables a | |
| 15169 | allowed for ranges). All variables (scalars, arrays, and hashes) | |
| 15170 | in the current package beginning with one of | |
| 12766 | 15171 | those letters are reset to their pristine state. If the expression is |
| 12767 | omitted, one-match searches (C<?pattern?>) are reset to match again. | |
| 15172 | omitted, one-match searches (C<m?pattern?>) are reset to match again. | |
| 12768 | 15173 | Only resets variables or searches in the current package. Always returns |
| 12769 | 15174 | 1. Examples: |
| 12770 | 15175 | |
| 12771 | 15176 | =end original |
| 12772 | 15177 | |
| 12773 | 通常、ループの最後に、変数をクリアし、C<??> 検索を再び | |
| 15178 | 通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように | |
| 12774 | ||
| 15179 | リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。 | |
| 12775 | 15180 | EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と |
| 12776 | 15181 | 解釈されます。 |
| 12777 | 名前がその文字のいずれかで始まる変数 | |
| 15182 | 名前がその文字のいずれかで始まる、現在のパッケージの全ての変数 | |
| 15183 | (スカラ、配列、ハッシュ)は、 | |
| 12778 | 15184 | 最初の状態にリセットされます。 |
| 12779 | EXPR を省略すると、1 回検索 (C<? | |
| 15185 | EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように | |
| 12780 | 15186 | リセットできます。 |
| 12781 | 15187 | カレントパッケージの変数もしくは検索だけがリセットされます。 |
| 12782 | 15188 | 常に 1 を返します。 |
| 12783 | 15189 | 例: |
| 12784 | 15190 | |
| 12785 | 15191 | reset 'X'; # reset all X variables |
| 12786 | 15192 | reset 'a-z'; # reset lower case variables |
| 12787 | reset; # just reset ?one-time? searches | |
| 15193 | reset; # just reset m?one-time? searches | |
| 12788 | 15194 | |
| 12789 | 15195 | =begin original |
| 12790 | 15196 | |
| 12791 | 15197 | Resetting C<"A-Z"> is not recommended because you'll wipe out your |
| 12792 | C<@ARGV> and C<@INC> arrays and your | |
| 15198 | L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your | |
| 12793 | ||
| 15199 | L<C<%ENV>|perlvar/%ENV> hash. | |
| 12794 | up on scope exit anyway, so you'll probably want to use them instead. | |
| 12795 | See L</my>. | |
| 12796 | 15200 | |
| 12797 | 15201 | =end original |
| 12798 | 15202 | |
| 12799 | reset C<"A-Z"> とすると、C<@ARGV> | |
| 15203 | reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>, | |
| 12800 | ||
| 15204 | L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも | |
| 12801 | ||
| 15205 | なくなってしまうので、止めた方が良いでしょう。 | |
| 12802 | レキシカル変数は、影響を受けませんが、スコープから外れれば、 | |
| 12803 | 自動的に綺麗になりますので、これからは、こちらを使うようにした方が | |
| 12804 | よいでしょう。 | |
| 12805 | L</my> を参照してください。 | |
| 12806 | 15206 | |
| 15207 | =begin original | |
| 15208 | ||
| 15209 | Resets only package variables; lexical variables are unaffected, but | |
| 15210 | they clean themselves up on scope exit anyway, so you'll probably want | |
| 15211 | to use them instead. See L<C<my>|/my VARLIST>. | |
| 15212 | ||
| 15213 | =end original | |
| 15214 | ||
| 15215 | パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、 | |
| 15216 | スコープから外れれば自動的に綺麗になるので、これからはこちらを | |
| 15217 | 使うようにした方がよいでしょう。 | |
| 15218 | L<C<my>|/my VARLIST> を参照してください。 | |
| 15219 | ||
| 12807 | 15220 | =item return EXPR |
| 12808 | 15221 | X<return> |
| 12809 | 15222 | |
| 12810 | 15223 | =item return |
| 12811 | 15224 | |
| 12812 | 15225 | =for Pod::Functions get out of a function early |
| 12813 | 15226 | |
| 12814 | 15227 | =begin original |
| 12815 | 15228 | |
| 12816 | Returns from a subroutine, C<eval> | |
| 15229 | Returns from a subroutine, L<C<eval>|/eval EXPR>, | |
| 15230 | L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex | |
| 15231 | eval block (but not a L<C<grep>|/grep BLOCK LIST>, | |
| 15232 | L<C<map>|/map BLOCK LIST>, or L<C<do BLOCK>|/do BLOCK> block) with the value | |
| 12817 | 15233 | given in EXPR. Evaluation of EXPR may be in list, scalar, or void |
| 12818 | 15234 | context, depending on how the return value will be used, and the context |
| 12819 | may vary from one execution to the next (see | |
| 15235 | may vary from one execution to the next (see | |
| 15236 | L<C<wantarray>|/wantarray>). If no EXPR | |
| 12820 | 15237 | is given, returns an empty list in list context, the undefined value in |
| 12821 | 15238 | scalar context, and (of course) nothing at all in void context. |
| 12822 | 15239 | |
| 12823 | 15240 | =end original |
| 12824 | 15241 | |
| 12825 | サブルーチン, C<eval>, C<do FILE> | |
| 15242 | サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>, | |
| 12826 | ||
| 15243 | L<C<sort>|/sort SUBNAME LIST> ブロックまたは正規表現 eval ブロック | |
| 15244 | (但し L<C<grep>|/grep BLOCK LIST>, | |
| 15245 | L<C<map>|/map BLOCK LIST>, L<C<do BLOCK>|/do BLOCK> ブロックではない) から | |
| 15246 | EXPR で与えられた値をもって、リターンします。 | |
| 12827 | 15247 | EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、 |
| 12828 | 15248 | 無効コンテキストになります; またコンテキストは実行毎に変わります |
| 12829 | (C<wantarray> を参照してください)。 | |
| 15249 | (L<C<wantarray>|/wantarray> を参照してください)。 | |
| 12830 | 15250 | EXPR が指定されなかった場合は、リストコンテキストでは空リストを、 |
| 12831 | 15251 | スカラコンテキストでは未定義値を返します; そして(もちろん) |
| 12832 | 15252 | 無効コンテキストでは何も返しません。 |
| 12833 | 15253 | |
| 12834 | 15254 | =begin original |
| 12835 | 15255 | |
| 12836 | (In the absence of an explicit C<return>, a subroutine | |
| 15256 | (In the absence of an explicit L<C<return>|/return EXPR>, a subroutine, | |
| 12837 | ||
| 15257 | L<C<eval>|/eval EXPR>, | |
| 15258 | or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression | |
| 12838 | 15259 | evaluated.) |
| 12839 | 15260 | |
| 12840 | 15261 | =end original |
| 12841 | 15262 | |
| 12842 | (サブルーチン, eval, do FILE に明示的に | |
| 15263 | (サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に | |
| 12843 | なければ、最後に評価された値で、 | |
| 15264 | L<C<return>|/return EXPR> がなければ、最後に評価された値で、 | |
| 15265 | 自動的にリターンします。) | |
| 12844 | 15266 | |
| 12845 | 15267 | =begin original |
| 12846 | 15268 | |
| 12847 | 15269 | Unlike most named operators, this is also exempt from the |
| 12848 | 15270 | looks-like-a-function rule, so C<return ("foo")."bar"> will |
| 12849 | cause "bar" to be part of the argument to C<return>. | |
| 15271 | cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>. | |
| 12850 | 15272 | |
| 12851 | 15273 | =end original |
| 12852 | 15274 | |
| 12853 | 15275 | ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも |
| 12854 | 免れるので、C<return ("foo")."bar"> とすると "bar" | |
| 15276 | 免れるので、C<return ("foo")."bar"> とすると C<"bar"> は | |
| 12855 | 一部となります。 | |
| 15277 | L<C<return>|/return EXPR> への引数の一部となります。 | |
| 12856 | 15278 | |
| 12857 | 15279 | =item reverse LIST |
| 12858 | 15280 | X<reverse> X<rev> X<invert> |
| 12859 | 15281 | |
| 12860 | 15282 | =for Pod::Functions flip a string or a list |
| 12861 | 15283 | |
| 12862 | 15284 | =begin original |
| 12863 | 15285 | |
| 12864 | 15286 | In list context, returns a list value consisting of the elements |
| 12865 | 15287 | of LIST in the opposite order. In scalar context, concatenates the |
| 12866 | 15288 | elements of LIST and returns a string value with all characters |
| 12867 | 15289 | in the opposite order. |
| 12868 | 15290 | |
| 12869 | 15291 | =end original |
| 12870 | 15292 | |
| 12871 | 15293 | リストコンテキストでは、LIST を構成する要素を逆順に並べた |
| 12872 | 15294 | リスト値を返します。 |
| 12873 | 15295 | スカラコンテキストでは、LIST の要素を連結して、 |
| 12874 | 15296 | 全ての文字を逆順にした文字列を返します。 |
| 12875 | 15297 | |
| 12876 | 15298 | print join(", ", reverse "world", "Hello"); # Hello, world |
| 12877 | 15299 | |
| 12878 | 15300 | print scalar reverse "dlrow ,", "olleH"; # Hello, world |
| 12879 | 15301 | |
| 12880 | 15302 | =begin original |
| 12881 | 15303 | |
| 12882 | Used without arguments in scalar context, reverse | |
| 15304 | Used without arguments in scalar context, L<C<reverse>|/reverse LIST> | |
| 15305 | reverses L<C<$_>|perlvar/$_>. | |
| 12883 | 15306 | |
| 12884 | 15307 | =end original |
| 12885 | 15308 | |
| 12886 | スカラコンテキストで引数なしで使うと、reverse | |
| 15309 | スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は | |
| 15310 | L<C<$_>|perlvar/$_> を逆順にします。 | |
| 12887 | 15311 | |
| 12888 | 15312 | $_ = "dlrow ,olleH"; |
| 12889 | 15313 | print reverse; # No output, list context |
| 12890 | 15314 | print scalar reverse; # Hello, world |
| 12891 | 15315 | |
| 12892 | 15316 | =begin original |
| 12893 | 15317 | |
| 12894 | 15318 | Note that reversing an array to itself (as in C<@a = reverse @a>) will |
| 12895 | 15319 | preserve non-existent elements whenever possible; i.e., for non-magical |
| 12896 | 15320 | arrays or for tied arrays with C<EXISTS> and C<DELETE> methods. |
| 12897 | 15321 | |
| 12898 | 15322 | =end original |
| 12899 | 15323 | |
| 12900 | 15324 | (C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、 |
| 12901 | 15325 | 存在しない要素は可能なら(つまりマジカルでない配列や |
| 12902 | 15326 | C<EXISTS> と C<DELETE> メソッドがある tie された配列) |
| 12903 | 15327 | いつでも保存されることに注意してください。 |
| 12904 | 15328 | |
| 12905 | 15329 | =begin original |
| 12906 | 15330 | |
| 12907 | 15331 | This operator is also handy for inverting a hash, although there are some |
| 12908 | 15332 | caveats. If a value is duplicated in the original hash, only one of those |
| 12909 | 15333 | can be represented as a key in the inverted hash. Also, this has to |
| 12910 | 15334 | unwind one hash and build a whole new one, which may take some time |
| 12911 | 15335 | on a large hash, such as from a DBM file. |
| 12912 | 15336 | |
| 12913 | 15337 | =end original |
| 12914 | 15338 | |
| 12915 | 15339 | この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。 |
| 12916 | 15340 | 元のハッシュで値が重複していると、それらのうち一つだけが |
| 12917 | 15341 | 逆順になったハッシュのキーとして表現されます。 |
| 12918 | 15342 | また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、 |
| 12919 | 15343 | DBM ファイルからのような大きなハッシュでは少し時間がかかります。 |
| 12920 | 15344 | |
| 12921 | %by_name = reverse %by_address; # Invert the hash | |
| 15345 | my %by_name = reverse %by_address; # Invert the hash | |
| 12922 | 15346 | |
| 12923 | 15347 | =item rewinddir DIRHANDLE |
| 12924 | 15348 | X<rewinddir> |
| 12925 | 15349 | |
| 12926 | 15350 | =for Pod::Functions reset directory handle |
| 12927 | 15351 | |
| 12928 | 15352 | =begin original |
| 12929 | 15353 | |
| 12930 | 15354 | Sets the current position to the beginning of the directory for the |
| 12931 | C<readdir> routine on DIRHANDLE. | |
| 15355 | L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE. | |
| 12932 | 15356 | |
| 12933 | 15357 | =end original |
| 12934 | 15358 | |
| 12935 | DIRHANDLE に対する C<readdir> ルーチンの現在位置を | |
| 15359 | DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を | |
| 12936 | 15360 | ディレクトリの最初に設定します。 |
| 12937 | 15361 | |
| 12938 | 15362 | =begin original |
| 12939 | 15363 | |
| 12940 | 15364 | Portability issues: L<perlport/rewinddir>. |
| 12941 | 15365 | |
| 12942 | 15366 | =end original |
| 12943 | 15367 | |
| 12944 | 15368 | 移植性の問題: L<perlport/rewinddir>。 |
| 12945 | 15369 | |
| 12946 | 15370 | =item rindex STR,SUBSTR,POSITION |
| 12947 | 15371 | X<rindex> |
| 12948 | 15372 | |
| 12949 | 15373 | =item rindex STR,SUBSTR |
| 12950 | 15374 | |
| 12951 | 15375 | =for Pod::Functions right-to-left substring search |
| 12952 | 15376 | |
| 12953 | 15377 | =begin original |
| 12954 | 15378 | |
| 12955 | Works just like index | |
| 15379 | Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it | |
| 15380 | returns the position of the I<last> | |
| 12956 | 15381 | occurrence of SUBSTR in STR. If POSITION is specified, returns the |
| 12957 | 15382 | last occurrence beginning at or before that position. |
| 12958 | 15383 | |
| 12959 | 15384 | =end original |
| 12960 | 15385 | |
| 12961 | 15386 | STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、 |
| 12962 | index | |
| 15387 | L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。 | |
| 12963 | 15388 | POSITION を指定すると、その位置から始まるか、その位置より前の、 |
| 12964 | 15389 | 最後の位置を返します。 |
| 12965 | 15390 | |
| 12966 | 15391 | =item rmdir FILENAME |
| 12967 | 15392 | X<rmdir> X<rd> X<directory, remove> |
| 12968 | 15393 | |
| 12969 | 15394 | =item rmdir |
| 12970 | 15395 | |
| 12971 | 15396 | =for Pod::Functions remove a directory |
| 12972 | 15397 | |
| 12973 | 15398 | =begin original |
| 12974 | 15399 | |
| 12975 | 15400 | Deletes the directory specified by FILENAME if that directory is |
| 12976 | 15401 | empty. If it succeeds it returns true; otherwise it returns false and |
| 12977 | sets C<$!> (errno). If FILENAME is omitted, uses | |
| 15402 | sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses | |
| 15403 | L<C<$_>|perlvar/$_>. | |
| 12978 | 15404 | |
| 12979 | 15405 | =end original |
| 12980 | 15406 | |
| 12981 | 15407 | FILENAME で指定したディレクトリが空であれば、 |
| 12982 | 15408 | そのディレクトリを削除します。 |
| 12983 | 成功時には真を返します; さもなければ偽を返して C<$!> | |
| 15409 | 成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> | |
| 12984 | ||
| 15410 | (errno) を設定します。 | |
| 15411 | FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。 | |
| 12985 | 15412 | |
| 12986 | 15413 | =begin original |
| 12987 | 15414 | |
| 12988 | 15415 | To remove a directory tree recursively (C<rm -rf> on Unix) look at |
| 12989 | the C<rmtree> function of the L<File::Path> | |
| 15416 | the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path> | |
| 15417 | module. | |
| 12990 | 15418 | |
| 12991 | 15419 | =end original |
| 12992 | 15420 | |
| 12993 | 15421 | ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、 |
| 12994 | L<File::Path> モジュールの C<rmtree> 関数を | |
| 15422 | L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を | |
| 15423 | 参照してください。 | |
| 12995 | 15424 | |
| 12996 | 15425 | =item s/// |
| 12997 | 15426 | |
| 12998 | 15427 | =for Pod::Functions replace a pattern with a string |
| 12999 | 15428 | |
| 13000 | 15429 | =begin original |
| 13001 | 15430 | |
| 13002 | 15431 | The substitution operator. See L<perlop/"Regexp Quote-Like Operators">. |
| 13003 | 15432 | |
| 13004 | 15433 | =end original |
| 13005 | 15434 | |
| 13006 | 15435 | 置換演算子。 |
| 13007 | 15436 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 |
| 13008 | 15437 | |
| 13009 | 15438 | =item say FILEHANDLE LIST |
| 13010 | 15439 | X<say> |
| 13011 | 15440 | |
| 13012 | 15441 | =item say FILEHANDLE |
| 13013 | 15442 | |
| 13014 | 15443 | =item say LIST |
| 13015 | 15444 | |
| 13016 | 15445 | =item say |
| 13017 | 15446 | |
| 13018 | 15447 | =for Pod::Functions +say output a list to a filehandle, appending a newline |
| 13019 | 15448 | |
| 13020 | 15449 | =begin original |
| 13021 | 15450 | |
| 13022 | Just like C<print>, but implicitly appends a | |
| 15451 | Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a | |
| 13023 | ||
| 15452 | newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\> | |
| 13024 | FILEHANDLE without a LIST to | |
| 15453 | might have. To use FILEHANDLE without a LIST to | |
| 13025 | ||
| 15454 | print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword | |
| 15455 | filehandle like C<FH>, not an indirect one like C<$fh>. | |
| 13026 | 15456 | |
| 13027 | 15457 | =end original |
| 13028 | 15458 | |
| 13029 | C<print> と同様ですが、 | |
| 15459 | L<C<print>|/print FILEHANDLE LIST> と同様ですが、 | |
| 13030 | ||
| 15460 | L<C<$\>|perlvar/$\> の値の代わりに LIST の末尾に | |
| 13031 | ||
| 15461 | 改行が暗黙に追加されます。 | |
| 13032 | C<$ | |
| 15462 | L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を | |
| 13033 | ファイルハンドル | |
| 15463 | 使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような | |
| 15464 | 裸の単語のファイルハンドルを使わなければなりません。 | |
| 13034 | 15465 | |
| 13035 | 15466 | =begin original |
| 13036 | 15467 | |
| 13037 | ||
| 15468 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
| 13038 | is enabled | |
| 15469 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is | |
| 13039 | ||
| 15470 | prefixed with C<CORE::>. The | |
| 13040 | s | |
| 15471 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically | |
| 15472 | with a C<use v5.10> (or higher) declaration in the current scope. | |
| 13041 | 15473 | |
| 13042 | 15474 | =end original |
| 13043 | 15475 | |
| 13044 | ||
| 15476 | L<C<say>|/say FILEHANDLE LIST> は | |
| 13045 | ||
| 15477 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
| 13046 | ||
| 15478 | 前置されたときにのみ利用可能です。 | |
| 15479 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
| 15480 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 13047 | 15481 | |
| 13048 | 15482 | =item scalar EXPR |
| 13049 | 15483 | X<scalar> X<context> |
| 13050 | 15484 | |
| 13051 | 15485 | =for Pod::Functions force a scalar context |
| 13052 | 15486 | |
| 13053 | 15487 | =begin original |
| 13054 | 15488 | |
| 13055 | 15489 | Forces EXPR to be interpreted in scalar context and returns the value |
| 13056 | 15490 | of EXPR. |
| 13057 | 15491 | |
| 13058 | 15492 | =end original |
| 13059 | 15493 | |
| 13060 | 15494 | EXPR を強制的にスカラコンテキストで解釈されるようにして、 |
| 13061 | 15495 | EXPR の値を返します。 |
| 13062 | 15496 | |
| 13063 | @counts = ( scalar @a, scalar @b, scalar @c ); | |
| 15497 | my @counts = ( scalar @a, scalar @b, scalar @c ); | |
| 13064 | 15498 | |
| 13065 | 15499 | =begin original |
| 13066 | 15500 | |
| 13067 | 15501 | There is no equivalent operator to force an expression to |
| 13068 | 15502 | be interpolated in list context because in practice, this is never |
| 13069 | 15503 | needed. If you really wanted to do so, however, you could use |
| 13070 | 15504 | the construction C<@{[ (some expression) ]}>, but usually a simple |
| 13071 | 15505 | C<(some expression)> suffices. |
| 13072 | 15506 | |
| 13073 | 15507 | =end original |
| 13074 | 15508 | |
| 13075 | 15509 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません; |
| 13076 | 15510 | 理論的には不要だからです。 |
| 13077 | 15511 | それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を |
| 13078 | 15512 | 使えます; しかし、普通は単に C<(some expression)> とすれば十分です。 |
| 13079 | 15513 | |
| 13080 | 15514 | =begin original |
| 13081 | 15515 | |
| 13082 | Because C<scalar> is a unary operator, if you | |
| 15516 | Because L<C<scalar>|/scalar EXPR> is a unary operator, if you | |
| 15517 | accidentally use a | |
| 13083 | 15518 | parenthesized list for the EXPR, this behaves as a scalar comma expression, |
| 13084 | 15519 | evaluating all but the last element in void context and returning the final |
| 13085 | 15520 | element evaluated in scalar context. This is seldom what you want. |
| 13086 | 15521 | |
| 13087 | 15522 | =end original |
| 13088 | 15523 | |
| 13089 | C<scalar> は単項演算子なので、EXPR として括弧でくくった | |
| 15524 | L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった | |
| 13090 | これはスカラカンマ表現として振舞い、最後以外の全ては | |
| 15525 | リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては | |
| 13091 | 扱われ、最後の要素をスカラコンテキストとして扱った | |
| 15526 | 無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った | |
| 15527 | 結果が返されます。 | |
| 13092 | 15528 | これがあなたの望むものであることはめったにないでしょう。 |
| 13093 | 15529 | |
| 13094 | 15530 | =begin original |
| 13095 | 15531 | |
| 13096 | 15532 | The following single statement: |
| 13097 | 15533 | |
| 13098 | 15534 | =end original |
| 13099 | 15535 | |
| 13100 | 15536 | 以下の一つの文は: |
| 13101 | 15537 | |
| 13102 | print uc(scalar( | |
| 15538 | print uc(scalar(foo(), $bar)), $baz; | |
| 13103 | 15539 | |
| 13104 | 15540 | =begin original |
| 13105 | 15541 | |
| 13106 | 15542 | is the moral equivalent of these two: |
| 13107 | 15543 | |
| 13108 | 15544 | =end original |
| 13109 | 15545 | |
| 13110 | 15546 | 以下の二つの文と等価です。 |
| 13111 | 15547 | |
| 13112 | | |
| 15548 | foo(); | |
| 13113 | print(uc($bar),$baz); | |
| 15549 | print(uc($bar), $baz); | |
| 13114 | 15550 | |
| 13115 | 15551 | =begin original |
| 13116 | 15552 | |
| 13117 | See L<perlop> for more details on unary operators and the comma operator | |
| 15553 | See L<perlop> for more details on unary operators and the comma operator, | |
| 15554 | and L<perldata> for details on evaluating a hash in scalar context. | |
| 13118 | 15555 | |
| 13119 | 15556 | =end original |
| 13120 | 15557 | |
| 13121 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を | |
| 15558 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を、 | |
| 15559 | スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を | |
| 15560 | 参照してください。 | |
| 13122 | 15561 | |
| 13123 | 15562 | =item seek FILEHANDLE,POSITION,WHENCE |
| 13124 | 15563 | X<seek> X<fseek> X<filehandle, position> |
| 13125 | 15564 | |
| 13126 | 15565 | =for Pod::Functions reposition file pointer for random-access I/O |
| 13127 | 15566 | |
| 13128 | 15567 | =begin original |
| 13129 | 15568 | |
| 13130 | Sets FILEHANDLE's position, just like the | |
| 15569 | Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>. | |
| 13131 | 15570 | FILEHANDLE may be an expression whose value gives the name of the |
| 13132 | 15571 | filehandle. The values for WHENCE are C<0> to set the new position |
| 13133 | 15572 | I<in bytes> to POSITION; C<1> to set it to the current position plus |
| 13134 | 15573 | POSITION; and C<2> to set it to EOF plus POSITION, typically |
| 13135 | 15574 | negative. For WHENCE you may use the constants C<SEEK_SET>, |
| 13136 | 15575 | C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end |
| 13137 | 15576 | of the file) from the L<Fcntl> module. Returns C<1> on success, false |
| 13138 | 15577 | otherwise. |
| 13139 | 15578 | |
| 13140 | 15579 | =end original |
| 13141 | 15580 | |
| 13142 | C<stdio> ライブラリの | |
| 15581 | C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の | |
| 13143 | 15582 | ファイルポインタを任意の位置に設定します。 |
| 13144 | 15583 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
| 13145 | 15584 | WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ |
| 13146 | 設定します; C<1> ならば、現在位置から | |
| 15585 | 設定します; C<1> ならば、現在位置から POSITION 加えた位置へ | |
| 13147 | 15586 | 設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を |
| 13148 | 15587 | 設定します。 |
| 13149 | 15588 | この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、 |
| 13150 | 15589 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
| 13151 | 15590 | 使うこともできます。 |
| 13152 | 成功時には、C<1> を、失敗時には | |
| 15591 | 成功時には、C<1> を、失敗時にはそれ以外を返します。 | |
| 13153 | 15592 | |
| 13154 | 15593 | =begin original |
| 13155 | 15594 | |
| 13156 | Note the | |
| 15595 | Note the emphasis on bytes: even if the filehandle has been set to operate | |
| 13157 | o | |
| 15596 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the | |
| 13158 | ||
| 15597 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 13159 | ||
| 15598 | L<C<tell>|/tell FILEHANDLE>, and | |
| 15599 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 15600 | family of functions use byte offsets, not character offsets, | |
| 15601 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 13160 | 15602 | |
| 13161 | 15603 | =end original |
| 13162 | 15604 | |
| 13163 | ||
| 15605 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) | |
| 13164 | ||
| 15606 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 | |
| 13165 | ||
| 15607 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 13166 | ||
| 15608 | L<C<tell>|/tell FILEHANDLE>, | |
| 15609 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 15610 | 文字オフセットではなくバイトオフセットを使います; | |
| 15611 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 13167 | 15612 | |
| 13168 | 15613 | =begin original |
| 13169 | 15614 | |
| 13170 | If you want to position the file for | |
| 15615 | If you want to position the file for | |
| 13171 | C<s | |
| 15616 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
| 13172 | ||
| 15617 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use | |
| 15618 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its | |
| 15619 | effect on the file's read-write position unpredictable and non-portable. | |
| 15620 | Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead. | |
| 13173 | 15621 | |
| 13174 | 15622 | =end original |
| 13175 | 15623 | |
| 13176 | C<sysread> | |
| 15624 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
| 13177 | C<see | |
| 15625 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの | |
| 15626 | 位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は | |
| 15627 | 使えません; なぜならバッファリングのためにファイルの読み込み位置は | |
| 13178 | 15628 | 動作は予測不能で移植性のないものになってしまいます。 |
| 13179 | 代わりに C<sysseek> を使ってください。 | |
| 15629 | 代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。 | |
| 13180 | 15630 | |
| 13181 | 15631 | =begin original |
| 13182 | 15632 | |
| 13183 | 15633 | Due to the rules and rigors of ANSI C, on some systems you have to do a |
| 13184 | 15634 | seek whenever you switch between reading and writing. Amongst other |
| 13185 | things, this may have the effect of calling stdio's clearerr(3). | |
| 15635 | things, this may have the effect of calling stdio's L<clearerr(3)>. | |
| 13186 | 15636 | A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position: |
| 13187 | 15637 | |
| 13188 | 15638 | =end original |
| 13189 | 15639 | |
| 13190 | 15640 | ANSI C の規則と困難により、システムによっては読み込みと書き込みを |
| 13191 | 15641 | 切り替える度にシークしなければならない場合があります。 |
| 13192 | その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。 | |
| 15642 | その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。 | |
| 13193 | 15643 | WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です: |
| 13194 | 15644 | |
| 13195 | seek( | |
| 15645 | seek($fh, 0, 1); | |
| 13196 | 15646 | |
| 13197 | 15647 | =begin original |
| 13198 | 15648 | |
| 13199 | 15649 | This is also useful for applications emulating C<tail -f>. Once you hit |
| 13200 | 15650 | EOF on your read and then sleep for a while, you (probably) have to stick in a |
| 13201 | dummy seek | |
| 15651 | dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The | |
| 15652 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position, | |
| 13202 | 15653 | but it I<does> clear the end-of-file condition on the handle, so that the |
| 13203 | next C< | |
| 15654 | next C<readline FILE> makes Perl try again to read something. (We hope.) | |
| 13204 | 15655 | |
| 13205 | 15656 | =end original |
| 13206 | 15657 | |
| 13207 | 15658 | これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。 |
| 13208 | 15659 | 一度読み込み時に EOF に到達すると、しばらくスリープし、 |
| 13209 | (おそらく) ダミーの seek | |
| 15660 | (おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで | |
| 13210 | ||
| 15661 | リセットする必要があります。 | |
| 13211 | ||
| 15662 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置を変更しませんが、 | |
| 13212 | ||
| 15663 | ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は | |
| 15664 | 再び何かを読み込もうとします。(そのはずです。) | |
| 13213 | 15665 | |
| 13214 | 15666 | =begin original |
| 13215 | 15667 | |
| 13216 | 15668 | If that doesn't work (some I/O implementations are particularly |
| 13217 | 15669 | cantankerous), you might need something like this: |
| 13218 | 15670 | |
| 13219 | 15671 | =end original |
| 13220 | 15672 | |
| 13221 | 15673 | これが動かない場合(特に意地の悪い I/O 実装もあります)、 |
| 13222 | 15674 | 以下のようなことをする必要があります: |
| 13223 | 15675 | |
| 13224 | 15676 | for (;;) { |
| 13225 | for ($curpos = tell( | |
| 15677 | for ($curpos = tell($fh); $_ = readline($fh); | |
| 13226 | $curpos = tell( | |
| 15678 | $curpos = tell($fh)) { | |
| 13227 | 15679 | # search for some stuff and put it into files |
| 13228 | 15680 | } |
| 13229 | 15681 | sleep($for_a_while); |
| 13230 | seek( | |
| 15682 | seek($fh, $curpos, 0); | |
| 13231 | 15683 | } |
| 13232 | 15684 | |
| 13233 | 15685 | =item seekdir DIRHANDLE,POS |
| 13234 | 15686 | X<seekdir> |
| 13235 | 15687 | |
| 13236 | 15688 | =for Pod::Functions reposition directory pointer |
| 13237 | 15689 | |
| 13238 | 15690 | =begin original |
| 13239 | 15691 | |
| 13240 | Sets the current position for the C<readdir> | |
| 15692 | Sets the current position for the L<C<readdir>|/readdir DIRHANDLE> | |
| 13241 | must be a value returned by | |
| 15693 | routine on DIRHANDLE. POS must be a value returned by | |
| 13242 | ||
| 15694 | L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS> | |
| 13243 | ||
| 15695 | also has the same caveats about possible directory compaction as the | |
| 15696 | corresponding system library routine. | |
| 13244 | 15697 | |
| 13245 | 15698 | =end original |
| 13246 | 15699 | |
| 13247 | DIRHANDLE での C<readdir> ルーチンの現在位置を | |
| 15700 | DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を | |
| 13248 | ||
| 15701 | 設定します。 | |
| 13249 | C< | |
| 15702 | POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。 | |
| 13250 | ||
| 15703 | L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラリルーチンと | |
| 15704 | 同じく、ディレクトリ縮小時の問題が考えられます。 | |
| 13251 | 15705 | |
| 13252 | 15706 | =item select FILEHANDLE |
| 13253 | 15707 | X<select> X<filehandle, default> |
| 13254 | 15708 | |
| 13255 | 15709 | =item select |
| 13256 | 15710 | |
| 13257 | 15711 | =for Pod::Functions reset default output or do I/O multiplexing |
| 13258 | 15712 | |
| 13259 | 15713 | =begin original |
| 13260 | 15714 | |
| 13261 | 15715 | Returns the currently selected filehandle. If FILEHANDLE is supplied, |
| 13262 | 15716 | sets the new current default filehandle for output. This has two |
| 13263 | effects: first, a C<write> | |
| 15717 | effects: first, a L<C<write>|/write FILEHANDLE>, L<C<print>|/print | |
| 13264 | ||
| 15718 | FILEHANDLE LIST>, or L<C<say>|/say FILEHANDLE LIST> without a | |
| 13265 | ||
| 15719 | filehandle default to this FILEHANDLE. Second, references to variables | |
| 15720 | related to output will refer to this output channel. | |
| 13266 | 15721 | |
| 13267 | 15722 | =end original |
| 13268 | 15723 | |
| 13269 | 15724 | その時点で、選択されていたファイルハンドルを返します。 |
| 13270 | 15725 | FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに |
| 13271 | 15726 | 設定します。 |
| 13272 | 15727 | これには、2 つの効果があります: まず、ファイルハンドルを指定しないで |
| 13273 | C<write> | |
| 15728 | L<C<write>|/write FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>, | |
| 13274 | ||
| 15729 | L<C<say>|/say FILEHANDLE LIST> を | |
| 15730 | 行なった場合のデフォルトが、この FILEHANDLE になります。 | |
| 13275 | 15731 | もう一つは、出力関連の変数への参照は、この出力チャネルを |
| 13276 | 参照するようになります。 | |
| 15732 | 参照するようになります。 | |
| 13277 | 15733 | |
| 13278 | 15734 | =begin original |
| 13279 | 15735 | |
| 13280 | 15736 | For example, to set the top-of-form format for more than one |
| 13281 | 15737 | output channel, you might do the following: |
| 13282 | 15738 | |
| 13283 | 15739 | =end original |
| 13284 | 15740 | |
| 13285 | 15741 | 例えば、複数の出力チャネルに対して、ページ先頭フォーマットを |
| 13286 | 15742 | 設定するには: |
| 13287 | 15743 | |
| 13288 | 15744 | select(REPORT1); |
| 13289 | 15745 | $^ = 'report1_top'; |
| 13290 | 15746 | select(REPORT2); |
| 13291 | 15747 | $^ = 'report2_top'; |
| 13292 | 15748 | |
| 13293 | 15749 | =begin original |
| 13294 | 15750 | |
| 13295 | 15751 | FILEHANDLE may be an expression whose value gives the name of the |
| 13296 | 15752 | actual filehandle. Thus: |
| 13297 | 15753 | |
| 13298 | 15754 | =end original |
| 13299 | 15755 | |
| 13300 | 15756 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
| 13301 | 15757 | つまり、以下のようなものです: |
| 13302 | 15758 | |
| 13303 | $oldfh = select(STDERR); $| = 1; select($oldfh); | |
| 15759 | my $oldfh = select(STDERR); $| = 1; select($oldfh); | |
| 13304 | 15760 | |
| 13305 | 15761 | =begin original |
| 13306 | 15762 | |
| 13307 | 15763 | Some programmers may prefer to think of filehandles as objects with |
| 13308 | 15764 | methods, preferring to write the last example as: |
| 13309 | 15765 | |
| 13310 | 15766 | =end original |
| 13311 | 15767 | |
| 13312 | 15768 | ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む |
| 13313 | 15769 | プログラマもいるかもしれません; そのような場合のための最後の例は |
| 13314 | 15770 | 以下のようなものです: |
| 13315 | 15771 | |
| 13316 | use IO::Handle; | |
| 13317 | 15772 | STDERR->autoflush(1); |
| 13318 | 15773 | |
| 13319 | 15774 | =begin original |
| 13320 | 15775 | |
| 15776 | (Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly | |
| 15777 | first.) | |
| 15778 | ||
| 15779 | =end original | |
| 15780 | ||
| 15781 | (Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする | |
| 15782 | 必要があります。) | |
| 15783 | ||
| 15784 | =begin original | |
| 15785 | ||
| 15786 | Whilst you can use C<select> to temporarily "capture" the output of | |
| 15787 | C<print> like this: | |
| 15788 | ||
| 15789 | =end original | |
| 15790 | ||
| 15791 | Whilst you can use C<select> to temporarily "capture" the output of | |
| 15792 | C<print> like this: | |
| 15793 | (TBT) | |
| 15794 | ||
| 15795 | { | |
| 15796 | my $old_handle = select $new_handle; | |
| 15797 | ||
| 15798 | # This goes to $new_handle: | |
| 15799 | print "ok 1\n"; | |
| 15800 | ... | |
| 15801 | ||
| 15802 | select $old_handle; | |
| 15803 | } | |
| 15804 | ||
| 15805 | =begin original | |
| 15806 | ||
| 15807 | you might find it easier to localize the typeglob instead: | |
| 15808 | ||
| 15809 | =end original | |
| 15810 | ||
| 15811 | you might find it easier to localize the typeglob instead: | |
| 15812 | (TBT) | |
| 15813 | ||
| 15814 | { | |
| 15815 | local *STDOUT = $new_handle; | |
| 15816 | ||
| 15817 | print "ok 1\n"; | |
| 15818 | ... | |
| 15819 | } | |
| 15820 | ||
| 15821 | =begin original | |
| 15822 | ||
| 15823 | The two are not exactly equivalent, but the latter might be clearer and will | |
| 15824 | restore STDOUT if the wrapped code dies. The difference is that in the | |
| 15825 | former, the original STDOUT can still be accessed by explicitly using it in a | |
| 15826 | C<print> statement (as C<print STDOUT ...>), whereas in the latter the meaning | |
| 15827 | of the STDOUT handle itself has temporarily been changed. | |
| 15828 | ||
| 15829 | =end original | |
| 15830 | ||
| 15831 | The two are not exactly equivalent, but the latter might be clearer and will | |
| 15832 | restore STDOUT if the wrapped code dies. The difference is that in the | |
| 15833 | former, the original STDOUT can still be accessed by explicitly using it in a | |
| 15834 | C<print> statement (as C<print STDOUT ...>), whereas in the latter the meaning | |
| 15835 | of the STDOUT handle itself has temporarily been changed. | |
| 15836 | (TBT) | |
| 15837 | ||
| 15838 | =begin original | |
| 15839 | ||
| 13321 | 15840 | Portability issues: L<perlport/select>. |
| 13322 | 15841 | |
| 13323 | 15842 | =end original |
| 13324 | 15843 | |
| 13325 | 15844 | 移植性の問題: L<perlport/select>。 |
| 13326 | 15845 | |
| 13327 | 15846 | =item select RBITS,WBITS,EBITS,TIMEOUT |
| 13328 | 15847 | X<select> |
| 13329 | 15848 | |
| 13330 | 15849 | =begin original |
| 13331 | 15850 | |
| 13332 | This calls the select(2) syscall with the bit masks specified, which | |
| 15851 | This calls the L<select(2)> syscall with the bit masks specified, which | |
| 13333 | can be constructed using C<fileno> | |
| 15852 | can be constructed using L<C<fileno>|/fileno FILEHANDLE> and | |
| 15853 | L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines: | |
| 13334 | 15854 | |
| 13335 | 15855 | =end original |
| 13336 | 15856 | |
| 13337 | これは、select(2) システムコールを、指定したビットマスクで呼び出します; | |
| 15857 | これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します; | |
| 13338 | ビットマスクは、C<fileno> | |
| 15858 | ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と | |
| 13339 | 作成できます: | |
| 15859 | L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます: | |
| 13340 | 15860 | |
| 13341 | $rin = $win = $ein = ''; | |
| 15861 | my $rin = my $win = my $ein = ''; | |
| 13342 | 15862 | vec($rin, fileno(STDIN), 1) = 1; |
| 13343 | 15863 | vec($win, fileno(STDOUT), 1) = 1; |
| 13344 | 15864 | $ein = $rin | $win; |
| 13345 | 15865 | |
| 13346 | 15866 | =begin original |
| 13347 | 15867 | |
| 13348 | 15868 | If you want to select on many filehandles, you may wish to write a |
| 13349 | 15869 | subroutine like this: |
| 13350 | 15870 | |
| 13351 | 15871 | =end original |
| 13352 | 15872 | |
| 13353 | 15873 | 複数のファイルハンドルに select を行ないたいのであれば、 |
| 13354 | 15874 | 以下のようにします: |
| 13355 | 15875 | |
| 13356 | 15876 | sub fhbits { |
| 13357 | 15877 | my @fhlist = @_; |
| 13358 | 15878 | my $bits = ""; |
| 13359 | 15879 | for my $fh (@fhlist) { |
| 13360 | 15880 | vec($bits, fileno($fh), 1) = 1; |
| 13361 | 15881 | } |
| 13362 | 15882 | return $bits; |
| 13363 | 15883 | } |
| 13364 | $rin = fhbits(*STDIN, | |
| 15884 | my $rin = fhbits(\*STDIN, $tty, $mysock); | |
| 13365 | 15885 | |
| 13366 | 15886 | =begin original |
| 13367 | 15887 | |
| 13368 | 15888 | The usual idiom is: |
| 13369 | 15889 | |
| 13370 | 15890 | =end original |
| 13371 | 15891 | |
| 13372 | 15892 | 通常は、 |
| 13373 | 15893 | |
| 13374 | | |
| 15894 | my ($nfound, $timeleft) = | |
| 13375 | | |
| 15895 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, | |
| 15896 | $timeout); | |
| 13376 | 15897 | |
| 13377 | 15898 | =begin original |
| 13378 | 15899 | |
| 13379 | 15900 | or to block until something becomes ready just do this |
| 13380 | 15901 | |
| 13381 | 15902 | =end original |
| 13382 | 15903 | |
| 13383 | 15904 | のように使い、いずれかの準備が整うまでブロックするには、 |
| 13384 | 15905 | 以下のようにします。 |
| 13385 | 15906 | |
| 13386 | | |
| 15907 | my $nfound = | |
| 15908 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); | |
| 13387 | 15909 | |
| 13388 | 15910 | =begin original |
| 13389 | 15911 | |
| 13390 | Most systems do not bother to return anything useful in $timeleft, so | |
| 15912 | Most systems do not bother to return anything useful in C<$timeleft>, so | |
| 13391 | calling select | |
| 15913 | calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context | |
| 15914 | just returns C<$nfound>. | |
| 13392 | 15915 | |
| 13393 | 15916 | =end original |
| 13394 | 15917 | |
| 13395 | ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、 | |
| 15918 | ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、 | |
| 13396 | select | |
| 15919 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで | |
| 15920 | 呼び出すと、単に C<$nfound> を返します。 | |
| 13397 | 15921 | |
| 13398 | 15922 | =begin original |
| 13399 | 15923 | |
| 13400 | Any of the bit masks can also be undef. The timeout, | |
| 15924 | Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout, | |
| 15925 | if specified, is | |
| 13401 | 15926 | in seconds, which may be fractional. Note: not all implementations are |
| 13402 | capable of returning the $timeleft. If not, they always return | |
| 15927 | capable of returning the C<$timeleft>. If not, they always return | |
| 13403 | $timeleft equal to the supplied $timeout. | |
| 15928 | C<$timeleft> equal to the supplied C<$timeout>. | |
| 13404 | 15929 | |
| 13405 | 15930 | =end original |
| 13406 | 15931 | |
| 13407 | どのビットマスクにも undef を設定することができます。 | |
| 15932 | どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。 | |
| 13408 | 15933 | TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。 |
| 13409 | 注: すべての実装で、$timeleft が返せるものではありません。 | |
| 15934 | 注: すべての実装で、C<$timeleft> が返せるものではありません。 | |
| 13410 | その場合、$timeleft には、常に指定した | |
| 15935 | その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。 | |
| 13411 | 15936 | |
| 13412 | 15937 | =begin original |
| 13413 | 15938 | |
| 13414 | 15939 | You can effect a sleep of 250 milliseconds this way: |
| 13415 | 15940 | |
| 13416 | 15941 | =end original |
| 13417 | 15942 | |
| 13418 | 15943 | 250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。 |
| 13419 | 15944 | |
| 13420 | 15945 | select(undef, undef, undef, 0.25); |
| 13421 | 15946 | |
| 13422 | 15947 | =begin original |
| 13423 | 15948 | |
| 13424 | Note that whether C<select> | |
| 15949 | Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets | |
| 13425 | is implementation-dependent. Se | |
| 15950 | restarted after signals (say, SIGALRM) is implementation-dependent. See | |
| 13426 | portability of | |
| 15951 | also L<perlport> for notes on the portability of | |
| 15952 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>. | |
| 13427 | 15953 | |
| 13428 | 15954 | =end original |
| 13429 | 15955 | |
| 13430 | C<select> がシグナル (例えば、SIGALRM) の | |
| 15956 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の | |
| 13431 | 実装依存であることに注意してください。 | |
| 15957 | 後に再起動するかどうかは実装依存であることに注意してください。 | |
| 13432 | C<select> の移植性に関する | |
| 15958 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する | |
| 15959 | 注意については L<perlport> も参照してください。 | |
| 13433 | 15960 | |
| 13434 | 15961 | =begin original |
| 13435 | 15962 | |
| 13436 | On error, C<select> behaves just | |
| 15963 | On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just | |
| 13437 | -1 and sets C<$!>. | |
| 15964 | like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>. | |
| 13438 | 15965 | |
| 13439 | 15966 | =end original |
| 13440 | 15967 | |
| 13441 | エラー時は、C<select> | |
| 15968 | エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は | |
| 13442 | ||
| 15969 | L<select(2)> のように振舞います: | |
| 15970 | C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。 | |
| 13443 | 15971 | |
| 13444 | 15972 | =begin original |
| 13445 | 15973 | |
| 13446 | On some Unixes, select(2) may report a socket file descriptor as | |
| 15974 | On some Unixes, L<select(2)> may report a socket file descriptor as | |
| 13447 | reading" even when no data is available, and thus any | |
| 15975 | "ready for reading" even when no data is available, and thus any | |
| 13448 | ||
| 15976 | subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block. | |
| 13449 | s | |
| 15977 | This can be avoided if you always use C<O_NONBLOCK> on the socket. See | |
| 15978 | L<select(2)> and L<fcntl(2)> for further details. | |
| 13450 | 15979 | |
| 13451 | 15980 | =end original |
| 13452 | 15981 | |
| 13453 | Unix の中には、実際に利用可能なデータがないために引き続く | |
| 15982 | Unix の中には、実際に利用可能なデータがないために引き続く | |
| 13454 | ||
| 15983 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が | |
| 15984 | ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が | |
| 13455 | 15985 | 「読み込み準備中」であると報告するものもあります。 |
| 13456 | これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。 | |
| 15986 | これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。 | |
| 13457 | さらなる詳細については select(2) と fcntl(2) を参照してください。 | |
| 15987 | さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。 | |
| 13458 | 15988 | |
| 13459 | 15989 | =begin original |
| 13460 | 15990 | |
| 13461 | The standard C<IO::Select> module provides a | |
| 15991 | The standard L<C<IO::Select>|IO::Select> module provides a | |
| 13462 | ||
| 15992 | user-friendlier interface to | |
| 15993 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does | |
| 15994 | all the bit-mask work for you. | |
| 13463 | 15995 | |
| 13464 | 15996 | =end original |
| 13465 | 15997 | |
| 13466 | 標準の C<IO::Select> | |
| 15998 | 標準の L<C<IO::Select>|IO::Select> モジュールは | |
| 15999 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな | |
| 13467 | 16000 | インターフェースを提供します; 主な理由はビットマスクの仕事を |
| 13468 | 16001 | してくれることです。 |
| 13469 | 16002 | |
| 13470 | 16003 | =begin original |
| 13471 | 16004 | |
| 13472 | B<WARNING>: One should not attempt to mix buffered I/O (like | |
| 16005 | B<WARNING>: One should not attempt to mix buffered I/O (like | |
| 13473 | ||
| 16006 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
| 13474 | ||
| 16007 | L<C<readline>|/readline EXPR>) with | |
| 16008 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by | |
| 16009 | POSIX, and even then only on POSIX systems. You have to use | |
| 16010 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead. | |
| 13475 | 16011 | |
| 13476 | 16012 | =end original |
| 13477 | 16013 | |
| 13478 | B<警告>: バッファ付き I/O (C<read> | |
| 16014 | B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
| 16015 | L<C<readline>|/readline EXPR>) と | |
| 16016 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を | |
| 13479 | 16017 | 混ぜて使ってはいけません(例外: POSIX で認められている形で使い、 |
| 13480 | 16018 | POSIX システムでだけ動かす場合を除きます)。 |
| 13481 | 代わりに C<sysread> を | |
| 16019 | 代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を | |
| 16020 | 使わなければなりません。 | |
| 13482 | 16021 | |
| 13483 | 16022 | =begin original |
| 13484 | 16023 | |
| 13485 | 16024 | Portability issues: L<perlport/select>. |
| 13486 | 16025 | |
| 13487 | 16026 | =end original |
| 13488 | 16027 | |
| 13489 | 16028 | 移植性の問題: L<perlport/select>。 |
| 13490 | 16029 | |
| 13491 | 16030 | =item semctl ID,SEMNUM,CMD,ARG |
| 13492 | 16031 | X<semctl> |
| 13493 | 16032 | |
| 13494 | 16033 | =for Pod::Functions SysV semaphore control operations |
| 13495 | 16034 | |
| 13496 | 16035 | =begin original |
| 13497 | 16036 | |
| 13498 | Calls the System V IPC function semctl(2). You'll probably have to say | |
| 16037 | Calls the System V IPC function L<semctl(2)>. You'll probably have to say | |
| 13499 | 16038 | |
| 13500 | 16039 | =end original |
| 13501 | 16040 | |
| 13502 | System V IPC 関数 semctl(2) を呼び出します。 | |
| 16041 | System V IPC 関数 L<semctl(2)> を呼び出します。 | |
| 13503 | 16042 | 正しい定数定義を得るために、まず |
| 13504 | 16043 | |
| 13505 | 16044 | use IPC::SysV; |
| 13506 | 16045 | |
| 13507 | 16046 | =begin original |
| 13508 | 16047 | |
| 13509 | 16048 | first to get the correct constant definitions. If CMD is IPC_STAT or |
| 13510 | 16049 | GETALL, then ARG must be a variable that will hold the returned |
| 13511 | semid_ds structure or semaphore value array. Returns like | |
| 16050 | semid_ds structure or semaphore value array. Returns like | |
| 16051 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: | |
| 13512 | 16052 | the undefined value for error, "C<0 but true>" for zero, or the actual |
| 13513 | 16053 | return value otherwise. The ARG must consist of a vector of native |
| 13514 | 16054 | short integers, which may be created with C<pack("s!",(0)x$nsem)>. |
| 13515 | See also L<perlipc/"SysV IPC"> | |
| 16055 | See also L<perlipc/"SysV IPC"> and the documentation for | |
| 13516 | d | |
| 16056 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
| 13517 | 16057 | |
| 13518 | 16058 | =end original |
| 13519 | 16059 | |
| 13520 | 16060 | と書くことが必要でしょう。 |
| 13521 | 16061 | CMD が、IPC_STAT か GETALL のときには、ARG は、返される |
| 13522 | 16062 | semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。 |
| 13523 | C<ioctl> と同じように、エラー時には | |
| 16063 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には | |
| 13524 | ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 | |
| 16064 | 未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 | |
| 13525 | 16065 | ARG はネイティブな short int のベクターから成っていなければなりません; これは |
| 13526 | 16066 | C<pack("s!",(0)x$nsem)> で作成できます。 |
| 13527 | L<perlipc/"SysV IPC"> | |
| 16067 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 16068 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
| 13528 | 16069 | |
| 13529 | 16070 | =begin original |
| 13530 | 16071 | |
| 13531 | 16072 | Portability issues: L<perlport/semctl>. |
| 13532 | 16073 | |
| 13533 | 16074 | =end original |
| 13534 | 16075 | |
| 13535 | 16076 | 移植性の問題: L<perlport/semctl>。 |
| 13536 | 16077 | |
| 13537 | 16078 | =item semget KEY,NSEMS,FLAGS |
| 13538 | 16079 | X<semget> |
| 13539 | 16080 | |
| 13540 | 16081 | =for Pod::Functions get set of SysV semaphores |
| 13541 | 16082 | |
| 13542 | 16083 | =begin original |
| 13543 | 16084 | |
| 13544 | Calls the System V IPC function semget(2). Returns the semaphore id, or | |
| 16085 | Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or | |
| 13545 | 16086 | the undefined value on error. See also |
| 13546 | L<perlipc/"SysV IPC"> | |
| 16087 | L<perlipc/"SysV IPC"> and the documentation for | |
| 13547 | d | |
| 16088 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
| 13548 | 16089 | |
| 13549 | 16090 | =end original |
| 13550 | 16091 | |
| 13551 | System V IPC 関数 semget(2) を呼び出します。 | |
| 16092 | System V IPC 関数 L<semget(2)> を呼び出します。 | |
| 13552 | 16093 | セマフォ ID か、エラー時には未定義値を返します。 |
| 13553 | L<perlipc/"SysV IPC"> | |
| 16094 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 13554 | 参照してください。 | |
| 16095 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
| 13555 | 16096 | |
| 13556 | 16097 | =begin original |
| 13557 | 16098 | |
| 13558 | 16099 | Portability issues: L<perlport/semget>. |
| 13559 | 16100 | |
| 13560 | 16101 | =end original |
| 13561 | 16102 | |
| 13562 | 16103 | 移植性の問題: L<perlport/semget>。 |
| 13563 | 16104 | |
| 13564 | 16105 | =item semop KEY,OPSTRING |
| 13565 | 16106 | X<semop> |
| 13566 | 16107 | |
| 13567 | 16108 | =for Pod::Functions SysV semaphore operations |
| 13568 | 16109 | |
| 13569 | 16110 | =begin original |
| 13570 | 16111 | |
| 13571 | Calls the System V IPC function semop(2) for semaphore operations | |
| 16112 | Calls the System V IPC function L<semop(2)> for semaphore operations | |
| 13572 | 16113 | such as signalling and waiting. OPSTRING must be a packed array of |
| 13573 | 16114 | semop structures. Each semop structure can be generated with |
| 13574 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING | |
| 16115 | C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING | |
| 13575 | 16116 | implies the number of semaphore operations. Returns true if |
| 13576 | 16117 | successful, false on error. As an example, the |
| 13577 | 16118 | following code waits on semaphore $semnum of semaphore id $semid: |
| 13578 | 16119 | |
| 13579 | 16120 | =end original |
| 13580 | 16121 | |
| 13581 | 16122 | シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、 |
| 13582 | System V IPC 関数 semop(2) を呼び出します。 | |
| 16123 | System V IPC 関数 L<semop(2)> を呼び出します。 | |
| 13583 | 16124 | OPSTRING は、semop 構造体の pack された配列でなければなりません。 |
| 13584 | semop 構造体は、それぞれ、 | |
| 16125 | semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように | |
| 13585 | ||
| 16126 | 作ることができます。 | |
| 13586 | 16127 | セマフォ操作の数は、OPSTRING の長さからわかります。 |
| 13587 | 16128 | 成功時には真を、エラー時には偽を返します。 |
| 13588 | 16129 | 以下の例は、セマフォ ID $semid のセマフォ $semnum で |
| 13589 | 16130 | 待ち合わせを行ないます。 |
| 13590 | 16131 | |
| 13591 | $semop = pack("s!3", $semnum, -1, 0); | |
| 16132 | my $semop = pack("s!3", $semnum, -1, 0); | |
| 13592 | 16133 | die "Semaphore trouble: $!\n" unless semop($semid, $semop); |
| 13593 | 16134 | |
| 13594 | 16135 | =begin original |
| 13595 | 16136 | |
| 13596 | 16137 | To signal the semaphore, replace C<-1> with C<1>. See also |
| 13597 | L<perlipc/"SysV IPC"> | |
| 16138 | L<perlipc/"SysV IPC"> and the documentation for | |
| 13598 | d | |
| 16139 | L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>. | |
| 13599 | 16140 | |
| 13600 | 16141 | =end original |
| 13601 | 16142 | |
| 13602 | 16143 | セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。 |
| 13603 | L<perlipc/"SysV IPC"> | |
| 16144 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と | |
| 13604 | 参照してください。 | |
| 16145 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
| 13605 | 16146 | |
| 13606 | 16147 | =begin original |
| 13607 | 16148 | |
| 13608 | 16149 | Portability issues: L<perlport/semop>. |
| 13609 | 16150 | |
| 13610 | 16151 | =end original |
| 13611 | 16152 | |
| 13612 | 16153 | 移植性の問題: L<perlport/semop>。 |
| 13613 | 16154 | |
| 13614 | 16155 | =item send SOCKET,MSG,FLAGS,TO |
| 13615 | 16156 | X<send> |
| 13616 | 16157 | |
| 13617 | 16158 | =item send SOCKET,MSG,FLAGS |
| 13618 | 16159 | |
| 13619 | 16160 | =for Pod::Functions send a message over a socket |
| 13620 | 16161 | |
| 13621 | 16162 | =begin original |
| 13622 | 16163 | |
| 13623 | 16164 | Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET |
| 13624 | 16165 | filehandle. Takes the same flags as the system call of the same name. On |
| 13625 | 16166 | unconnected sockets, you must specify a destination to I<send to>, in which |
| 13626 | case it does a sendto(2) syscall. Returns the number of characters sent, | |
| 16167 | case it does a L<sendto(2)> syscall. Returns the number of characters sent, | |
| 13627 | or the undefined value on error. The sendmsg(2) syscall is currently | |
| 16168 | or the undefined value on error. The L<sendmsg(2)> syscall is currently | |
| 13628 | 16169 | unimplemented. See L<perlipc/"UDP: Message Passing"> for examples. |
| 13629 | 16170 | |
| 13630 | 16171 | =end original |
| 13631 | 16172 | |
| 13632 | 16173 | ソケットにメッセージを送ります。 |
| 13633 | 16174 | スカラ MSG を ファイルハンドル SOCKET に送ろうとします。 |
| 13634 | 16175 | 同名のシステムコールと同じフラグが指定できます。 |
| 13635 | 16176 | 接続していないソケットには、I<send to> に接続先を指定しなければならず、 |
| 13636 | この場合、sendto(2) を実行します。 | |
| 16177 | この場合、L<sendto(2)> を実行します。 | |
| 13637 | 16178 | 送信した文字数か、エラー時には、未定義値を返します。 |
| 13638 | システムコール sendmsg(2) は現在実装されていません。 | |
| 16179 | システムコール L<sendmsg(2)> は現在実装されていません。 | |
| 13639 | 16180 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
| 13640 | 16181 | |
| 13641 | 16182 | =begin original |
| 13642 | 16183 | |
| 13643 | Note th | |
| 16184 | Note that if the socket has been marked as C<:utf8>, C<send> will | |
| 13644 | ||
| 16185 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
| 13645 | ||
| 16186 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 13646 | binmode() to operate with the C<:encoding(utf8)> I/O layer (see | |
| 13647 | L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8 | |
| 13648 | encoded Unicode characters, not bytes. Similarly for the C<:encoding> | |
| 13649 | pragma: in that case pretty much any characters can be sent. | |
| 13650 | 16187 | |
| 13651 | 16188 | =end original |
| 13652 | 16189 | |
| 13653 | ||
| 16190 | ソケットが C<:utf8> とマークされている場合、 | |
| 13654 | ||
| 16191 | C<send> は例外を投げることに注意してください。 | |
| 13655 | ||
| 16192 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 13656 | ||
| 16193 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
| 13657 | C<open> プラグマ、L<open> を参照してください) を使うように指定された場合、 | |
| 13658 | I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。 | |
| 13659 | C<:encoding> プラグマも同様です: | |
| 13660 | この場合、ほとんど大体全ての文字が書き込めます。 | |
| 13661 | 16194 | |
| 13662 | 16195 | =item setpgrp PID,PGRP |
| 13663 | 16196 | X<setpgrp> X<group> |
| 13664 | 16197 | |
| 13665 | 16198 | =for Pod::Functions set the process group of a process |
| 13666 | 16199 | |
| 13667 | 16200 | =begin original |
| 13668 | 16201 | |
| 13669 | 16202 | Sets the current process group for the specified PID, C<0> for the current |
| 13670 | 16203 | process. Raises an exception when used on a machine that doesn't |
| 13671 | implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments | |
| 16204 | implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments | |
| 13672 | it defaults to C<0,0>. Note that the BSD 4.2 version of | |
| 16205 | are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of | |
| 13673 | accept any arguments, so only | |
| 16206 | L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only | |
| 13674 | C< | |
| 16207 | C<setpgrp(0,0)> is portable. See also | |
| 16208 | L<C<POSIX::setsid()>|POSIX/C<setsid>>. | |
| 13675 | 16209 | |
| 13676 | 16210 | =end original |
| 13677 | 16211 | |
| 13678 | 16212 | 指定した PID (C<0> を指定するとカレントプロセス) に |
| 13679 | 16213 | 対するプロセスグループを設定します。 |
| 13680 | POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、 | |
| 16214 | POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、 | |
| 13681 | 16215 | 例外が発生します。 |
| 13682 | 16216 | 引数が省略された場合は、C<0,0>が使われます。 |
| 13683 | BSD 4.2 版の C<setpgrp> は引数を取ることができないので、 | |
| 16217 | BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、 | |
| 13684 | 16218 | C<setpgrp(0,0)> のみが移植性があることに注意してください。 |
| 13685 | C<POSIX::setsid()> も参照してください。 | |
| 16219 | L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。 | |
| 13686 | 16220 | |
| 13687 | 16221 | =begin original |
| 13688 | 16222 | |
| 13689 | 16223 | Portability issues: L<perlport/setpgrp>. |
| 13690 | 16224 | |
| 13691 | 16225 | =end original |
| 13692 | 16226 | |
| 13693 | 16227 | 移植性の問題: L<perlport/setpgrp>。 |
| 13694 | 16228 | |
| 13695 | 16229 | =item setpriority WHICH,WHO,PRIORITY |
| 13696 | 16230 | X<setpriority> X<priority> X<nice> X<renice> |
| 13697 | 16231 | |
| 13698 | 16232 | =for Pod::Functions set a process's nice value |
| 13699 | 16233 | |
| 13700 | 16234 | =begin original |
| 13701 | 16235 | |
| 13702 | 16236 | Sets the current priority for a process, a process group, or a user. |
| 13703 | (See setpriority(2).) Raises an exception when used on a machine | |
| 16237 | (See L<setpriority(2)>.) Raises an exception when used on a machine | |
| 13704 | that doesn't implement setpriority(2). | |
| 16238 | that doesn't implement L<setpriority(2)>. | |
| 13705 | 16239 | |
| 13706 | 16240 | =end original |
| 13707 | 16241 | |
| 13708 | 16242 | プロセス、プロセスグループ、ユーザに対する優先順位を設定します。 |
| 13709 | (setpriority(2) を参照してください。) | |
| 16243 | (L<setpriority(2)> を参照してください。) | |
| 13710 | setpriority(2) が実装されていないマシンでは、 | |
| 16244 | L<setpriority(2)> が実装されていないマシンでは、例外が発生します。 | |
| 13711 | 例外が発生します。 | |
| 13712 | 16245 | |
| 13713 | 16246 | =begin original |
| 13714 | 16247 | |
| 16248 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
| 16249 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
| 16250 | ||
| 16251 | =end original | |
| 16252 | ||
| 16253 | C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
| 16254 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
| 16255 | ||
| 16256 | =begin original | |
| 16257 | ||
| 13715 | 16258 | Portability issues: L<perlport/setpriority>. |
| 13716 | 16259 | |
| 13717 | 16260 | =end original |
| 13718 | 16261 | |
| 13719 | 16262 | 移植性の問題: L<perlport/setpriority>。 |
| 13720 | 16263 | |
| 13721 | 16264 | =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL |
| 13722 | 16265 | X<setsockopt> |
| 13723 | 16266 | |
| 13724 | 16267 | =for Pod::Functions set some socket options |
| 13725 | 16268 | |
| 13726 | 16269 | =begin original |
| 13727 | 16270 | |
| 13728 | Sets the socket option requested. Returns C<undef> | |
| 16271 | Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on | |
| 13729 | Use integer constants provided by the C<Socket> module | |
| 16272 | error. Use integer constants provided by the L<C<Socket>|Socket> module | |
| 16273 | for | |
| 13730 | 16274 | LEVEL and OPNAME. Values for LEVEL can also be obtained from |
| 13731 | 16275 | getprotobyname. OPTVAL might either be a packed string or an integer. |
| 13732 | 16276 | An integer OPTVAL is shorthand for pack("i", OPTVAL). |
| 13733 | 16277 | |
| 13734 | 16278 | =end original |
| 13735 | 16279 | |
| 13736 | 16280 | 要求したソケットオプションを設定します。 |
| 13737 | エラー時には、C<undef> を返します。 | |
| 16281 | エラー時には、L<C<undef>|/undef EXPR> を返します。 | |
| 13738 | LEVEL と OPNAME には C<Socket> モジュールが提供する | |
| 16282 | LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する | |
| 16283 | 整数定数を使います。 | |
| 13739 | 16284 | LEVEL の値は getprotobyname から得ることもできます。 |
| 13740 | 16285 | OPTVAL は pack された文字列か整数です。 |
| 13741 | 16286 | 整数の OPTVAL は pack("i", OPTVAL) の省略表現です。 |
| 13742 | 16287 | |
| 13743 | 16288 | =begin original |
| 13744 | 16289 | |
| 13745 | 16290 | An example disabling Nagle's algorithm on a socket: |
| 13746 | 16291 | |
| 13747 | 16292 | =end original |
| 13748 | 16293 | |
| 13749 | 16294 | ソケットに対する Nagle のアルゴリズムを無効にする例です: |
| 13750 | 16295 | |
| 13751 | 16296 | use Socket qw(IPPROTO_TCP TCP_NODELAY); |
| 13752 | 16297 | setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); |
| 13753 | 16298 | |
| 13754 | 16299 | =begin original |
| 13755 | 16300 | |
| 13756 | 16301 | Portability issues: L<perlport/setsockopt>. |
| 13757 | 16302 | |
| 13758 | 16303 | =end original |
| 13759 | 16304 | |
| 13760 | 16305 | 移植性の問題: L<perlport/setsockopt>。 |
| 13761 | 16306 | |
| 13762 | 16307 | =item shift ARRAY |
| 13763 | 16308 | X<shift> |
| 13764 | 16309 | |
| 13765 | =item shift EXPR | |
| 13766 | ||
| 13767 | 16310 | =item shift |
| 13768 | 16311 | |
| 13769 | 16312 | =for Pod::Functions remove the first element of an array, and return it |
| 13770 | 16313 | |
| 13771 | 16314 | =begin original |
| 13772 | 16315 | |
| 13773 | ||
| 16316 | Removes and returns the B<first> element of an array. This shortens the | |
| 13774 | array by | |
| 16317 | array by one and moves everything down. | |
| 13775 | array, returns the undefined value. If ARRAY is omitted, shifts the | |
| 13776 | C<@_> array within the lexical scope of subroutines and formats, and the | |
| 13777 | C<@ARGV> array outside a subroutine and also within the lexical scopes | |
| 13778 | established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, | |
| 13779 | C<UNITCHECK {}>, and C<END {}> constructs. | |
| 13780 | 16318 | |
| 13781 | 16319 | =end original |
| 13782 | 16320 | |
| 13783 | 配列の最初の値を | |
| 16321 | 配列の B<最初の> 値を削除して返します。 | |
| 13784 | 短くして、すべての要素を前へずらします。 | |
| 16322 | 配列を一つ短くして、すべての要素を前へずらします。 | |
| 13785 | 配列に要素がなければ、未定義値を返します。 | |
| 13786 | ARRAY を省略すると、 | |
| 13787 | サブルーチンやフォーマットのレキシカルスコープでは C<@_> を、 | |
| 13788 | サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, | |
| 13789 | C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは | |
| 13790 | C<@ARGV> が用いられます。 | |
| 13791 | 16323 | |
| 16324 | my @arr = ('cat', 'dog'); | |
| 16325 | my $item = shift(@arr); # 'cat' | |
| 16326 | ||
| 16327 | # @arr is now ('dog'); | |
| 16328 | ||
| 13792 | 16329 | =begin original |
| 13793 | 16330 | |
| 13794 | ||
| 16331 | Returns C<undef> if the array is empty. | |
| 13795 | reference to an unblessed array. The argument will be dereferenced | |
| 13796 | automatically. This aspect of C<shift> is considered highly experimental. | |
| 13797 | The exact behaviour may change in a future version of Perl. | |
| 13798 | 16332 | |
| 13799 | 16333 | =end original |
| 13800 | 16334 | |
| 13801 | ||
| 16335 | 配列が空なら C<undef> を返します。 | |
| 13802 | これは bless されていない配列へのリファレンスでなければなりません。 | |
| 13803 | 引数は自動的にデリファレンスされます。 | |
| 13804 | C<shift> のこの動作は高度に実験的であると考えられています。 | |
| 13805 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 13806 | 16336 | |
| 13807 | 16337 | =begin original |
| 13808 | 16338 | |
| 13809 | ||
| 16339 | B<Note:> C<shift> may also return C<undef> if the first element in the array | |
| 13810 | ||
| 16340 | is C<undef>. | |
| 13811 | the top of your file to signal that your code will work I<only> on Perls of | |
| 13812 | a recent vintage: | |
| 13813 | 16341 | |
| 13814 | 16342 | =end original |
| 13815 | 16343 | |
| 13816 | ||
| 16344 | B<Note:> C<shift> may also return C<undef> if the first element in the array | |
| 13817 | ||
| 16345 | is C<undef>. | |
| 13818 | ||
| 16346 | (TBT) | |
| 13819 | 書いてください: | |
| 13820 | 16347 | |
| 13821 | | |
| 16348 | my @arr = (undef, 'two', 'three'); | |
| 16349 | my $item = shift(@arr); # undef | |
| 13822 | 16350 | |
| 13823 | 16351 | =begin original |
| 13824 | 16352 | |
| 13825 | ||
| 16353 | If ARRAY is omitted, C<shift> operates on the C<@ARGV> array in the main | |
| 13826 | ||
| 16354 | program, and the C<@_> array in subroutines. C<shift> will operate on the | |
| 13827 | ri | |
| 16355 | C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}> blocks. | |
| 13828 | 16356 | |
| 13829 | 16357 | =end original |
| 13830 | 16358 | |
| 13831 | C< | |
| 16359 | If ARRAY is omitted, C<shift> operates on the C<@ARGV> array in the main | |
| 13832 | C< | |
| 16360 | program, and the C<@_> array in subroutines. C<shift> will operate on the | |
| 13833 | C< | |
| 16361 | C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}> blocks. | |
| 16362 | (TBT) | |
| 13834 | 16363 | |
| 16364 | =begin original | |
| 16365 | ||
| 16366 | Starting with Perl 5.14, an experimental feature allowed | |
| 16367 | L<C<shift>|/shift ARRAY> to take a | |
| 16368 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 16369 | removed as of Perl 5.24. | |
| 16370 | ||
| 16371 | =end original | |
| 16372 | ||
| 16373 | Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという | |
| 16374 | 実験的機能がありました。 | |
| 16375 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 16376 | ||
| 16377 | =begin original | |
| 16378 | ||
| 16379 | See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>, | |
| 16380 | and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and | |
| 16381 | L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of | |
| 16382 | an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to | |
| 16383 | the right end. | |
| 16384 | ||
| 16385 | =end original | |
| 16386 | ||
| 16387 | L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、 | |
| 16388 | L<C<pop>|/pop ARRAY> も参照してください。 | |
| 16389 | L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、 | |
| 16390 | L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で | |
| 16391 | 行なうことを、左端で行ないます。 | |
| 16392 | ||
| 13835 | 16393 | =item shmctl ID,CMD,ARG |
| 13836 | 16394 | X<shmctl> |
| 13837 | 16395 | |
| 13838 | 16396 | =for Pod::Functions SysV shared memory operations |
| 13839 | 16397 | |
| 13840 | 16398 | =begin original |
| 13841 | 16399 | |
| 13842 | 16400 | Calls the System V IPC function shmctl. You'll probably have to say |
| 13843 | 16401 | |
| 13844 | 16402 | =end original |
| 13845 | 16403 | |
| 13846 | 16404 | System V IPC 関数 shmctl を呼び出します。 |
| 13847 | 16405 | 正しい定数定義を得るために、まず |
| 13848 | 16406 | |
| 13849 | 16407 | use IPC::SysV; |
| 13850 | 16408 | |
| 13851 | 16409 | =begin original |
| 13852 | 16410 | |
| 13853 | 16411 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
| 13854 | 16412 | then ARG must be a variable that will hold the returned C<shmid_ds> |
| 13855 | structure. Returns like ioctl: C<undef> for error; "C<0> | |
| 16413 | structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0> | |
| 13856 | true" for zero; and the actual return value otherwise. | |
| 16414 | but true" for zero; and the actual return value otherwise. | |
| 13857 | See also L<perlipc/"SysV IPC"> and | |
| 16415 | See also L<perlipc/"SysV IPC"> and the documentation for | |
| 16416 | L<C<IPC::SysV>|IPC::SysV>. | |
| 13858 | 16417 | |
| 13859 | 16418 | =end original |
| 13860 | 16419 | |
| 13861 | 16420 | と書くことが必要でしょう。 |
| 13862 | 16421 | CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を |
| 13863 | 16422 | 納める変数でなければなりません。 |
| 13864 | ioctl と同様です: エラー時には C<undef>; ゼロのときは | |
| 16423 | ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは | |
| 13865 | それ以外なら、その値そのものを返します。 | |
| 16424 | "C<0> だが真"; それ以外なら、その値そのものを返します。 | |
| 13866 | L<perlipc/"SysV IPC"> | |
| 16425 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書も | |
| 16426 | 参照してください。 | |
| 13867 | 16427 | |
| 13868 | 16428 | =begin original |
| 13869 | 16429 | |
| 13870 | 16430 | Portability issues: L<perlport/shmctl>. |
| 13871 | 16431 | |
| 13872 | 16432 | =end original |
| 13873 | 16433 | |
| 13874 | 16434 | 移植性の問題: L<perlport/shmctl>。 |
| 13875 | 16435 | |
| 13876 | 16436 | =item shmget KEY,SIZE,FLAGS |
| 13877 | 16437 | X<shmget> |
| 13878 | 16438 | |
| 13879 | 16439 | =for Pod::Functions get SysV shared memory segment identifier |
| 13880 | 16440 | |
| 13881 | 16441 | =begin original |
| 13882 | 16442 | |
| 13883 | 16443 | Calls the System V IPC function shmget. Returns the shared memory |
| 13884 | segment id, or C<undef> on error. | |
| 16444 | segment id, or L<C<undef>|/undef EXPR> on error. | |
| 13885 | See also L<perlipc/"SysV IPC"> and | |
| 16445 | See also L<perlipc/"SysV IPC"> and the documentation for | |
| 16446 | L<C<IPC::SysV>|IPC::SysV>. | |
| 13886 | 16447 | |
| 13887 | 16448 | =end original |
| 13888 | 16449 | |
| 13889 | 16450 | System V IPC 関数 shmget を呼び出します。 |
| 13890 | 共有メモリのセグメント ID か、エラー時には C<undef> を返します。 | |
| 16451 | 共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
| 13891 | L<perlipc/"SysV IPC"> | |
| 16452 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書も | |
| 16453 | 参照してください。 | |
| 13892 | 16454 | |
| 13893 | 16455 | =begin original |
| 13894 | 16456 | |
| 13895 | 16457 | Portability issues: L<perlport/shmget>. |
| 13896 | 16458 | |
| 13897 | 16459 | =end original |
| 13898 | 16460 | |
| 13899 | 16461 | 移植性の問題: L<perlport/shmget>。 |
| 13900 | 16462 | |
| 13901 | 16463 | =item shmread ID,VAR,POS,SIZE |
| 13902 | 16464 | X<shmread> |
| 13903 | 16465 | X<shmwrite> |
| 13904 | 16466 | |
| 13905 | 16467 | =for Pod::Functions read SysV shared memory |
| 13906 | 16468 | |
| 13907 | 16469 | =item shmwrite ID,STRING,POS,SIZE |
| 13908 | 16470 | |
| 13909 | 16471 | =for Pod::Functions write SysV shared memory |
| 13910 | 16472 | |
| 13911 | 16473 | =begin original |
| 13912 | 16474 | |
| 13913 | 16475 | Reads or writes the System V shared memory segment ID starting at |
| 13914 | 16476 | position POS for size SIZE by attaching to it, copying in/out, and |
| 13915 | 16477 | detaching from it. When reading, VAR must be a variable that will |
| 13916 | 16478 | hold the data read. When writing, if STRING is too long, only SIZE |
| 13917 | 16479 | bytes are used; if STRING is too short, nulls are written to fill out |
| 13918 | 16480 | SIZE bytes. Return true if successful, false on error. |
| 13919 | shmread | |
| 16481 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also | |
| 13920 | ||
| 16482 | L<perlipc/"SysV IPC"> and the documentation for | |
| 16483 | L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable> | |
| 16484 | module from CPAN. | |
| 13921 | 16485 | |
| 13922 | 16486 | =end original |
| 13923 | 16487 | |
| 13924 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
| 16488 | System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、 | |
| 13925 | ||
| 16489 | デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを | |
| 13926 | ||
| 16490 | 行ないます。 | |
| 13927 | 読み込み時には、VAR は読み込んだデータを納める | |
| 16491 | 読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。 | |
| 13928 | 変数でなければなりません。 | |
| 13929 | 16492 | 書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が |
| 13930 | 16493 | 短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。 |
| 13931 | 16494 | 成功時には真を、エラー時には偽を返します。 |
| 13932 | shmread | |
| 16495 | L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。 | |
| 13933 | L<perlipc/"SysV IPC"> および | |
| 16496 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN の | |
| 13934 | CP | |
| 16497 | L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。 | |
| 13935 | 16498 | |
| 13936 | 16499 | =begin original |
| 13937 | 16500 | |
| 13938 | 16501 | Portability issues: L<perlport/shmread> and L<perlport/shmwrite>. |
| 13939 | 16502 | |
| 13940 | 16503 | =end original |
| 13941 | 16504 | |
| 13942 | 16505 | 移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。 |
| 13943 | 16506 | |
| 13944 | 16507 | =item shutdown SOCKET,HOW |
| 13945 | 16508 | X<shutdown> |
| 13946 | 16509 | |
| 13947 | 16510 | =for Pod::Functions close down just half of a socket connection |
| 13948 | 16511 | |
| 13949 | 16512 | =begin original |
| 13950 | 16513 | |
| 13951 | 16514 | Shuts down a socket connection in the manner indicated by HOW, which |
| 13952 | 16515 | has the same interpretation as in the syscall of the same name. |
| 13953 | 16516 | |
| 13954 | 16517 | =end original |
| 13955 | 16518 | |
| 13956 | 16519 | 同名のシステムコールと同じように解釈される HOW によって、 |
| 13957 | 16520 | 指定された方法でソケット接続のシャットダウンを行ないます。 |
| 13958 | 16521 | |
| 13959 | shutdown( | |
| 16522 | shutdown($socket, 0); # I/we have stopped reading data | |
| 13960 | shutdown( | |
| 16523 | shutdown($socket, 1); # I/we have stopped writing data | |
| 13961 | shutdown( | |
| 16524 | shutdown($socket, 2); # I/we have stopped using this socket | |
| 13962 | 16525 | |
| 13963 | 16526 | =begin original |
| 13964 | 16527 | |
| 13965 | 16528 | This is useful with sockets when you want to tell the other |
| 13966 | 16529 | side you're done writing but not done reading, or vice versa. |
| 13967 | 16530 | It's also a more insistent form of close because it also |
| 13968 | 16531 | disables the file descriptor in any forked copies in other |
| 13969 | 16532 | processes. |
| 13970 | 16533 | |
| 13971 | 16534 | =end original |
| 13972 | 16535 | |
| 13973 | 16536 | これは、こちらがソケットを書き終わったが読み終わっていない、 |
| 13974 | 16537 | またはその逆を相手側に伝えたいときに便利です。 |
| 13975 | 16538 | これはその他のプロセスでフォークしたファイル記述子のコピーも |
| 13976 | 16539 | 無効にするので、よりしつこい閉じ方です。 |
| 13977 | 16540 | |
| 13978 | 16541 | =begin original |
| 13979 | 16542 | |
| 13980 | Returns C<1> for success; on error, returns C<undef> if | |
| 16543 | Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if | |
| 13981 | 16544 | the first argument is not a valid filehandle, or returns C<0> and sets |
| 13982 | C<$!> for any other failure. | |
| 16545 | L<C<$!>|perlvar/$!> for any other failure. | |
| 13983 | 16546 | |
| 13984 | 16547 | =end original |
| 13985 | 16548 | |
| 13986 | 16549 | 成功時には C<1> を返します; |
| 13987 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は | |
| 16550 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は | |
| 13988 | 返し、その他のエラーの場合は C<0> を返して | |
| 16551 | L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して | |
| 16552 | L<C<$!>|perlvar/$!> をセットします。 | |
| 13989 | 16553 | |
| 13990 | 16554 | =item sin EXPR |
| 13991 | 16555 | X<sin> X<sine> X<asin> X<arcsine> |
| 13992 | 16556 | |
| 13993 | 16557 | =item sin |
| 13994 | 16558 | |
| 13995 | 16559 | =for Pod::Functions return the sine of a number |
| 13996 | 16560 | |
| 13997 | 16561 | =begin original |
| 13998 | 16562 | |
| 13999 | 16563 | Returns the sine of EXPR (expressed in radians). If EXPR is omitted, |
| 14000 | returns sine of C<$_>. | |
| 16564 | returns sine of L<C<$_>|perlvar/$_>. | |
| 14001 | 16565 | |
| 14002 | 16566 | =end original |
| 14003 | 16567 | |
| 14004 | 16568 | (ラジアンで示した) EXPR の正弦を返します。 |
| 14005 | EXPR が省略されたときには、C<$_> の正弦を返します。 | |
| 16569 | EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。 | |
| 14006 | 16570 | |
| 14007 | 16571 | =begin original |
| 14008 | 16572 | |
| 14009 | 16573 | For the inverse sine operation, you may use the C<Math::Trig::asin> |
| 14010 | 16574 | function, or use this relation: |
| 14011 | 16575 | |
| 14012 | 16576 | =end original |
| 14013 | 16577 | |
| 14014 | 16578 | 逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、 |
| 14015 | 16579 | 以下の関係を使ってください: |
| 14016 | 16580 | |
| 14017 | 16581 | sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } |
| 14018 | 16582 | |
| 14019 | 16583 | =item sleep EXPR |
| 14020 | 16584 | X<sleep> X<pause> |
| 14021 | 16585 | |
| 14022 | 16586 | =item sleep |
| 14023 | 16587 | |
| 14024 | 16588 | =for Pod::Functions block for some number of seconds |
| 14025 | 16589 | |
| 14026 | 16590 | =begin original |
| 14027 | 16591 | |
| 14028 | Causes the script to sleep for (integer) EXPR seconds, or forever if no | |
| 16592 | Causes the script to sleep for (integer) EXPR seconds, or forever if no | |
| 14029 | argument is given. Returns the integer number of seconds actually slept. | |
| 16593 | argument is given. Returns the integer number of seconds actually slept. | |
| 14030 | 16594 | |
| 14031 | 16595 | =end original |
| 14032 | 16596 | |
| 14033 | 16597 | スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に) |
| 14034 | 16598 | スリープさせます。 |
| 14035 | 実際にスリープした秒数を返します。 | |
| 16599 | 実際にスリープした秒数を返します。 | |
| 14036 | 16600 | |
| 14037 | 16601 | =begin original |
| 14038 | 16602 | |
| 16603 | EXPR should be a positive integer. If called with a negative integer, | |
| 16604 | L<C<sleep>|/sleep EXPR> does not sleep but instead emits a warning, sets | |
| 16605 | C<$!> (C<errno>), and returns zero. | |
| 16606 | ||
| 16607 | =end original | |
| 16608 | ||
| 16609 | EXPR は正の整数である必要があります。 | |
| 16610 | 負の整数で呼び出すと、 L<C<sleep>|/sleep EXPR> はスリープせず、 | |
| 16611 | 警告を出力して、C<$!> (C<errno>) を設定し、ゼロを返します。 | |
| 16612 | ||
| 16613 | =begin original | |
| 16614 | ||
| 16615 | If called with a non-integer, the fractional part is ignored. | |
| 16616 | ||
| 16617 | =end original | |
| 16618 | ||
| 16619 | If called with a non-integer, the fractional part is ignored. | |
| 16620 | (TBT) | |
| 16621 | ||
| 16622 | =begin original | |
| 16623 | ||
| 16624 | C<sleep 0> is permitted, but a function call to the underlying platform | |
| 16625 | implementation still occurs, with any side effects that may have. | |
| 16626 | C<sleep 0> is therefore not exactly identical to not sleeping at all. | |
| 16627 | ||
| 16628 | =end original | |
| 16629 | ||
| 16630 | C<sleep 0> は許されていますが、基となるプラットフォーム実装への | |
| 16631 | 関数呼び出しはやはり行われ、どのような副作用も起こり得ます。 | |
| 16632 | 従って、C<sleep 0> は全くスリープしないのと正確に同じではありません。 | |
| 16633 | ||
| 16634 | =begin original | |
| 16635 | ||
| 14039 | 16636 | May be interrupted if the process receives a signal such as C<SIGALRM>. |
| 14040 | 16637 | |
| 14041 | 16638 | =end original |
| 14042 | 16639 | |
| 14043 | 16640 | そのプロセスが C<SIGALRM>のようなシグナルを受信すると、 |
| 14044 | 16641 | 割り込みがかかります。 |
| 14045 | 16642 | |
| 14046 | 16643 | eval { |
| 14047 | local $SIG{AL | |
| 16644 | local $SIG{ALRM} = sub { die "Alarm!\n" }; | |
| 14048 | 16645 | sleep; |
| 14049 | 16646 | }; |
| 14050 | 16647 | die $@ unless $@ eq "Alarm!\n"; |
| 14051 | 16648 | |
| 14052 | 16649 | =begin original |
| 14053 | 16650 | |
| 14054 | You probably cannot mix C<alarm> | |
| 16651 | You probably cannot mix L<C<alarm>|/alarm SECONDS> and | |
| 14055 | ||
| 16652 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often | |
| 16653 | implemented using L<C<alarm>|/alarm SECONDS>. | |
| 14056 | 16654 | |
| 14057 | 16655 | =end original |
| 14058 | 16656 | |
| 14059 | C<sleep> は、C<alarm> | |
| 16657 | L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って | |
| 14060 | C< | |
| 16658 | 実装されることが多いので、L<C<alarm>|/alarm SECONDS> と | |
| 16659 | L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。 | |
| 14061 | 16660 | |
| 14062 | 16661 | =begin original |
| 14063 | 16662 | |
| 14064 | 16663 | On some older systems, it may sleep up to a full second less than what |
| 14065 | 16664 | you requested, depending on how it counts seconds. Most modern systems |
| 14066 | 16665 | always sleep the full amount. They may appear to sleep longer than that, |
| 14067 | 16666 | however, because your process might not be scheduled right away in a |
| 14068 | 16667 | busy multitasking system. |
| 14069 | 16668 | |
| 14070 | 16669 | =end original |
| 14071 | 16670 | |
| 14072 | 16671 | 古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に |
| 14073 | 16672 | 満たないうちに、スリープから抜ける場合があります。 |
| 14074 | 16673 | 最近のシステムでは、常に完全にスリープします。 |
| 14075 | 16674 | しかし、負荷の高いマルチタスクシステムでは |
| 14076 | 16675 | 正しくスケジューリングされないがために |
| 14077 | 16676 | より長い時間スリープすることがあります。 |
| 14078 | 16677 | |
| 14079 | 16678 | =begin original |
| 14080 | 16679 | |
| 14081 | For delays of finer granularity than one second, the Time::HiRes | |
| 16680 | For delays of finer granularity than one second, the L<Time::HiRes> | |
| 14082 | (from CPAN, and starting from Perl 5.8 part of the standard | |
| 16681 | module (from CPAN, and starting from Perl 5.8 part of the standard | |
| 14083 | distribution) provides usleep | |
| 16682 | distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>. | |
| 14084 | ||
| 16683 | You may also use Perl's four-argument | |
| 14085 | ||
| 16684 | version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the | |
| 14086 | ||
| 16685 | first three arguments undefined, or you might be able to use the | |
| 16686 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
| 16687 | if your system supports it. See L<perlfaq8> for details. | |
| 14087 | 16688 | |
| 14088 | 16689 | =end original |
| 14089 | 16690 | |
| 14090 | 1 秒より精度の高いスリープを行なうには、 | |
| 16691 | 1 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、 | |
| 14091 | ||
| 16692 | また Perl 5.8 からは標準配布されています) が | |
| 14092 | ||
| 16693 | L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。 | |
| 14093 | Perl の 4 引数版 select | |
| 16694 | Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の | |
| 14094 | setitimer(2) をサポートしているシステムでは、 | |
| 16695 | 3 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、 | |
| 14095 | C<syscall> インタフェースを使って | |
| 16696 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
| 16697 | アクセスすることもできます。 | |
| 14096 | 16698 | 詳しくは L<perlfaq8> を参照してください。 |
| 14097 | 16699 | |
| 14098 | 16700 | =begin original |
| 14099 | 16701 | |
| 14100 | See also the POSIX module's C<pause> function. | |
| 16702 | See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function. | |
| 14101 | 16703 | |
| 14102 | 16704 | =end original |
| 14103 | 16705 | |
| 14104 | POSIX モジュールの C<pause> 関数も参照してください。 | |
| 16706 | L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。 | |
| 14105 | 16707 | |
| 14106 | 16708 | =item socket SOCKET,DOMAIN,TYPE,PROTOCOL |
| 14107 | 16709 | X<socket> |
| 14108 | 16710 | |
| 14109 | 16711 | =for Pod::Functions create a socket |
| 14110 | 16712 | |
| 14111 | 16713 | =begin original |
| 14112 | 16714 | |
| 14113 | 16715 | Opens a socket of the specified kind and attaches it to filehandle |
| 14114 | 16716 | SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for |
| 14115 | 16717 | the syscall of the same name. You should C<use Socket> first |
| 14116 | 16718 | to get the proper definitions imported. See the examples in |
| 14117 | 16719 | L<perlipc/"Sockets: Client/Server Communication">. |
| 14118 | 16720 | |
| 14119 | 16721 | =end original |
| 14120 | 16722 | |
| 14121 | 指定した種類のソケットをオープンし、ファイルハンドル | |
| 16723 | 指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。 | |
| 14122 | SOCKET にアタッチします。 | |
| 14123 | 16724 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
| 14124 | 適切な定義を import するために、まず、C<use Socket> と | |
| 16725 | 適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。 | |
| 14125 | するとよいでしょう。 | |
| 14126 | 16726 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 14127 | 16727 | |
| 14128 | 16728 | =begin original |
| 14129 | 16729 | |
| 14130 | 16730 | On systems that support a close-on-exec flag on files, the flag will |
| 14131 | 16731 | be set for the newly opened file descriptor, as determined by the |
| 14132 | value of $^F. See L<perlvar/$^F>. | |
| 16732 | value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
| 14133 | 16733 | |
| 14134 | 16734 | =end original |
| 14135 | 16735 | |
| 14136 | 16736 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 14137 | フラグは $^F の値で決定される、新しくオープンされた | |
| 16737 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
| 14138 | セットされます。 | |
| 16738 | ファイル記述子に対してセットされます。 | |
| 14139 | 16739 | L<perlvar/$^F> を参照してください。 |
| 14140 | 16740 | |
| 14141 | 16741 | =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL |
| 14142 | 16742 | X<socketpair> |
| 14143 | 16743 | |
| 14144 | 16744 | =for Pod::Functions create a pair of sockets |
| 14145 | 16745 | |
| 14146 | 16746 | =begin original |
| 14147 | 16747 | |
| 14148 | 16748 | Creates an unnamed pair of sockets in the specified domain, of the |
| 14149 | 16749 | specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as |
| 14150 | 16750 | for the syscall of the same name. If unimplemented, raises an exception. |
| 14151 | 16751 | Returns true if successful. |
| 14152 | 16752 | |
| 14153 | 16753 | =end original |
| 14154 | 16754 | |
| 14155 | 16755 | 指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。 |
| 14156 | 16756 | DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。 |
| 14157 | 16757 | 実装されていない場合には、例外が発生します。 |
| 14158 | 16758 | 成功時には真を返します。 |
| 14159 | 16759 | |
| 14160 | 16760 | =begin original |
| 14161 | 16761 | |
| 14162 | 16762 | On systems that support a close-on-exec flag on files, the flag will |
| 14163 | 16763 | be set for the newly opened file descriptors, as determined by the value |
| 14164 | of $^F. See L<perlvar/$^F>. | |
| 16764 | of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>. | |
| 14165 | 16765 | |
| 14166 | 16766 | =end original |
| 14167 | 16767 | |
| 14168 | 16768 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 14169 | フラグは $^F の値で決定される、新しくオープンされた | |
| 16769 | フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた | |
| 14170 | セットされます。 | |
| 16770 | ファイル記述子に対してセットされます。 | |
| 14171 | 16771 | L<perlvar/$^F> を参照してください。 |
| 14172 | 16772 | |
| 14173 | 16773 | =begin original |
| 14174 | 16774 | |
| 14175 | Some systems define | |
| 16775 | Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of | |
| 14176 | ||
| 16776 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in | |
| 16777 | which a call to C<pipe($rdr, $wtr)> is essentially: | |
| 14177 | 16778 | |
| 14178 | 16779 | =end original |
| 14179 | 16780 | |
| 14180 | C<pipe> | |
| 16781 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を | |
| 14181 | C<pi | |
| 16782 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って | |
| 16783 | 定義しているシステムもあります; | |
| 16784 | C<pipe($rdr, $wtr)> は本質的には以下のようになります: | |
| 14182 | 16785 | |
| 14183 | 16786 | use Socket; |
| 14184 | socketpair( | |
| 16787 | socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); | |
| 14185 | shutdown( | |
| 16788 | shutdown($rdr, 1); # no more writing for reader | |
| 14186 | shutdown( | |
| 16789 | shutdown($wtr, 0); # no more reading for writer | |
| 14187 | 16790 | |
| 14188 | 16791 | =begin original |
| 14189 | 16792 | |
| 14190 | 16793 | See L<perlipc> for an example of socketpair use. Perl 5.8 and later will |
| 14191 | 16794 | emulate socketpair using IP sockets to localhost if your system implements |
| 14192 | 16795 | sockets but not socketpair. |
| 14193 | 16796 | |
| 14194 | 16797 | =end original |
| 14195 | 16798 | |
| 14196 | 16799 | socketpair の使用例については L<perlipc> を参照してください。 |
| 14197 | 16800 | Perl 5.8 以降では、システムがソケットを実装しているが socketpair を |
| 14198 | 16801 | 実装していない場合、localhost に対して IP ソケットを使うことで |
| 14199 | 16802 | socketpair をエミュレートします。 |
| 14200 | 16803 | |
| 14201 | 16804 | =begin original |
| 14202 | 16805 | |
| 14203 | 16806 | Portability issues: L<perlport/socketpair>. |
| 14204 | 16807 | |
| 14205 | 16808 | =end original |
| 14206 | 16809 | |
| 14207 | 16810 | 移植性の問題: L<perlport/socketpair>。 |
| 14208 | 16811 | |
| 14209 | 16812 | =item sort SUBNAME LIST |
| 14210 | X<sort> | |
| 16813 | X<sort> | |
| 14211 | 16814 | |
| 14212 | 16815 | =item sort BLOCK LIST |
| 14213 | 16816 | |
| 14214 | 16817 | =item sort LIST |
| 14215 | 16818 | |
| 14216 | 16819 | =for Pod::Functions sort a list of values |
| 14217 | 16820 | |
| 14218 | 16821 | =begin original |
| 14219 | 16822 | |
| 14220 | 16823 | In list context, this sorts the LIST and returns the sorted list value. |
| 14221 | In scalar context, the behaviour of C<sort | |
| 16824 | In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is | |
| 16825 | undefined. | |
| 14222 | 16826 | |
| 14223 | 16827 | =end original |
| 14224 | 16828 | |
| 14225 | 16829 | リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。 |
| 14226 | スカラコンテキストでは、C<sort | |
| 16830 | スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。 | |
| 14227 | 16831 | |
| 14228 | 16832 | =begin original |
| 14229 | 16833 | |
| 14230 | If SUBNAME or BLOCK is omitted, C<sort>s | |
| 16834 | If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in | |
| 16835 | standard string comparison | |
| 14231 | 16836 | order. If SUBNAME is specified, it gives the name of a subroutine |
| 14232 | that returns a | |
| 16837 | that returns a numeric value less than, equal to, or greater than C<0>, | |
| 14233 | depending on how the elements of the list are to be ordered. (The | |
| 16838 | depending on how the elements of the list are to be ordered. (The | |
| 14234 | 16839 | C<< <=> >> and C<cmp> operators are extremely useful in such routines.) |
| 14235 | 16840 | SUBNAME may be a scalar variable name (unsubscripted), in which case |
| 14236 | 16841 | the value provides the name of (or a reference to) the actual |
| 14237 | 16842 | subroutine to use. In place of a SUBNAME, you can provide a BLOCK as |
| 14238 | 16843 | an anonymous, in-line sort subroutine. |
| 14239 | 16844 | |
| 14240 | 16845 | =end original |
| 14241 | 16846 | |
| 14242 | SUBNAME や BLOCK を省略すると、標準の | |
| 16847 | SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の | |
| 14243 | 行なわれます。 | |
| 16848 | 文字列比較の順番で行なわれます。 | |
| 14244 | 16849 | SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに |
| 14245 | 応じて、負、 | |
| 16850 | 応じて、負の数、C<0>、正の数を返すサブルーチンの名前であると解釈されます。 | |
| 14246 | (このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、 | |
| 16851 | (このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、 | |
| 14247 | 16852 | たいへん便利です。) |
| 14248 | SUBNAME は、スカラ変数名(添字なし)でもよく、 | |
| 16853 | SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する | |
| 14249 | ||
| 16854 | 実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。 | |
| 14250 | 名 | |
| 16855 | SUBNAME の代わりに、無名のインラインソートルーチンとして、BLOCK を | |
| 14251 | ||
| 16856 | 書くことができます。 | |
| 14252 | ソートルーチンとして、BLOCK を書くことができます。 | |
| 14253 | 16857 | |
| 14254 | 16858 | =begin original |
| 14255 | 16859 | |
| 14256 | 16860 | If the subroutine's prototype is C<($$)>, the elements to be compared are |
| 14257 | passed by reference in C<@_>, as for a normal subroutine. | |
| 16861 | passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine. | |
| 14258 | than unprototyped subroutines, where the elements to be | |
| 16862 | This is slower than unprototyped subroutines, where the elements to be | |
| 14259 | into the subroutine as the package global variables | |
| 16863 | compared are passed into the subroutine as the package global variables | |
| 14260 | ||
| 16864 | C<$a> and C<$b> (see example below). | |
| 14261 | to declare $a and $b as lexicals. | |
| 14262 | 16865 | |
| 14263 | 16866 | =end original |
| 14264 | 16867 | |
| 14265 | サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常の | |
| 16868 | サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと | |
| 14266 | ||
| 16869 | 同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。 | |
| 14267 | 16870 | これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため |
| 14268 | サブルーチンに渡される二つの要素は、パッケージのグローバル変数 $a と | |
| 16871 | サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と | |
| 14269 | 渡されます(次の例を参照してください)。 | |
| 16872 | C<$b> で渡されます(次の例を参照してください)。 | |
| 14270 | 後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。 | |
| 14271 | 16873 | |
| 14272 | 16874 | =begin original |
| 14273 | 16875 | |
| 14274 | If the subroutine is an XSUB, the elements to be compared are pushed on | |
| 16876 | If the subroutine is an XSUB, the elements to be compared are pushed on | |
| 14275 | the stack, the way arguments are usually passed to XSUBs. $a and | |
| 16877 | to the stack, the way arguments are usually passed to XSUBs. C<$a> and | |
| 14276 | not set. | |
| 16878 | C<$b> are not set. | |
| 14277 | 16879 | |
| 14278 | 16880 | =end original |
| 14279 | 16881 | |
| 14280 | 16882 | サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、 |
| 14281 | 16883 | スタックにプッシュされます。 |
| 14282 | $a と $b は設定されません。 | |
| 16884 | C<$a> と C<$b> は設定されません。 | |
| 14283 | 16885 | |
| 14284 | 16886 | =begin original |
| 14285 | 16887 | |
| 14286 | 16888 | The values to be compared are always passed by reference and should not |
| 14287 | 16889 | be modified. |
| 14288 | 16890 | |
| 14289 | 16891 | =end original |
| 14290 | 16892 | |
| 14291 | ||
| 16893 | 比較される値はリファレンスによって渡されるので、変更するべきではありません。 | |
| 14292 | 16894 | |
| 14293 | 16895 | =begin original |
| 14294 | 16896 | |
| 14295 | 16897 | You also cannot exit out of the sort block or subroutine using any of the |
| 14296 | loop control operators described in L<perlsyn> or with | |
| 16898 | loop control operators described in L<perlsyn> or with | |
| 16899 | L<C<goto>|/goto LABEL>. | |
| 14297 | 16900 | |
| 14298 | 16901 | =end original |
| 14299 | 16902 | |
| 14300 | 16903 | また、ソートブロックやサブルーチンから L<perlsyn> で説明されている |
| 14301 | ループ制御子や C<goto> を使って抜けてはいけません。 | |
| 16904 | ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。 | |
| 14302 | 16905 | |
| 14303 | 16906 | =begin original |
| 14304 | 16907 | |
| 14305 | When C<use locale> (but not C<use locale 'not_characters'>) | |
| 16908 | When L<C<use locale>|locale> (but not C<use locale ':not_characters'>) | |
| 14306 | effect, C<sort LIST> sorts LIST according to the | |
| 16909 | is in effect, C<sort LIST> sorts LIST according to the | |
| 14307 | 16910 | current collation locale. See L<perllocale>. |
| 14308 | 16911 | |
| 14309 | 16912 | =end original |
| 14310 | 16913 | |
| 14311 | C<use locale> が有効(そして C<use locale 'not_characters'> が | |
| 16914 | L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が | |
| 14312 | 場合、C<sort LIST> は LIST を現在の比較ロケールに従って | |
| 16915 | 有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って | |
| 16916 | ソートします。 | |
| 14313 | 16917 | L<perllocale> を参照してください。 |
| 14314 | 16918 | |
| 14315 | 16919 | =begin original |
| 14316 | 16920 | |
| 14317 | sort | |
| 16921 | L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list, | |
| 14318 | variable aliases the list elements. That is, | |
| 16922 | much as a for loop's index variable aliases the list elements. That is, | |
| 14319 | list returned by sort | |
| 16923 | modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST> | |
| 16924 | (for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or | |
| 16925 | L<C<grep>|/grep BLOCK LIST>) | |
| 14320 | 16926 | actually modifies the element in the original list. This is usually |
| 14321 | 16927 | something to be avoided when writing clear code. |
| 14322 | 16928 | |
| 14323 | 16929 | =end original |
| 14324 | 16930 | |
| 14325 | sort | |
| 16931 | L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します; | |
| 14326 | リスト要素へのエイリアスと同様です。 | |
| 16932 | for ループのインデックス変数がリスト要素へのエイリアスと同様です。 | |
| 14327 | つまり、sort | |
| 16933 | つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、 | |
| 14328 | C< | |
| 16934 | C<foreach> や L<C<map>|/map BLOCK LIST> や | |
| 16935 | L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が | |
| 16936 | 変更されます。 | |
| 14329 | 16937 | これはきれいなコードを書くときには普通は回避されます。 |
| 14330 | 16938 | |
| 14331 | 16939 | =begin original |
| 14332 | 16940 | |
| 14333 | Perl | |
| 16941 | Historically Perl has varied in whether sorting is stable by default. | |
| 14334 | ||
| 16942 | If stability matters, it can be controlled explicitly by using the | |
| 14335 | ||
| 16943 | L<sort> pragma. | |
| 14336 | quicksort's run time is O(NlogN) when averaged over all arrays of | |
| 14337 | length N, the time can be O(N**2), I<quadratic> behavior, for some | |
| 14338 | inputs.) In 5.7, the quicksort implementation was replaced with | |
| 14339 | a stable mergesort algorithm whose worst-case behavior is O(NlogN). | |
| 14340 | But benchmarks indicated that for some inputs, on some platforms, | |
| 14341 | the original quicksort was faster. 5.8 has a sort pragma for | |
| 14342 | limited control of the sort. Its rather blunt control of the | |
| 14343 | underlying algorithm may not persist into future Perls, but the | |
| 14344 | ability to characterize the input or output in implementation | |
| 14345 | independent ways quite probably will. See L<the sort pragma|sort>. | |
| 14346 | 16944 | |
| 14347 | 16945 | =end original |
| 14348 | 16946 | |
| 14349 | ||
| 16947 | 歴史的には、ソートがデフォルトで安定かどうかは様々です。 | |
| 14350 | ||
| 16948 | 安定性が問題になる場合は、L<sort> プラグマを使うことで明示的に制御できます。 | |
| 14351 | I<可能性があります>。 | |
| 14352 | (I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。 | |
| 14353 | クイックソートの実行時間は、長さ N の全ての配列の平均では | |
| 14354 | O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを | |
| 14355 | することがあります。) | |
| 14356 | 5.7 では、クイックソートによる実装は、最悪の場合の振る舞いも | |
| 14357 | O(NlogN) である、安定したマージソートアルゴリズムに置き換えられました。 | |
| 14358 | しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの | |
| 14359 | 方が速くなります。 | |
| 14360 | 5.8 ではソートを限定的に制御できる sort プラグマがあります。 | |
| 14361 | この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも | |
| 14362 | しれませんが、実装に依存しない形で入力や出力を性格付ける機能は | |
| 14363 | おそらくあります。 | |
| 14364 | L<the sort pragma|sort> を参照してください。 | |
| 14365 | 16949 | |
| 14366 | 16950 | =begin original |
| 14367 | 16951 | |
| 14368 | 16952 | Examples: |
| 14369 | 16953 | |
| 14370 | 16954 | =end original |
| 14371 | 16955 | |
| 14372 | 16956 | 例: |
| 14373 | 16957 | |
| 14374 | 16958 | # sort lexically |
| 14375 | @articles = sort @files; | |
| 16959 | my @articles = sort @files; | |
| 14376 | 16960 | |
| 14377 | 16961 | # same thing, but with explicit sort routine |
| 14378 | @articles = sort {$a cmp $b} @files; | |
| 16962 | my @articles = sort {$a cmp $b} @files; | |
| 14379 | 16963 | |
| 14380 | 16964 | # now case-insensitively |
| 14381 | @articles = sort {fc($a) cmp fc($b)} @files; | |
| 16965 | my @articles = sort {fc($a) cmp fc($b)} @files; | |
| 14382 | 16966 | |
| 14383 | 16967 | # same thing in reversed order |
| 14384 | @articles = sort {$b cmp $a} @files; | |
| 16968 | my @articles = sort {$b cmp $a} @files; | |
| 14385 | 16969 | |
| 14386 | 16970 | # sort numerically ascending |
| 14387 | @articles = sort {$a <=> $b} @files; | |
| 16971 | my @articles = sort {$a <=> $b} @files; | |
| 14388 | 16972 | |
| 14389 | 16973 | # sort numerically descending |
| 14390 | @articles = sort {$b <=> $a} @files; | |
| 16974 | my @articles = sort {$b <=> $a} @files; | |
| 14391 | 16975 | |
| 14392 | 16976 | # this sorts the %age hash by value instead of key |
| 14393 | 16977 | # using an in-line function |
| 14394 | @eldest = sort { $age{$b} <=> $age{$a} } keys %age; | |
| 16978 | my @eldest = sort { $age{$b} <=> $age{$a} } keys %age; | |
| 14395 | 16979 | |
| 14396 | 16980 | # sort using explicit subroutine name |
| 14397 | 16981 | sub byage { |
| 14398 | 16982 | $age{$a} <=> $age{$b}; # presuming numeric |
| 14399 | 16983 | } |
| 14400 | @sortedclass = sort byage @class; | |
| 16984 | my @sortedclass = sort byage @class; | |
| 14401 | 16985 | |
| 14402 | 16986 | sub backwards { $b cmp $a } |
| 14403 | @harry = qw(dog cat x Cain Abel); | |
| 16987 | my @harry = qw(dog cat x Cain Abel); | |
| 14404 | @george = qw(gone chased yz Punished Axed); | |
| 16988 | my @george = qw(gone chased yz Punished Axed); | |
| 14405 | 16989 | print sort @harry; |
| 14406 | 16990 | # prints AbelCaincatdogx |
| 14407 | 16991 | print sort backwards @harry; |
| 14408 | 16992 | # prints xdogcatCainAbel |
| 14409 | 16993 | print sort @george, 'to', @harry; |
| 14410 | 16994 | # prints AbelAxedCainPunishedcatchaseddoggonetoxyz |
| 14411 | 16995 | |
| 14412 | 16996 | # inefficiently sort by descending numeric compare using |
| 14413 | 16997 | # the first integer after the first = sign, or the |
| 14414 | 16998 | # whole record case-insensitively otherwise |
| 14415 | 16999 | |
| 14416 | 17000 | my @new = sort { |
| 14417 | 17001 | ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] |
| 14418 | 17002 | || |
| 14419 | 17003 | fc($a) cmp fc($b) |
| 14420 | 17004 | } @old; |
| 14421 | 17005 | |
| 14422 | 17006 | # same thing, but much more efficiently; |
| 14423 | 17007 | # we'll build auxiliary indices instead |
| 14424 | 17008 | # for speed |
| 14425 | my @nums | |
| 17009 | my (@nums, @caps); | |
| 14426 | 17010 | for (@old) { |
| 14427 | 17011 | push @nums, ( /=(\d+)/ ? $1 : undef ); |
| 14428 | 17012 | push @caps, fc($_); |
| 14429 | 17013 | } |
| 14430 | 17014 | |
| 14431 | 17015 | my @new = @old[ sort { |
| 14432 | 17016 | $nums[$b] <=> $nums[$a] |
| 14433 | 17017 | || |
| 14434 | 17018 | $caps[$a] cmp $caps[$b] |
| 14435 | 17019 | } 0..$#old |
| 14436 | 17020 | ]; |
| 14437 | 17021 | |
| 14438 | 17022 | # same thing, but without any temps |
| 14439 | @new = map { $_->[0] } | |
| 17023 | my @new = map { $_->[0] } | |
| 14440 | 17024 | sort { $b->[1] <=> $a->[1] |
| 14441 | 17025 | || |
| 14442 | 17026 | $a->[2] cmp $b->[2] |
| 14443 | 17027 | } map { [$_, /=(\d+)/, fc($_)] } @old; |
| 14444 | 17028 | |
| 14445 | 17029 | # using a prototype allows you to use any comparison subroutine |
| 14446 | 17030 | # as a sort subroutine (including other package's subroutines) |
| 14447 | package | |
| 17031 | package Other; | |
| 14448 | 17032 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are |
| 14449 | # not set here | |
| 17033 | # not set here | |
| 14450 | 17034 | package main; |
| 14451 | @new = sort | |
| 17035 | my @new = sort Other::backwards @old; | |
| 14452 | 17036 | |
| 14453 | # | |
| 17037 | <#ins># using a prototype with function signature | |
| 14454 | use | |
| 17038 | use feature 'signatures'; | |
| 14455 | | |
| 17039 | sub function_with_signature :prototype($$) ($one, $two) { | |
| 17040 | return $one <=> $two | |
| 17041 | } | |
| 14456 | 17042 | |
| 14457 | | |
| 17043 | my @new = sort function_with_signature @old; | |
| 14458 | use sort '_mergesort'; # note discouraging _ | |
| 14459 | @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
| 14460 | 17044 | |
| 17045 | # guarantee stability | |
| 17046 | use sort 'stable'; | |
| 17047 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
| 17048 | ||
| 14461 | 17049 | =begin original |
| 14462 | 17050 | |
| 14463 | 17051 | Warning: syntactical care is required when sorting the list returned from |
| 14464 | 17052 | a function. If you want to sort the list returned by the function call |
| 14465 | 17053 | C<find_records(@key)>, you can use: |
| 14466 | 17054 | |
| 14467 | 17055 | =end original |
| 14468 | 17056 | |
| 14469 | 警告: 関数から | |
| 17057 | 警告: 関数から返されたリストをソートするときには文法上の注意が必要です。 | |
| 14470 | 17058 | 関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、 |
| 14471 | 17059 | 以下のように出来ます: |
| 14472 | 17060 | |
| 14473 | @contact = sort { $a cmp $b } find_records @key; | |
| 17061 | my @contact = sort { $a cmp $b } find_records @key; | |
| 14474 | @contact = sort +find_records(@key); | |
| 17062 | my @contact = sort +find_records(@key); | |
| 14475 | @contact = sort &find_records(@key); | |
| 17063 | my @contact = sort &find_records(@key); | |
| 14476 | @contact = sort(find_records(@key)); | |
| 17064 | my @contact = sort(find_records(@key)); | |
| 14477 | 17065 | |
| 14478 | 17066 | =begin original |
| 14479 | 17067 | |
| 14480 | If instead you want to sort the array @key with the comparison routine | |
| 17068 | If instead you want to sort the array C<@key> with the comparison routine | |
| 14481 | 17069 | C<find_records()> then you can use: |
| 14482 | 17070 | |
| 14483 | 17071 | =end original |
| 14484 | 17072 | |
| 14485 | 一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、 | |
| 17073 | 一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、 | |
| 14486 | 17074 | 以下のように出来ます: |
| 14487 | 17075 | |
| 14488 | @contact = sort { find_records() } @key; | |
| 17076 | my @contact = sort { find_records() } @key; | |
| 14489 | @contact = sort find_records(@key); | |
| 17077 | my @contact = sort find_records(@key); | |
| 14490 | @contact = sort(find_records @key); | |
| 17078 | my @contact = sort(find_records @key); | |
| 14491 | @contact = sort(find_records (@key)); | |
| 17079 | my @contact = sort(find_records (@key)); | |
| 14492 | 17080 | |
| 14493 | 17081 | =begin original |
| 14494 | 17082 | |
| 14495 | ||
| 17083 | C<$a> and C<$b> are set as package globals in the package the sort() is | |
| 14496 | ||
| 17084 | called from. That means C<$main::a> and C<$main::b> (or C<$::a> and | |
| 14497 | ||
| 17085 | C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the | |
| 17086 | C<FooPack> package, etc. If the sort block is in scope of a C<my> or | |
| 17087 | C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full | |
| 17088 | name of the variables in the sort block : | |
| 14498 | 17089 | |
| 14499 | 17090 | =end original |
| 14500 | 17091 | |
| 14501 | ||
| 17092 | C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして | |
| 14502 | ||
| 17093 | 設定されます。 | |
| 14503 | ||
| 17094 | つまり、C<main> パッケージの C<$main::a> と C<$main::b> | |
| 14504 | ||
| 17095 | (あるいは C<$::a> と C<$::b>) 、 | |
| 17096 | C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。 | |
| 17097 | ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、 | |
| 17098 | ソートブロックの変数の完全名を I<指定しなければなりません>: | |
| 14505 | 17099 | |
| 14506 | | |
| 17100 | package main; | |
| 17101 | my $a = "C"; # DANGER, Will Robinson, DANGER !!! | |
| 14507 | 17102 | |
| 17103 | print sort { $a cmp $b } qw(A C E G B D F H); | |
| 17104 | # WRONG | |
| 17105 | sub badlexi { $a cmp $b } | |
| 17106 | print sort badlexi qw(A C E G B D F H); | |
| 17107 | # WRONG | |
| 17108 | # the above prints BACFEDGH or some other incorrect ordering | |
| 17109 | ||
| 17110 | print sort { $::a cmp $::b } qw(A C E G B D F H); | |
| 17111 | # OK | |
| 17112 | print sort { our $a cmp our $b } qw(A C E G B D F H); | |
| 17113 | # also OK | |
| 17114 | print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H); | |
| 17115 | # also OK | |
| 17116 | sub lexi { our $a cmp our $b } | |
| 17117 | print sort lexi qw(A C E G B D F H); | |
| 17118 | # also OK | |
| 17119 | # the above print ABCDEFGH | |
| 17120 | ||
| 14508 | 17121 | =begin original |
| 14509 | 17122 | |
| 14510 | the | |
| 17123 | With proper care you may mix package and my (or state) C<$a> and/or C<$b>: | |
| 14511 | but if you're in the C<FooPack> package, it's the same as typing | |
| 14512 | 17124 | |
| 14513 | 17125 | =end original |
| 14514 | 17126 | |
| 14515 | ||
| 17127 | 適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を | |
| 14516 | ||
| 17128 | 混ぜることができます: | |
| 14517 | 17129 | |
| 14518 | | |
| 17130 | my $a = { | |
| 17131 | tiny => -2, | |
| 17132 | small => -1, | |
| 17133 | normal => 0, | |
| 17134 | big => 1, | |
| 17135 | huge => 2 | |
| 17136 | }; | |
| 14519 | 17137 | |
| 17138 | say sort { $a->{our $a} <=> $a->{our $b} } | |
| 17139 | qw{ huge normal tiny small big}; | |
| 17140 | ||
| 17141 | # prints tinysmallnormalbighuge | |
| 17142 | ||
| 14520 | 17143 | =begin original |
| 14521 | 17144 | |
| 17145 | C<$a> and C<$b> are implicitly local to the sort() execution and regain their | |
| 17146 | former values upon completing the sort. | |
| 17147 | ||
| 17148 | =end original | |
| 17149 | ||
| 17150 | C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に | |
| 17151 | 元の値に戻ります。 | |
| 17152 | ||
| 17153 | =begin original | |
| 17154 | ||
| 17155 | Sort subroutines written using C<$a> and C<$b> are bound to their calling | |
| 17156 | package. It is possible, but of limited interest, to define them in a | |
| 17157 | different package, since the subroutine must still refer to the calling | |
| 17158 | package's C<$a> and C<$b> : | |
| 17159 | ||
| 17160 | =end original | |
| 17161 | ||
| 17162 | C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに | |
| 17163 | しなければなりません。 | |
| 17164 | 異なるパッケージに定義することは可能ですが、 | |
| 17165 | これは可能ですが、限られた関心しかありません; | |
| 17166 | サブルーチンは呼び出しパッケージの C<$a> と C<$b> を | |
| 17167 | 参照しなければならないからです: | |
| 17168 | ||
| 17169 | package Foo; | |
| 17170 | sub lexi { $Bar::a cmp $Bar::b } | |
| 17171 | package Bar; | |
| 17172 | ... sort Foo::lexi ... | |
| 17173 | ||
| 17174 | =begin original | |
| 17175 | ||
| 17176 | Use the prototyped versions (see above) for a more generic alternative. | |
| 17177 | ||
| 17178 | =end original | |
| 17179 | ||
| 17180 | より一般的な代替案としては(前述の)プロトタイプ版を使ってください。 | |
| 17181 | ||
| 17182 | =begin original | |
| 17183 | ||
| 14522 | 17184 | The comparison function is required to behave. If it returns |
| 14523 | 17185 | inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and |
| 14524 | 17186 | sometimes saying the opposite, for example) the results are not |
| 14525 | 17187 | well-defined. |
| 14526 | 17188 | |
| 14527 | 17189 | =end original |
| 14528 | 17190 | |
| 14529 | 17191 | 比較関数は一貫した振る舞いをすることが求められます。 |
| 14530 | 17192 | 一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より |
| 14531 | 17193 | 小さいと返し、またあるときは逆を返す)場合、結果は未定義です。 |
| 14532 | 17194 | |
| 14533 | 17195 | =begin original |
| 14534 | 17196 | |
| 14535 | Because C<< <=> >> returns C<undef> when either operand | |
| 17197 | Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand | |
| 14536 | (not-a-number), be careful when sorting with a | |
| 17198 | is C<NaN> (not-a-number), be careful when sorting with a | |
| 14537 | 17199 | comparison function like C<< $a <=> $b >> any lists that might contain a |
| 14538 | 17200 | C<NaN>. The following example takes advantage that C<NaN != NaN> to |
| 14539 | 17201 | eliminate any C<NaN>s from the input list. |
| 14540 | 17202 | |
| 14541 | 17203 | =end original |
| 14542 | 17204 | |
| 14543 | 17205 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに |
| 14544 | C<undef> を返すので、 | |
| 17206 | L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で | |
| 14545 | ||
| 17207 | ソートする場合はリストに C<NaN> が含まれないように注意してください。 | |
| 14546 | 含まれないように注意してください。 | |
| 14547 | 17208 | 以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を |
| 14548 | 17209 | 利用しています。 |
| 14549 | 17210 | |
| 14550 | @result = sort { $a <=> $b } grep { $_ == $_ } @input; | |
| 17211 | my @result = sort { $a <=> $b } grep { $_ == $_ } @input; | |
| 14551 | 17212 | |
| 14552 | = | |
| 17213 | =begin original | |
| 17214 | ||
| 17215 | In this version of F<perl>, the C<sort> function is implemented via the | |
| 17216 | mergesort algorithm. | |
| 17217 | ||
| 17218 | =end original | |
| 17219 | ||
| 17220 | このバージョンの F<perl> では、C<sort> 関数はマージソートアルゴリズムで | |
| 17221 | 実装されています。 | |
| 17222 | ||
| 17223 | =item splice ARRAY,OFFSET,LENGTH,LIST | |
| 14553 | 17224 | X<splice> |
| 14554 | 17225 | |
| 14555 | =item splice ARRAY | |
| 17226 | =item splice ARRAY,OFFSET,LENGTH | |
| 14556 | 17227 | |
| 14557 | =item splice ARRAY | |
| 17228 | =item splice ARRAY,OFFSET | |
| 14558 | 17229 | |
| 14559 | =item splice ARRAY | |
| 17230 | =item splice ARRAY | |
| 14560 | 17231 | |
| 14561 | 17232 | =for Pod::Functions add or remove elements anywhere in an array |
| 14562 | 17233 | |
| 14563 | 17234 | =begin original |
| 14564 | 17235 | |
| 14565 | 17236 | Removes the elements designated by OFFSET and LENGTH from an array, and |
| 14566 | 17237 | replaces them with the elements of LIST, if any. In list context, |
| 14567 | 17238 | returns the elements removed from the array. In scalar context, |
| 14568 | returns the last element removed, or C<undef> if no | |
| 17239 | returns the last element removed, or L<C<undef>|/undef EXPR> if no | |
| 17240 | elements are | |
| 14569 | 17241 | removed. The array grows or shrinks as necessary. |
| 14570 | 17242 | If OFFSET is negative then it starts that far from the end of the array. |
| 14571 | 17243 | If LENGTH is omitted, removes everything from OFFSET onward. |
| 14572 | 17244 | If LENGTH is negative, removes the elements from OFFSET onward |
| 14573 | 17245 | except for -LENGTH elements at the end of the array. |
| 14574 | 17246 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is |
| 14575 | past the end of the array, Perl issues a warning, | |
| 17247 | past the end of the array and a LENGTH was provided, Perl issues a warning, | |
| 14576 | end of the array. | |
| 17248 | and splices at the end of the array. | |
| 14577 | 17249 | |
| 14578 | 17250 | =end original |
| 14579 | 17251 | |
| 14580 | 17252 | ARRAY から OFFSET、LENGTH で指定される要素を取り除き、 |
| 14581 | 17253 | LIST があれば、それを代わりに挿入します。 |
| 14582 | 17254 | リストコンテキストでは、配列から取り除かれた要素を返します。 |
| 14583 | 17255 | スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が |
| 14584 | 取り除かれなかった場合は C<undef> を返します。 | |
| 17256 | 取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。 | |
| 14585 | 17257 | 配列は、必要に応じて、大きくなったり、小さくなったりします。 |
| 14586 | 17258 | OFFSET が負の数の場合は、配列の最後からの距離を示します。 |
| 14587 | 17259 | LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。 |
| 14588 | 17260 | LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を |
| 14589 | 17261 | 除いて取り除きます。 |
| 14590 | 17262 | OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。 |
| 14591 | OFFSET が配列の最後より後ろ | |
| 17263 | OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、 | |
| 14592 | 処理します。 | |
| 17264 | 配列の最後に対して処理します。 | |
| 14593 | 17265 | |
| 14594 | 17266 | =begin original |
| 14595 | 17267 | |
| 14596 | 17268 | The following equivalences hold (assuming C<< $#a >= $i >> ) |
| 14597 | 17269 | |
| 14598 | 17270 | =end original |
| 14599 | 17271 | |
| 14600 | 17272 | 以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。 |
| 14601 | 17273 | |
| 14602 | 17274 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) |
| 14603 | 17275 | pop(@a) splice(@a,-1) |
| 14604 | 17276 | shift(@a) splice(@a,0,1) |
| 14605 | 17277 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) |
| 14606 | 17278 | $a[$i] = $y splice(@a,$i,1,$y) |
| 14607 | 17279 | |
| 14608 | 17280 | =begin original |
| 14609 | 17281 | |
| 14610 | ||
| 17282 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example, | |
| 17283 | to implement n-ary queue processing: | |
| 14611 | 17284 | |
| 14612 | 17285 | =end original |
| 14613 | 17286 | |
| 14614 | ||
| 17287 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えば、n-ary キュー処理の | |
| 17288 | 実装に使えます: | |
| 14615 | 17289 | |
| 14616 | sub a | |
| 17290 | sub nary_print { | |
| 14617 | | |
| 17291 | my $n = shift; | |
| 14618 | | |
| 17292 | while (my @next_n = splice @_, 0, $n) { | |
| 14619 | | |
| 17293 | say join q{ -- }, @next_n; | |
| 14620 | | |
| 17294 | } | |
| 14621 | return 0 if pop(@a) ne pop(@b); | |
| 14622 | } | |
| 14623 | return 1; | |
| 14624 | 17295 | } |
| 14625 | if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... } | |
| 14626 | 17296 | |
| 14627 | ||
| 17297 | nary_print(3, qw(a b c d e f g h)); | |
| 17298 | # prints: | |
| 17299 | # a -- b -- c | |
| 17300 | # d -- e -- f | |
| 17301 | # g -- h | |
| 14628 | 17302 | |
| 14629 | Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a | |
| 14630 | reference to an unblessed array. The argument will be dereferenced | |
| 14631 | automatically. This aspect of C<splice> is considered highly experimental. | |
| 14632 | The exact behaviour may change in a future version of Perl. | |
| 14633 | ||
| 14634 | =end original | |
| 14635 | ||
| 14636 | Perl 5.14 から、C<splice> はスカラの EXPR を取ることができるようになりました; | |
| 14637 | これは bless されていない配列へのリファレンスでなければなりません。 | |
| 14638 | 引数は自動的にデリファレンスされます。 | |
| 14639 | C<splice> のこの動作は高度に実験的であると考えられています。 | |
| 14640 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 14641 | ||
| 14642 | 17303 | =begin original |
| 14643 | 17304 | |
| 14644 | ||
| 17305 | Starting with Perl 5.14, an experimental feature allowed | |
| 14645 | ||
| 17306 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a | |
| 14646 | ||
| 17307 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 14647 | ||
| 17308 | removed as of Perl 5.24. | |
| 14648 | 17309 | |
| 14649 | 17310 | =end original |
| 14650 | 17311 | |
| 14651 | ||
| 17312 | Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を | |
| 14652 | ||
| 17313 | 取ることが出来るという実験的機能がありました。 | |
| 14653 | ||
| 17314 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 14654 | 書いてください: | |
| 14655 | 17315 | |
| 14656 | use 5.014; # so push/pop/etc work on scalars (experimental) | |
| 14657 | ||
| 14658 | 17316 | =item split /PATTERN/,EXPR,LIMIT |
| 14659 | 17317 | X<split> |
| 14660 | 17318 | |
| 14661 | 17319 | =item split /PATTERN/,EXPR |
| 14662 | 17320 | |
| 14663 | 17321 | =item split /PATTERN/ |
| 14664 | 17322 | |
| 14665 | 17323 | =item split |
| 14666 | 17324 | |
| 14667 | 17325 | =for Pod::Functions split up a string using a regexp delimiter |
| 14668 | 17326 | |
| 14669 | 17327 | =begin original |
| 14670 | 17328 | |
| 14671 | 17329 | Splits the string EXPR into a list of strings and returns the |
| 14672 | 17330 | list in list context, or the size of the list in scalar context. |
| 17331 | (Prior to Perl 5.11, it also overwrote C<@_> with the list in | |
| 17332 | void and scalar context. If you target old perls, beware.) | |
| 14673 | 17333 | |
| 14674 | 17334 | =end original |
| 14675 | 17335 | |
| 14676 | 17336 | 文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを |
| 14677 | 17337 | 返し、スカラコンテキストではリストの大きさを返します。 |
| 17338 | (Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は | |
| 17339 | C<@_> をリストで上書きします。 | |
| 17340 | もし古い perl を対象にするなら、注意してください。) | |
| 14678 | 17341 | |
| 14679 | 17342 | =begin original |
| 14680 | 17343 | |
| 14681 | If only PATTERN is given, EXPR defaults to C<$_>. | |
| 17344 | If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>. | |
| 14682 | 17345 | |
| 14683 | 17346 | =end original |
| 14684 | 17347 | |
| 14685 | PATTERN のみが与えられた場合、EXPR のデフォルトは C<$_> です。 | |
| 17348 | PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。 | |
| 14686 | 17349 | |
| 14687 | 17350 | =begin original |
| 14688 | 17351 | |
| 14689 | 17352 | Anything in EXPR that matches PATTERN is taken to be a separator |
| 14690 | 17353 | that separates the EXPR into substrings (called "I<fields>") that |
| 14691 | 17354 | do B<not> include the separator. Note that a separator may be |
| 14692 | 17355 | longer than one character or even have no characters at all (the |
| 14693 | 17356 | empty string, which is a zero-width match). |
| 14694 | 17357 | |
| 14695 | 17358 | =end original |
| 14696 | 17359 | |
| 14697 | 17360 | EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と |
| 14698 | 17361 | 呼ばれる)セパレータを B<含まない> 部分文字列に分割するための |
| 14699 | 17362 | セパレータとなります。 |
| 14700 | 17363 | セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は |
| 14701 | 17364 | ゼロ幅マッチングです)ということに注意してください。 |
| 14702 | 17365 | |
| 14703 | 17366 | =begin original |
| 14704 | 17367 | |
| 14705 | 17368 | The PATTERN need not be constant; an expression may be used |
| 14706 | 17369 | to specify a pattern that varies at runtime. |
| 14707 | 17370 | |
| 14708 | 17371 | =end original |
| 14709 | 17372 | |
| 14710 | 17373 | PATTERN は定数である必要はありません; 実行時に変更されるパターンを |
| 14711 | 17374 | 指定するために式を使えます。 |
| 14712 | 17375 | |
| 14713 | 17376 | =begin original |
| 14714 | 17377 | |
| 14715 | 17378 | If PATTERN matches the empty string, the EXPR is split at the match |
| 14716 | 17379 | position (between characters). As an example, the following: |
| 14717 | 17380 | |
| 14718 | 17381 | =end original |
| 14719 | 17382 | |
| 14720 | 17383 | PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置 |
| 14721 | 17384 | (文字の間)で分割されます。 |
| 14722 | 17385 | 例えば、以下のものは: |
| 14723 | 17386 | |
| 14724 | | |
| 17387 | my @x = split(/b/, "abc"); # ("a", "c") | |
| 14725 | 17388 | |
| 14726 | 17389 | =begin original |
| 14727 | 17390 | |
| 14728 | uses the | |
| 17391 | uses the C<b> in C<'abc'> as a separator to produce the list ("a", "c"). | |
| 14729 | 17392 | However, this: |
| 14730 | 17393 | |
| 14731 | 17394 | =end original |
| 14732 | 17395 | |
| 14733 | 'abc' の | |
| 17396 | C<'abc'> の C<b> をセパレータとして使ってリスト ("a", "c") を生成します。 | |
| 14734 | 17397 | しかし、これは: |
| 14735 | 17398 | |
| 14736 | | |
| 17399 | my @x = split(//, "abc"); # ("a", "b", "c") | |
| 14737 | 17400 | |
| 14738 | 17401 | =begin original |
| 14739 | 17402 | |
| 14740 | uses empty string matches as separators t | |
| 17403 | uses empty string matches as separators; thus, the empty string | |
| 14741 | ||
| 17404 | may be used to split EXPR into a list of its component characters. | |
| 14742 | list of its component characters. | |
| 14743 | 17405 | |
| 14744 | 17406 | =end original |
| 14745 | 17407 | |
| 14746 | 空文字列マッチングをセパレータとして使 | |
| 17408 | 空文字列マッチングをセパレータとして使います; 従って、 | |
| 14747 | 17409 | 空文字列は EXPR を構成する文字のリストに分割するために使われます。 |
| 14748 | 17410 | |
| 14749 | 17411 | =begin original |
| 14750 | 17412 | |
| 14751 | As a special case for C<split> | |
| 17413 | As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>, | |
| 14752 | ||
| 17414 | the empty pattern given in | |
| 17415 | L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>) | |
| 17416 | specifically matches the empty string, which is contrary to its usual | |
| 14753 | 17417 | interpretation as the last successful match. |
| 14754 | 17418 | |
| 14755 | 17419 | =end original |
| 14756 | 17420 | |
| 14757 | C<split> の特殊な場合として、 | |
| 17421 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、 | |
| 14758 | L<マッチング演算子|perlop/"m/PATTERN/msixpodualgc"> 文法で与えられた | |
| 17422 | L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた | |
| 14759 | 17423 | 空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した |
| 14760 | 17424 | マッチングという普通の解釈と異なります。 |
| 14761 | 17425 | |
| 14762 | 17426 | =begin original |
| 14763 | 17427 | |
| 14764 | 17428 | If PATTERN is C</^/>, then it is treated as if it used the |
| 14765 | 17429 | L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it |
| 14766 | 17430 | isn't much use otherwise. |
| 14767 | 17431 | |
| 14768 | 17432 | =end original |
| 14769 | 17433 | |
| 14770 | 17434 | PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS> |
| 14771 | 17435 | (C</^/m>) が使われたかのように扱われます; そうでなければほとんど |
| 14772 | 17436 | 使えないからです。 |
| 14773 | 17437 | |
| 14774 | 17438 | =begin original |
| 14775 | 17439 | |
| 14776 | ||
| 17440 | C<E<sol>m> and any of the other pattern modifiers valid for C<qr> | |
| 14777 | ||
| 17441 | (summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be | |
| 14778 | s | |
| 17442 | specified explicitly. | |
| 17443 | ||
| 17444 | =end original | |
| 17445 | ||
| 17446 | C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子 | |
| 17447 | (L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は | |
| 17448 | 明示的に定義されます。 | |
| 17449 | ||
| 17450 | =begin original | |
| 17451 | ||
| 17452 | As another special case, | |
| 17453 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default | |
| 17454 | behavior of the | |
| 17455 | command line tool B<awk> when the PATTERN is either omitted or a | |
| 17456 | string composed of a single space character (such as S<C<' '>> or | |
| 14779 | 17457 | S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading |
| 14780 | 17458 | whitespace in EXPR is removed before splitting occurs, and the PATTERN is |
| 14781 | 17459 | instead treated as if it were C</\s+/>; in particular, this means that |
| 14782 | 17460 | I<any> contiguous whitespace (not just a single space character) is used as |
| 14783 | a separator. | |
| 17461 | a separator. | |
| 14784 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing | |
| 14785 | only a single space character to be a separator. In earlier Perl's this | |
| 14786 | special case was restricted to the use of a plain S<C<" ">> as the | |
| 14787 | pattern argument to split, in Perl 5.18.0 and later this special case is | |
| 14788 | triggered by any expression which evaluates as the simple string S<C<" ">>. | |
| 14789 | 17462 | |
| 14790 | 17463 | =end original |
| 14791 | 17464 | |
| 14792 | もう一つの特別な場合として、 | |
| 17465 | もう一つの特別な場合として、 | |
| 14793 | ||
| 17466 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は | |
| 17467 | PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば | |
| 14794 | 17468 | S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール |
| 14795 | 17469 | B<awk> のデフォルトの振る舞いをエミュレートします。 |
| 14796 | 17470 | この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は |
| 14797 | 17471 | C</\s+/> であったかのように扱われます; 特に、これは (単に単一の |
| 14798 | 17472 | スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして |
| 14799 | 17473 | 使われるということです。 |
| 17474 | ||
| 17475 | my @x = split(" ", " Quick brown fox\n"); | |
| 17476 | # ("Quick", "brown", "fox") | |
| 17477 | ||
| 17478 | my @x = split(" ", "RED\tGREEN\tBLUE"); | |
| 17479 | # ("RED", "GREEN", "BLUE") | |
| 17480 | ||
| 17481 | =begin original | |
| 17482 | ||
| 17483 | Using split in this fashion is very similar to how | |
| 17484 | L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> works. | |
| 17485 | ||
| 17486 | =end original | |
| 17487 | ||
| 17488 | この方法で split を使うのは、 | |
| 17489 | L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> の動作と非常に似ています。 | |
| 17490 | ||
| 17491 | =begin original | |
| 17492 | ||
| 17493 | However, this special treatment can be avoided by specifying | |
| 17494 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing | |
| 17495 | only a single space character to be a separator. In earlier Perls this | |
| 17496 | special case was restricted to the use of a plain S<C<" ">> as the | |
| 17497 | pattern argument to split; in Perl 5.18.0 and later this special case is | |
| 17498 | triggered by any expression which evaluates to the simple string S<C<" ">>. | |
| 17499 | ||
| 17500 | =end original | |
| 17501 | ||
| 14800 | 17502 | しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を |
| 14801 | 17503 | 指定することで回避でき、それによってセパレータとして単一の |
| 14802 | 17504 | スペース文字のみが使われます。 |
| 14803 | 17505 | 以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を |
| 14804 | 使った場合に制限されていました | |
| 17506 | 使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は | |
| 14805 | 単純な文字列 S<C<" ">> | |
| 17507 | 単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。 | |
| 14806 | 17508 | |
| 14807 | 17509 | =begin original |
| 14808 | 17510 | |
| 17511 | As of Perl 5.28, this special-cased whitespace splitting works as expected in | |
| 17512 | the scope of L<< S<C<"use feature 'unicode_strings'">>|feature/The | |
| 17513 | 'unicode_strings' feature >>. In previous versions, and outside the scope of | |
| 17514 | that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are | |
| 17515 | whitespace according to Unicode rules but not according to ASCII rules can be | |
| 17516 | treated as part of fields rather than as field separators, depending on the | |
| 17517 | string's internal encoding. | |
| 17518 | ||
| 17519 | =end original | |
| 17520 | ||
| 17521 | Perl 5.28 から、この特別な場合の空白分割は | |
| 17522 | L<< S<C<"use feature 'unicode_strings'">>|feature/The | |
| 17523 | 'unicode_strings' feature >> のスコープの中では想定通りに動作します。 | |
| 17524 | 以前のバージョンでは、そしてこの機能のスコープの外側では、 | |
| 17525 | これは L<perlunicode/The "Unicode Bug"> を引き起こします: | |
| 17526 | Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、 | |
| 17527 | 文字列の内部エンコーディングに依存して、 | |
| 17528 | フィールドの区切りではなくフィールドの一部として扱われることがあります。 | |
| 17529 | ||
| 17530 | =begin original | |
| 17531 | ||
| 14809 | 17532 | If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering |
| 14810 | 17533 | the previously described I<awk> emulation. |
| 14811 | 17534 | |
| 14812 | 17535 | =end original |
| 14813 | 17536 | |
| 14814 | 17537 | 省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、 |
| 14815 | 17538 | 先に記述した I<awk> エミュレーションを起動します。 |
| 14816 | 17539 | |
| 14817 | 17540 | =begin original |
| 14818 | 17541 | |
| 14819 | 17542 | If LIMIT is specified and positive, it represents the maximum number |
| 14820 | 17543 | of fields into which the EXPR may be split; in other words, LIMIT is |
| 14821 | 17544 | one greater than the maximum number of times EXPR may be split. Thus, |
| 14822 | 17545 | the LIMIT value C<1> means that EXPR may be split a maximum of zero |
| 14823 | 17546 | times, producing a maximum of one field (namely, the entire value of |
| 14824 | 17547 | EXPR). For instance: |
| 14825 | 17548 | |
| 14826 | 17549 | =end original |
| 14827 | 17550 | |
| 14828 | 17551 | LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を |
| 14829 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい | |
| 17552 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。 | |
| 14830 | 数です。 | |
| 14831 | 17553 | 従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、 |
| 14832 | 17554 | 最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。 |
| 14833 | 17555 | 例えば: |
| 14834 | 17556 | |
| 14835 | | |
| 17557 | my @x = split(//, "abc", 1); # ("abc") | |
| 17558 | my @x = split(//, "abc", 2); # ("a", "bc") | |
| 17559 | my @x = split(//, "abc", 3); # ("a", "b", "c") | |
| 17560 | my @x = split(//, "abc", 4); # ("a", "b", "c") | |
| 14836 | 17561 | |
| 14837 | 17562 | =begin original |
| 14838 | 17563 | |
| 14839 | produces the output 'abc', and this: | |
| 14840 | ||
| 14841 | =end original | |
| 14842 | ||
| 14843 | これは 'abc' を出力し、次のものは: | |
| 14844 | ||
| 14845 | print join(':', split(//, 'abc', 2)), "\n"; | |
| 14846 | ||
| 14847 | =begin original | |
| 14848 | ||
| 14849 | produces the output 'a:bc', and each of these: | |
| 14850 | ||
| 14851 | =end original | |
| 14852 | ||
| 14853 | 'a:bc' を出力し、以下のものそれぞれは: | |
| 14854 | ||
| 14855 | print join(':', split(//, 'abc', 3)), "\n"; | |
| 14856 | print join(':', split(//, 'abc', 4)), "\n"; | |
| 14857 | ||
| 14858 | =begin original | |
| 14859 | ||
| 14860 | produces the output 'a:b:c'. | |
| 14861 | ||
| 14862 | =end original | |
| 14863 | ||
| 14864 | 'a:b:c' を出力します。 | |
| 14865 | ||
| 14866 | =begin original | |
| 14867 | ||
| 14868 | 17564 | If LIMIT is negative, it is treated as if it were instead arbitrarily |
| 14869 | 17565 | large; as many fields as possible are produced. |
| 14870 | 17566 | |
| 14871 | 17567 | =end original |
| 14872 | 17568 | |
| 14873 | 17569 | LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの |
| 14874 | 17570 | フィールドが生成されます。 |
| 14875 | 17571 | |
| 14876 | 17572 | =begin original |
| 14877 | 17573 | |
| 14878 | 17574 | If LIMIT is omitted (or, equivalently, zero), then it is usually |
| 14879 | 17575 | treated as if it were instead negative but with the exception that |
| 14880 | 17576 | trailing empty fields are stripped (empty leading fields are always |
| 14881 | 17577 | preserved); if all fields are empty, then all fields are considered to |
| 14882 | 17578 | be trailing (and are thus stripped in this case). Thus, the following: |
| 14883 | 17579 | |
| 14884 | 17580 | =end original |
| 14885 | 17581 | |
| 14886 | 17582 | LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように |
| 14887 | 17583 | 動作しますが、末尾の空フィールドは取り除かれるという例外があります |
| 14888 | 17584 | (先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、 |
| 14889 | 17585 | 全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。 |
| 14890 | 17586 | 従って、以下のようにすると: |
| 14891 | 17587 | |
| 14892 | | |
| 17588 | my @x = split(/,/, "a,b,c,,,"); # ("a", "b", "c") | |
| 14893 | 17589 | |
| 14894 | 17590 | =begin original |
| 14895 | 17591 | |
| 14896 | produces | |
| 17592 | produces only a three element list. | |
| 14897 | 17593 | |
| 14898 | 17594 | =end original |
| 14899 | 17595 | |
| 14900 | ||
| 17596 | 3 要素だけのリストを生成します。 | |
| 14901 | 17597 | |
| 14902 | | |
| 17598 | my @x = split(/,/, "a,b,c,,,", -1); # ("a", "b", "c", "", "", "") | |
| 14903 | 17599 | |
| 14904 | 17600 | =begin original |
| 14905 | 17601 | |
| 14906 | produces | |
| 17602 | produces a six element list. | |
| 14907 | 17603 | |
| 14908 | 17604 | =end original |
| 14909 | 17605 | |
| 14910 | ||
| 17606 | 6 要素のリストを生成します。 | |
| 14911 | 17607 | |
| 14912 | 17608 | =begin original |
| 14913 | 17609 | |
| 14914 | 17610 | In time-critical applications, it is worthwhile to avoid splitting |
| 14915 | 17611 | into more fields than necessary. Thus, when assigning to a list, |
| 14916 | 17612 | if LIMIT is omitted (or zero), then LIMIT is treated as though it |
| 14917 | 17613 | were one larger than the number of variables in the list; for the |
| 14918 | 17614 | following, LIMIT is implicitly 3: |
| 14919 | 17615 | |
| 14920 | 17616 | =end original |
| 14921 | 17617 | |
| 14922 | 17618 | 時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは |
| 14923 | 17619 | 価値があります。 |
| 14924 | 17620 | 従って、リストに代入される場合に、LIMIT が省略される(または 0)と、 |
| 14925 | 17621 | LIMIT は リストにある変数の数より一つ大きい数のように扱われます; |
| 14926 | 17622 | 次の場合、LIMIT は暗黙に 3 になります: |
| 14927 | 17623 | |
| 14928 | ($login, $passwd) = split(/:/); | |
| 17624 | my ($login, $passwd) = split(/:/); | |
| 14929 | 17625 | |
| 14930 | 17626 | =begin original |
| 14931 | 17627 | |
| 14932 | 17628 | Note that splitting an EXPR that evaluates to the empty string always |
| 14933 | 17629 | produces zero fields, regardless of the LIMIT specified. |
| 14934 | 17630 | |
| 14935 | 17631 | =end original |
| 14936 | 17632 | |
| 14937 | 17633 | LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の |
| 14938 | 17634 | フィールドを生成することに注意してください。 |
| 14939 | 17635 | |
| 14940 | 17636 | =begin original |
| 14941 | 17637 | |
| 14942 | 17638 | An empty leading field is produced when there is a positive-width |
| 14943 | 17639 | match at the beginning of EXPR. For instance: |
| 14944 | 17640 | |
| 14945 | 17641 | =end original |
| 14946 | 17642 | |
| 14947 | 17643 | EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが |
| 14948 | 17644 | 生成されます。 |
| 14949 | 17645 | 例えば: |
| 14950 | 17646 | |
| 14951 | | |
| 17647 | my @x = split(/ /, " abc"); # ("", "abc") | |
| 14952 | 17648 | |
| 14953 | 17649 | =begin original |
| 14954 | 17650 | |
| 14955 | p | |
| 17651 | splits into two elements. However, a zero-width match at the | |
| 14956 | 17652 | beginning of EXPR never produces an empty field, so that: |
| 14957 | 17653 | |
| 14958 | 17654 | =end original |
| 14959 | 17655 | |
| 14960 | これは | |
| 17656 | これは 2 要素に分割します。 | |
| 14961 | 17657 | しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので: |
| 14962 | 17658 | |
| 14963 | | |
| 17659 | my @x = split(//, " abc"); # (" ", "a", "b", "c") | |
| 14964 | 17660 | |
| 14965 | 17661 | =begin original |
| 14966 | 17662 | |
| 14967 | p | |
| 17663 | splits into four elements instead of five. | |
| 14968 | 17664 | |
| 14969 | 17665 | =end original |
| 14970 | 17666 | |
| 14971 | これは | |
| 17667 | これは 5 要素ではなく 4 要素に分割します。 | |
| 14972 | 17668 | |
| 14973 | 17669 | =begin original |
| 14974 | 17670 | |
| 14975 | 17671 | An empty trailing field, on the other hand, is produced when there is a |
| 14976 | 17672 | match at the end of EXPR, regardless of the length of the match |
| 14977 | 17673 | (of course, unless a non-zero LIMIT is given explicitly, such fields are |
| 14978 | 17674 | removed, as in the last example). Thus: |
| 14979 | 17675 | |
| 14980 | 17676 | =end original |
| 14981 | 17677 | |
| 14982 | 17678 | 一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で |
| 14983 | 17679 | マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に |
| 14984 | 17680 | 指定されていない場合です; このようなフィールドは前の例のように |
| 14985 | 17681 | 取り除かれます)。 |
| 14986 | 17682 | 従って: |
| 14987 | 17683 | |
| 14988 | | |
| 17684 | my @x = split(//, " abc", -1); # (" ", "a", "b", "c", "") | |
| 14989 | 17685 | |
| 14990 | 17686 | =begin original |
| 14991 | 17687 | |
| 14992 | produces the output S<' :a:b:c:'>. | |
| 14993 | ||
| 14994 | =end original | |
| 14995 | ||
| 14996 | これは出力 S<' :a:b:c:'> を生成します。 | |
| 14997 | ||
| 14998 | =begin original | |
| 14999 | ||
| 15000 | 17688 | If the PATTERN contains |
| 15001 | 17689 | L<capturing groups|perlretut/Grouping things and hierarchical matching>, |
| 15002 | 17690 | then for each separator, an additional field is produced for each substring |
| 15003 | 17691 | captured by a group (in the order in which the groups are specified, |
| 15004 | 17692 | as per L<backreferences|perlretut/Backreferences>); if any group does not |
| 15005 | match, then it captures the C<undef> value instead of a | |
| 17693 | match, then it captures the L<C<undef>|/undef EXPR> value instead of a | |
| 17694 | substring. Also, | |
| 15006 | 17695 | note that any such additional field is produced whenever there is a |
| 15007 | 17696 | separator (that is, whenever a split occurs), and such an additional field |
| 15008 | 17697 | does B<not> count towards the LIMIT. Consider the following expressions |
| 15009 | 17698 | evaluated in list context (each returned list is provided in the associated |
| 15010 | 17699 | comment): |
| 15011 | 17700 | |
| 15012 | 17701 | =end original |
| 15013 | 17702 | |
| 15014 | 17703 | PATTERN が |
| 15015 | 17704 | L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を |
| 15016 | 17705 | 含んでいる場合、それぞれのセパレータについて、 |
| 15017 | 17706 | (L<後方参照|perlretut/Backreferences> のようにグループが指定された) |
| 15018 | 17707 | グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが |
| 15019 | 17708 | 生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに |
| 15020 | C<undef> 値を捕捉します。 | |
| 17709 | L<C<undef>|/undef EXPR> 値を捕捉します。 | |
| 15021 | 17710 | また、このような追加のフィールドはセパレータがあるとき(つまり、分割が |
| 15022 | 17711 | 行われるとき)はいつでも生成され、このような追加のフィールドは |
| 15023 | 17712 | LIMIT に関してはカウント B<されない> ことに注意してください。 |
| 15024 | 17713 | リストコンテキストで評価される以下のような式を考えます |
| 15025 | 17714 | (それぞれの返されるリストは関連づけられたコメントで提供されます): |
| 15026 | 17715 | |
| 15027 | split(/-|,/, "1-10,20", 3) | |
| 17716 | my @x = split(/-|,/ , "1-10,20", 3); | |
| 15028 | # ( | |
| 17717 | # ("1", "10", "20") | |
| 15029 | 17718 | |
| 15030 | split(/(-|,)/, "1-10,20", 3) | |
| 17719 | my @x = split(/(-|,)/ , "1-10,20", 3); | |
| 15031 | # ( | |
| 17720 | # ("1", "-", "10", ",", "20") | |
| 15032 | 17721 | |
| 15033 | split(/-|(,)/, "1-10,20", 3) | |
| 17722 | my @x = split(/-|(,)/ , "1-10,20", 3); | |
| 15034 | # ( | |
| 17723 | # ("1", undef, "10", ",", "20") | |
| 15035 | 17724 | |
| 15036 | split(/(-)|,/, "1-10,20", 3) | |
| 17725 | my @x = split(/(-)|,/ , "1-10,20", 3); | |
| 15037 | # ( | |
| 17726 | # ("1", "-", "10", undef, "20") | |
| 15038 | 17727 | |
| 15039 | split(/(-)|(,)/, "1-10,20", 3) | |
| 17728 | my @x = split(/(-)|(,)/, "1-10,20", 3); | |
| 15040 | # ( | |
| 17729 | # ("1", "-", undef, "10", undef, ",", "20") | |
| 15041 | 17730 | |
| 15042 | 17731 | =item sprintf FORMAT, LIST |
| 15043 | 17732 | X<sprintf> |
| 15044 | 17733 | |
| 15045 | 17734 | =for Pod::Functions formatted print into a string |
| 15046 | 17735 | |
| 15047 | 17736 | =begin original |
| 15048 | 17737 | |
| 15049 | Returns a string formatted by the usual | |
| 17738 | Returns a string formatted by the usual | |
| 15050 | ||
| 17739 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C | |
| 15051 | an | |
| 17740 | library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for | |
| 15052 | ||
| 17741 | more details and see L<sprintf(3)> or L<printf(3)> on your system for an | |
| 17742 | explanation of the general principles. | |
| 15053 | 17743 | |
| 15054 | 17744 | =end original |
| 15055 | 17745 | |
| 15056 | ||
| 17746 | C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の | |
| 17747 | 普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の | |
| 17748 | 整形された文字列を返します。 | |
| 15057 | 17749 | 一般的な原則の説明については以下の説明と、システムの |
| 15058 | 17750 | L<sprintf(3)> または L<printf(3)> の説明を参照してください。 |
| 15059 | 17751 | |
| 15060 | 17752 | =begin original |
| 15061 | 17753 | |
| 15062 | 17754 | For example: |
| 15063 | 17755 | |
| 15064 | 17756 | =end original |
| 15065 | 17757 | |
| 15066 | 17758 | 例えば: |
| 15067 | 17759 | |
| 15068 | 17760 | # Format number with up to 8 leading zeroes |
| 15069 | $result = sprintf("%08d", $number); | |
| 17761 | my $result = sprintf("%08d", $number); | |
| 15070 | 17762 | |
| 15071 | 17763 | # Round number to 3 digits after decimal point |
| 15072 | $rounded = sprintf("%.3f", $number); | |
| 17764 | my $rounded = sprintf("%.3f", $number); | |
| 15073 | 17765 | |
| 15074 | 17766 | =begin original |
| 15075 | 17767 | |
| 15076 | Perl does its own C<sprintf> formatting: it | |
| 17768 | Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it | |
| 15077 | ||
| 17769 | emulates the C | |
| 15078 | ||
| 17770 | function L<sprintf(3)>, but doesn't use it except for floating-point | |
| 15079 | ||
| 17771 | numbers, and even then only standard modifiers are allowed. | |
| 17772 | Non-standard extensions in your local L<sprintf(3)> are | |
| 15080 | 17773 | therefore unavailable from Perl. |
| 15081 | 17774 | |
| 15082 | 17775 | =end original |
| 15083 | 17776 | |
| 15084 | Perl は C<sprintf> フォーマット処理を自力で行います: | |
| 17777 | Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います: | |
| 15085 | これは C の sprintf(3) 関数をエミュレートしますが、 | |
| 17778 | これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません | |
| 15086 | ||
| 17779 | (浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。 | |
| 15087 | ||
| 17780 | 従って、ローカルな非標準の L<sprintf(3)> 拡張機能は Perl では使えません。 | |
| 15088 | 従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。 | |
| 15089 | 17781 | |
| 15090 | 17782 | =begin original |
| 15091 | 17783 | |
| 15092 | Unlike C<printf> | |
| 17784 | Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 15093 | p | |
| 17785 | L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean | |
| 17786 | when you pass it an array as your first argument. | |
| 15094 | 17787 | The array is given scalar context, |
| 15095 | 17788 | and instead of using the 0th element of the array as the format, Perl will |
| 15096 | 17789 | use the count of elements in the array as the format, which is almost never |
| 15097 | 17790 | useful. |
| 15098 | 17791 | |
| 15099 | 17792 | =end original |
| 15100 | 17793 | |
| 15101 | C<printf> | |
| 17794 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違って、 | |
| 17795 | L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても | |
| 15102 | 17796 | あなたが多分望むとおりには動作しません。 |
| 15103 | 17797 | 配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、 |
| 15104 | 17798 | 配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。 |
| 15105 | 17799 | |
| 15106 | 17800 | =begin original |
| 15107 | 17801 | |
| 15108 | Perl's C<sprintf> permits the following | |
| 17802 | Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following | |
| 17803 | universally-known conversions: | |
| 15109 | 17804 | |
| 15110 | 17805 | =end original |
| 15111 | 17806 | |
| 15112 | Perl の C<sprintf> は以下の一般に知られている変換に | |
| 17807 | Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に | |
| 17808 | 対応しています: | |
| 15113 | 17809 | |
| 15114 | 17810 | =begin original |
| 15115 | 17811 | |
| 15116 | 17812 | %% a percent sign |
| 15117 | 17813 | %c a character with the given number |
| 15118 | 17814 | %s a string |
| 15119 | 17815 | %d a signed integer, in decimal |
| 15120 | 17816 | %u an unsigned integer, in decimal |
| 15121 | 17817 | %o an unsigned integer, in octal |
| 15122 | 17818 | %x an unsigned integer, in hexadecimal |
| 15123 | 17819 | %e a floating-point number, in scientific notation |
| 15124 | 17820 | %f a floating-point number, in fixed decimal notation |
| 15125 | 17821 | %g a floating-point number, in %e or %f notation |
| 15126 | 17822 | |
| 15127 | 17823 | =end original |
| 15128 | 17824 | |
| 15129 | 17825 | %% パーセントマーク |
| 15130 | 17826 | %c 与えられた番号の文字 |
| 15131 | 17827 | %s 文字列 |
| 15132 | 17828 | %d 符号付き 10 進数 |
| 15133 | 17829 | %u 符号なし 10 進数 |
| 15134 | 17830 | %o 符号なし 8 進数 |
| 15135 | 17831 | %x 符号なし 16 進数 |
| 15136 | 17832 | %e 科学的表記の浮動小数点数 |
| 15137 | 17833 | %f 固定 10 進数表記の浮動小数点数 |
| 15138 | 17834 | %g %e か %f の表記の浮動小数点数 |
| 15139 | 17835 | |
| 15140 | 17836 | =begin original |
| 15141 | 17837 | |
| 15142 | 17838 | In addition, Perl permits the following widely-supported conversions: |
| 15143 | 17839 | |
| 15144 | 17840 | =end original |
| 15145 | 17841 | |
| 15146 | 17842 | さらに、Perl では以下のよく使われている変換に対応しています: |
| 15147 | 17843 | |
| 15148 | 17844 | =begin original |
| 15149 | 17845 | |
| 15150 | 17846 | %X like %x, but using upper-case letters |
| 15151 | 17847 | %E like %e, but using an upper-case "E" |
| 15152 | 17848 | %G like %g, but with an upper-case "E" (if applicable) |
| 15153 | 17849 | %b an unsigned integer, in binary |
| 15154 | 17850 | %B like %b, but using an upper-case "B" with the # flag |
| 15155 | 17851 | %p a pointer (outputs the Perl value's address in hexadecimal) |
| 15156 | 17852 | %n special: *stores* the number of characters output so far |
| 15157 | 17853 | into the next argument in the parameter list |
| 17854 | %a hexadecimal floating point | |
| 17855 | %A like %a, but using upper-case letters | |
| 15158 | 17856 | |
| 15159 | 17857 | =end original |
| 15160 | 17858 | |
| 15161 | 17859 | %X %x と同様だが大文字を使う |
| 15162 | 17860 | %E %e と同様だが大文字の "E" を使う |
| 15163 | 17861 | %G %g と同様だが(適切なら)大文字の "E" を使う |
| 15164 | 17862 | %b 符号なし 2 進数 |
| 15165 | 17863 | %B %b と同様だが、# フラグで大文字の "B" を使う |
| 15166 | 17864 | %p ポインタ (Perl の値のアドレスを 16 進数で出力する) |
| 15167 | 17865 | %n 特殊: 出力文字数を引数リストの次の変数に「格納」する |
| 17866 | %a 16 進浮動小数点 | |
| 17867 | %A %a と同様だが、大文字を使う | |
| 15168 | 17868 | |
| 15169 | 17869 | =begin original |
| 15170 | 17870 | |
| 15171 | 17871 | Finally, for backward (and we do mean "backward") compatibility, Perl |
| 15172 | 17872 | permits these unnecessary but widely-supported conversions: |
| 15173 | 17873 | |
| 15174 | 17874 | =end original |
| 15175 | 17875 | |
| 15176 | 17876 | 最後に、過去との互換性(これは「過去」だと考えています)のために、 |
| 15177 | 17877 | Perl は以下の不要ではあるけれども広く使われている変換に対応しています。 |
| 15178 | 17878 | |
| 15179 | 17879 | =begin original |
| 15180 | 17880 | |
| 15181 | 17881 | %i a synonym for %d |
| 15182 | 17882 | %D a synonym for %ld |
| 15183 | 17883 | %U a synonym for %lu |
| 15184 | 17884 | %O a synonym for %lo |
| 15185 | 17885 | %F a synonym for %f |
| 15186 | 17886 | |
| 15187 | 17887 | =end original |
| 15188 | 17888 | |
| 15189 | 17889 | %i %d の同義語 |
| 15190 | 17890 | %D %ld の同義語 |
| 15191 | 17891 | %U %lu の同義語 |
| 15192 | 17892 | %O %lo の同義語 |
| 15193 | 17893 | %F %f の同義語 |
| 15194 | 17894 | |
| 15195 | 17895 | =begin original |
| 15196 | 17896 | |
| 15197 | 17897 | Note that the number of exponent digits in the scientific notation produced |
| 15198 | 17898 | by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the |
| 15199 | 17899 | exponent less than 100 is system-dependent: it may be three or less |
| 15200 | 17900 | (zero-padded as necessary). In other words, 1.23 times ten to the |
| 15201 | 99th may be either "1.23e99" or "1.23e099". | |
| 17901 | 99th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>: | |
| 17902 | the exponent or the hexadecimal digits may float: especially the | |
| 17903 | "long doubles" Perl configuration option may cause surprises. | |
| 15202 | 17904 | |
| 15203 | 17905 | =end original |
| 15204 | 17906 | |
| 15205 | 17907 | C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の |
| 15206 | 17908 | 指数部の科学的な表記法はシステム依存であることに注意してください: |
| 15207 | 17909 | 3 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で |
| 15208 | 17910 | パッディングされます)。 |
| 15209 | 17911 | 言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし |
| 15210 | 17912 | "1.23e099" かもしれません。 |
| 17913 | 同様に C<%a> と C<%A> の場合: | |
| 17914 | 指数部と 16 進数が浮動小数点かもしれません: | |
| 17915 | 特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。 | |
| 15211 | 17916 | |
| 15212 | 17917 | =begin original |
| 15213 | 17918 | |
| 15214 | 17919 | Between the C<%> and the format letter, you may specify several |
| 15215 | 17920 | additional attributes controlling the interpretation of the format. |
| 15216 | 17921 | In order, these are: |
| 15217 | 17922 | |
| 15218 | 17923 | =end original |
| 15219 | 17924 | |
| 15220 | 17925 | C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、 |
| 15221 | 17926 | いくつかの追加の属性を指定できます。 |
| 15222 | 17927 | 順番に、以下のものがあります: |
| 15223 | 17928 | |
| 15224 | 17929 | =over 4 |
| 15225 | 17930 | |
| 15226 | 17931 | =item format parameter index |
| 15227 | 17932 | |
| 15228 | 17933 | (フォーマットパラメータインデックス) |
| 15229 | 17934 | |
| 15230 | 17935 | =begin original |
| 15231 | 17936 | |
| 15232 | 17937 | An explicit format parameter index, such as C<2$>. By default sprintf |
| 15233 | 17938 | will format the next unused argument in the list, but this allows you |
| 15234 | 17939 | to take the arguments out of order: |
| 15235 | 17940 | |
| 15236 | 17941 | =end original |
| 15237 | 17942 | |
| 15238 | 17943 | C<2$> のような明示的なフォーマットパラメータインデックス。 |
| 15239 | 17944 | デフォルトでは sprintf はリストの次の使われていない引数を |
| 15240 | 17945 | フォーマットしますが、これによって異なった順番の引数を使えるようにします: |
| 15241 | 17946 | |
| 15242 | 17947 | printf '%2$d %1$d', 12, 34; # prints "34 12" |
| 15243 | 17948 | printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1" |
| 15244 | 17949 | |
| 15245 | 17950 | =item flags |
| 15246 | 17951 | |
| 15247 | 17952 | (フラグ) |
| 15248 | 17953 | |
| 15249 | 17954 | =begin original |
| 15250 | 17955 | |
| 15251 | 17956 | one or more of: |
| 15252 | 17957 | |
| 15253 | 17958 | =end original |
| 15254 | 17959 | |
| 15255 | 17960 | 以下のうちの一つまたは複数指定できます: |
| 15256 | 17961 | |
| 15257 | 17962 | =begin original |
| 15258 | 17963 | |
| 15259 | 17964 | space prefix non-negative number with a space |
| 15260 | 17965 | + prefix non-negative number with a plus sign |
| 15261 | 17966 | - left-justify within the field |
| 15262 | 17967 | 0 use zeros, not spaces, to right-justify |
| 15263 | 17968 | # ensure the leading "0" for any octal, |
| 15264 | 17969 | prefix non-zero hexadecimal with "0x" or "0X", |
| 15265 | 17970 | prefix non-zero binary with "0b" or "0B" |
| 15266 | 17971 | |
| 15267 | 17972 | =end original |
| 15268 | 17973 | |
| 15269 | 17974 | space 非負数の前に空白をつける |
| 15270 | 17975 | + 非負数の前にプラス記号をつける |
| 15271 | 17976 | - フィールド内で左詰めする |
| 15272 | 17977 | 0 右詰めに空白ではなくゼロを使う |
| 15273 | 17978 | # 8 進数では確実に先頭に "0" をつける; |
| 15274 | 17979 | 非 0 の 16 進数では "0x" か "0X" をつける; |
| 15275 | 17980 | 非 0 の 2 進数では "0b" か "0B" をつける |
| 15276 | 17981 | |
| 15277 | 17982 | =begin original |
| 15278 | 17983 | |
| 15279 | 17984 | For example: |
| 15280 | 17985 | |
| 15281 | 17986 | =end original |
| 15282 | 17987 | |
| 15283 | 17988 | 例えば: |
| 15284 | 17989 | |
| 15285 | 17990 | printf '<% d>', 12; # prints "< 12>" |
| 17991 | printf '<% d>', 0; # prints "< 0>" | |
| 17992 | printf '<% d>', -12; # prints "<-12>" | |
| 15286 | 17993 | printf '<%+d>', 12; # prints "<+12>" |
| 17994 | printf '<%+d>', 0; # prints "<+0>" | |
| 17995 | printf '<%+d>', -12; # prints "<-12>" | |
| 15287 | 17996 | printf '<%6s>', 12; # prints "< 12>" |
| 15288 | 17997 | printf '<%-6s>', 12; # prints "<12 >" |
| 15289 | 17998 | printf '<%06s>', 12; # prints "<000012>" |
| 15290 | 17999 | printf '<%#o>', 12; # prints "<014>" |
| 15291 | 18000 | printf '<%#x>', 12; # prints "<0xc>" |
| 15292 | 18001 | printf '<%#X>', 12; # prints "<0XC>" |
| 15293 | 18002 | printf '<%#b>', 12; # prints "<0b1100>" |
| 15294 | 18003 | printf '<%#B>', 12; # prints "<0B1100>" |
| 15295 | 18004 | |
| 15296 | 18005 | =begin original |
| 15297 | 18006 | |
| 15298 | 18007 | When a space and a plus sign are given as the flags at once, |
| 15299 | ||
| 18008 | the space is ignored. | |
| 15300 | 18009 | |
| 15301 | 18010 | =end original |
| 15302 | 18011 | |
| 15303 | 空白とプラス記号がフラグとして同時に与えられると、 | |
| 18012 | 空白とプラス記号がフラグとして同時に与えられると、 | |
| 15304 | ||
| 18013 | 空白は無視されます。 | |
| 15305 | 18014 | |
| 15306 | 18015 | printf '<%+ d>', 12; # prints "<+12>" |
| 15307 | 18016 | printf '<% +d>', 12; # prints "<+12>" |
| 15308 | 18017 | |
| 15309 | 18018 | =begin original |
| 15310 | 18019 | |
| 15311 | 18020 | When the # flag and a precision are given in the %o conversion, |
| 15312 | 18021 | the precision is incremented if it's necessary for the leading "0". |
| 15313 | 18022 | |
| 15314 | 18023 | =end original |
| 15315 | 18024 | |
| 15316 | 18025 | %o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は |
| 15317 | 18026 | 精度に 1 が加えられます。 |
| 15318 | 18027 | |
| 15319 | 18028 | printf '<%#.5o>', 012; # prints "<00012>" |
| 15320 | 18029 | printf '<%#.5o>', 012345; # prints "<012345>" |
| 15321 | 18030 | printf '<%#.0o>', 0; # prints "<0>" |
| 15322 | 18031 | |
| 15323 | 18032 | =item vector flag |
| 15324 | 18033 | |
| 15325 | 18034 | (ベクタフラグ) |
| 15326 | 18035 | |
| 15327 | 18036 | =begin original |
| 15328 | 18037 | |
| 15329 | 18038 | This flag tells Perl to interpret the supplied string as a vector of |
| 15330 | 18039 | integers, one for each character in the string. Perl applies the format to |
| 15331 | 18040 | each integer in turn, then joins the resulting strings with a separator (a |
| 15332 | 18041 | dot C<.> by default). This can be useful for displaying ordinal values of |
| 15333 | 18042 | characters in arbitrary strings: |
| 15334 | 18043 | |
| 15335 | 18044 | =end original |
| 15336 | 18045 | |
| 15337 | 18046 | このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして |
| 15338 | 18047 | 解釈させます。 |
| 15339 | 18048 | Perl は各数値をフォーマットし、それから結果の文字列をセパレータ |
| 15340 | 18049 | (デフォルトでは C<.>)で連結します。 |
| 15341 | 18050 | これは任意の文字列の文字を順序付きの値として表示するのに便利です: |
| 15342 | 18051 | |
| 15343 | 18052 | printf "%vd", "AB\x{100}"; # prints "65.66.256" |
| 15344 | 18053 | printf "version is v%vd\n", $^V; # Perl's version |
| 15345 | 18054 | |
| 15346 | 18055 | =begin original |
| 15347 | 18056 | |
| 15348 | 18057 | Put an asterisk C<*> before the C<v> to override the string to |
| 15349 | 18058 | use to separate the numbers: |
| 15350 | 18059 | |
| 15351 | 18060 | =end original |
| 15352 | 18061 | |
| 15353 | 18062 | アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を |
| 15354 | 18063 | 上書きします: |
| 15355 | 18064 | |
| 15356 | 18065 | printf "address is %*vX\n", ":", $addr; # IPv6 address |
| 15357 | 18066 | printf "bits are %0*v8b\n", " ", $bits; # random bitstring |
| 15358 | 18067 | |
| 15359 | 18068 | =begin original |
| 15360 | 18069 | |
| 15361 | 18070 | You can also explicitly specify the argument number to use for |
| 15362 | 18071 | the join string using something like C<*2$v>; for example: |
| 15363 | 18072 | |
| 15364 | 18073 | =end original |
| 15365 | 18074 | |
| 15366 | 18075 | また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に |
| 15367 | 18076 | 指定できます; 例えば: |
| 15368 | 18077 | |
| 15369 | 18078 | printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses |
| 15370 | 18079 | @addr[1..3], ":"; |
| 15371 | 18080 | |
| 15372 | 18081 | =item (minimum) width |
| 15373 | 18082 | |
| 15374 | 18083 | ((最小)幅) |
| 15375 | 18084 | |
| 15376 | 18085 | =begin original |
| 15377 | 18086 | |
| 15378 | 18087 | Arguments are usually formatted to be only as wide as required to |
| 15379 | 18088 | display the given value. You can override the width by putting |
| 15380 | 18089 | a number here, or get the width from the next argument (with C<*>) |
| 15381 | 18090 | or from a specified argument (e.g., with C<*2$>): |
| 15382 | 18091 | |
| 15383 | 18092 | =end original |
| 15384 | 18093 | |
| 15385 | 18094 | 引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。 |
| 15386 | 18095 | ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で |
| 15387 | 18096 | 幅を上書きできます。 |
| 15388 | 18097 | |
| 15389 | 18098 | printf "<%s>", "a"; # prints "<a>" |
| 15390 | 18099 | printf "<%6s>", "a"; # prints "< a>" |
| 15391 | 18100 | printf "<%*s>", 6, "a"; # prints "< a>" |
| 15392 | 18101 | printf '<%*2$s>', "a", 6; # prints "< a>" |
| 15393 | 18102 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) |
| 15394 | 18103 | |
| 15395 | 18104 | =begin original |
| 15396 | 18105 | |
| 15397 | 18106 | If a field width obtained through C<*> is negative, it has the same |
| 15398 | 18107 | effect as the C<-> flag: left-justification. |
| 15399 | 18108 | |
| 15400 | 18109 | =end original |
| 15401 | 18110 | |
| 15402 | 18111 | C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと |
| 15403 | 18112 | 同様の効果 (左詰め) があります。 |
| 15404 | 18113 | |
| 15405 | 18114 | =item precision, or maximum width |
| 15406 | 18115 | X<precision> |
| 15407 | 18116 | |
| 15408 | 18117 | (精度あるいは最大幅) |
| 15409 | 18118 | |
| 15410 | 18119 | =begin original |
| 15411 | 18120 | |
| 15412 | 18121 | You can specify a precision (for numeric conversions) or a maximum |
| 15413 | 18122 | width (for string conversions) by specifying a C<.> followed by a number. |
| 15414 | 18123 | For floating-point formats except C<g> and C<G>, this specifies |
| 15415 | 18124 | how many places right of the decimal point to show (the default being 6). |
| 15416 | 18125 | For example: |
| 15417 | 18126 | |
| 15418 | 18127 | =end original |
| 15419 | 18128 | |
| 15420 | 18129 | C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合) |
| 15421 | 18130 | 最大幅を指定できます。 |
| 15422 | 18131 | 小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の |
| 15423 | 18132 | 桁数を指定します(デフォルトは 6 です)。 |
| 15424 | 18133 | 例えば: |
| 15425 | 18134 | |
| 15426 | 18135 | # these examples are subject to system-specific variation |
| 15427 | 18136 | printf '<%f>', 1; # prints "<1.000000>" |
| 15428 | 18137 | printf '<%.1f>', 1; # prints "<1.0>" |
| 15429 | 18138 | printf '<%.0f>', 1; # prints "<1>" |
| 15430 | 18139 | printf '<%e>', 10; # prints "<1.000000e+01>" |
| 15431 | 18140 | printf '<%.1e>', 10; # prints "<1.0e+01>" |
| 15432 | 18141 | |
| 15433 | 18142 | =begin original |
| 15434 | 18143 | |
| 15435 | For "g" and "G", this specifies the maximum number of digits to | |
| 18144 | For "g" and "G", this specifies the maximum number of significant digits to | |
| 15436 | ||
| 18145 | show; for example: | |
| 15437 | example: | |
| 15438 | 18146 | |
| 15439 | 18147 | =end original |
| 15440 | 18148 | |
| 15441 | "g" と "G" の場合、これは | |
| 18149 | "g" と "G" の場合、これは最大有効数字を指定します; 例えば: | |
| 15442 | これには小数点の前の数値と後の数値を含みます; 例えば: | |
| 15443 | 18150 | |
| 15444 | 18151 | # These examples are subject to system-specific variation. |
| 15445 | 18152 | printf '<%g>', 1; # prints "<1>" |
| 15446 | 18153 | printf '<%.10g>', 1; # prints "<1>" |
| 15447 | 18154 | printf '<%g>', 100; # prints "<100>" |
| 15448 | 18155 | printf '<%.1g>', 100; # prints "<1e+02>" |
| 15449 | 18156 | printf '<%.2g>', 100.01; # prints "<1e+02>" |
| 15450 | 18157 | printf '<%.5g>', 100.01; # prints "<100.01>" |
| 15451 | 18158 | printf '<%.4g>', 100.01; # prints "<100>" |
| 18159 | printf '<%.1g>', 0.0111; # prints "<0.01>" | |
| 18160 | printf '<%.2g>', 0.0111; # prints "<0.011>" | |
| 18161 | printf '<%.3g>', 0.0111; # prints "<0.0111>" | |
| 15452 | 18162 | |
| 15453 | 18163 | =begin original |
| 15454 | 18164 | |
| 15455 | 18165 | For integer conversions, specifying a precision implies that the |
| 15456 | 18166 | output of the number itself should be zero-padded to this width, |
| 15457 | 18167 | where the 0 flag is ignored: |
| 15458 | 18168 | |
| 15459 | 18169 | =end original |
| 15460 | 18170 | |
| 15461 | 18171 | 整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で |
| 15462 | 18172 | パッディングするべきであることを暗に示すことになり、0 フラグは |
| 15463 | 18173 | 無視されます: |
| 15464 | 18174 | |
| 15465 | 18175 | printf '<%.6d>', 1; # prints "<000001>" |
| 15466 | 18176 | printf '<%+.6d>', 1; # prints "<+000001>" |
| 15467 | 18177 | printf '<%-10.6d>', 1; # prints "<000001 >" |
| 15468 | 18178 | printf '<%10.6d>', 1; # prints "< 000001>" |
| 15469 | 18179 | printf '<%010.6d>', 1; # prints "< 000001>" |
| 15470 | 18180 | printf '<%+10.6d>', 1; # prints "< +000001>" |
| 15471 | 18181 | |
| 15472 | 18182 | printf '<%.6x>', 1; # prints "<000001>" |
| 15473 | 18183 | printf '<%#.6x>', 1; # prints "<0x000001>" |
| 15474 | 18184 | printf '<%-10.6x>', 1; # prints "<000001 >" |
| 15475 | 18185 | printf '<%10.6x>', 1; # prints "< 000001>" |
| 15476 | 18186 | printf '<%010.6x>', 1; # prints "< 000001>" |
| 15477 | 18187 | printf '<%#10.6x>', 1; # prints "< 0x000001>" |
| 15478 | 18188 | |
| 15479 | 18189 | =begin original |
| 15480 | 18190 | |
| 15481 | 18191 | For string conversions, specifying a precision truncates the string |
| 15482 | 18192 | to fit the specified width: |
| 15483 | 18193 | |
| 15484 | 18194 | =end original |
| 15485 | 18195 | |
| 15486 | 18196 | 文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を |
| 15487 | 18197 | 切り詰めます: |
| 15488 | 18198 | |
| 15489 | 18199 | printf '<%.5s>', "truncated"; # prints "<trunc>" |
| 15490 | 18200 | printf '<%10.5s>', "truncated"; # prints "< trunc>" |
| 15491 | 18201 | |
| 15492 | 18202 | =begin original |
| 15493 | 18203 | |
| 15494 | You can also get the precision from the next argument using C<.*> | |
| 18204 | You can also get the precision from the next argument using C<.*>, or from a | |
| 18205 | specified argument (e.g., with C<.*2$>): | |
| 15495 | 18206 | |
| 15496 | 18207 | =end original |
| 15497 | 18208 | |
| 15498 | C<.*> を使って精度を次の引数から取 | |
| 18209 | C<.*> を使って精度を次の引数から取ったり、 | |
| 18210 | (C<.*2$> のように) 指定した引数から取ったりすることもできます: | |
| 15499 | 18211 | |
| 15500 | 18212 | printf '<%.6x>', 1; # prints "<000001>" |
| 15501 | 18213 | printf '<%.*x>', 6, 1; # prints "<000001>" |
| 15502 | 18214 | |
| 18215 | printf '<%.*2$x>', 1, 6; # prints "<000001>" | |
| 18216 | ||
| 18217 | printf '<%6.*2$x>', 1, 4; # prints "< 0001>" | |
| 18218 | ||
| 15503 | 18219 | =begin original |
| 15504 | 18220 | |
| 15505 | 18221 | If a precision obtained through C<*> is negative, it counts |
| 15506 | 18222 | as having no precision at all. |
| 15507 | 18223 | |
| 15508 | 18224 | =end original |
| 15509 | 18225 | |
| 15510 | 18226 | C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と |
| 15511 | 18227 | 同じ効果となります。 |
| 15512 | 18228 | |
| 15513 | 18229 | printf '<%.*s>', 7, "string"; # prints "<string>" |
| 15514 | 18230 | printf '<%.*s>', 3, "string"; # prints "<str>" |
| 15515 | 18231 | printf '<%.*s>', 0, "string"; # prints "<>" |
| 15516 | 18232 | printf '<%.*s>', -1, "string"; # prints "<string>" |
| 15517 | 18233 | |
| 15518 | 18234 | printf '<%.*d>', 1, 0; # prints "<0>" |
| 15519 | 18235 | printf '<%.*d>', 0, 0; # prints "<>" |
| 15520 | 18236 | printf '<%.*d>', -1, 0; # prints "<0>" |
| 15521 | 18237 | |
| 15522 | =begin original | |
| 15523 | ||
| 15524 | You cannot currently get the precision from a specified number, | |
| 15525 | but it is intended that this will be possible in the future, for | |
| 15526 | example using C<.*2$>: | |
| 15527 | ||
| 15528 | =end original | |
| 15529 | ||
| 15530 | 現在のところ精度を指定した数値から得ることはできませんが、 | |
| 15531 | 将来は 例えば C<.*2$> のようにして可能にしようとしています: | |
| 15532 | ||
| 15533 | printf '<%.*2$x>', 1, 6; # INVALID, but in future will print | |
| 15534 | # "<000001>" | |
| 15535 | ||
| 15536 | 18238 | =item size |
| 15537 | 18239 | |
| 15538 | 18240 | (サイズ) |
| 15539 | 18241 | |
| 15540 | 18242 | =begin original |
| 15541 | 18243 | |
| 15542 | 18244 | For numeric conversions, you can specify the size to interpret the |
| 15543 | 18245 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer |
| 15544 | 18246 | conversions (C<d u o x X b i D U O>), numbers are usually assumed to be |
| 15545 | 18247 | whatever the default integer size is on your platform (usually 32 or 64 |
| 15546 | 18248 | bits), but you can override this to use instead one of the standard C types, |
| 15547 | 18249 | as supported by the compiler used to build Perl: |
| 15548 | 18250 | |
| 15549 | 18251 | =end original |
| 15550 | 18252 | |
| 15551 | 18253 | 数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の |
| 15552 | 18254 | 大きさを指定できます。 |
| 15553 | 18255 | 整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの |
| 15554 | 18256 | デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、 |
| 15555 | 18257 | これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで |
| 15556 | 18258 | 上書きできます: |
| 15557 | 18259 | |
| 15558 | 18260 | =begin original |
| 15559 | 18261 | |
| 15560 | 18262 | hh interpret integer as C type "char" or "unsigned |
| 15561 | 18263 | char" on Perl 5.14 or later |
| 15562 | 18264 | h interpret integer as C type "short" or |
| 15563 | 18265 | "unsigned short" |
| 15564 | 18266 | j interpret integer as C type "intmax_t" on Perl |
| 15565 | 5.14 or later | |
| 18267 | 5.14 or later; and prior to Perl 5.30, only with | |
| 15566 | (unportable) | |
| 18268 | a C99 compiler (unportable) | |
| 15567 | 18269 | l interpret integer as C type "long" or |
| 15568 | 18270 | "unsigned long" |
| 15569 | 18271 | q, L, or ll interpret integer as C type "long long", |
| 15570 | 18272 | "unsigned long long", or "quad" (typically |
| 15571 | 18273 | 64-bit integers) |
| 15572 | 18274 | t interpret integer as C type "ptrdiff_t" on Perl |
| 15573 | 18275 | 5.14 or later |
| 15574 | z interpret integer as C type "size_t" o | |
| 18276 | z interpret integer as C types "size_t" or | |
| 15575 | or later | |
| 18277 | "ssize_t" on Perl 5.14 or later | |
| 15576 | 18278 | |
| 15577 | 18279 | =end original |
| 15578 | 18280 | |
| 15579 | 18281 | hh Perl 5.14 以降で整数を C の "char" または "unsigned char" |
| 15580 | 18282 | 型として解釈する |
| 15581 | 18283 | h 整数を C の "char" または "unsigned char" 型として解釈する |
| 15582 | j Perl 5.14 以降 C99 コンパイラのみで整数を | |
| 18284 | j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を | |
| 15583 | 型として解釈する (移植性なし) | |
| 18285 | C の "intmax_t" 型として解釈する (移植性なし) | |
| 15584 | 18286 | l 整数を C の "long" または "unsigned long" と解釈する |
| 15585 | 18287 | h 整数を C の "short" または "unsigned short" と解釈する |
| 15586 | 18288 | q, L or ll 整数を C の "long long", "unsigned long long", |
| 15587 | 18289 | "quads"(典型的には 64 ビット整数) のどれかと解釈する |
| 15588 | 18290 | t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する |
| 15589 | z Perl 5.14 以降で整数を C の "size_t" 型 | |
| 18291 | z Perl 5.14 以降で整数を C の "size_t" 型または "ssize_t" 型 | |
| 18292 | として解釈する | |
| 15590 | 18293 | |
| 15591 | 18294 | =begin original |
| 15592 | 18295 | |
| 18296 | Note that, in general, using the C<l> modifier (for example, when writing | |
| 18297 | C<"%ld"> or C<"%lu"> instead of C<"%d"> and C<"%u">) is unnecessary | |
| 18298 | when used from Perl code. Moreover, it may be harmful, for example on | |
| 18299 | Windows 64-bit where a long is 32-bits. | |
| 18300 | ||
| 18301 | =end original | |
| 18302 | ||
| 18303 | 一般的に、C<l> 修飾子を使う (例えば、C<"%d"> と C<"%u"> ではなく | |
| 18304 | C<"%ld"> や C<"%lu"> と書く) ことは、Perl のコードから使われる場合は | |
| 18305 | 不要であることに注意してください。 | |
| 18306 | さらに、例えば long が 32 ビットのときの 64 ビット Windows のように、 | |
| 18307 | 有害な場合もあります。 | |
| 18308 | ||
| 18309 | =begin original | |
| 18310 | ||
| 15593 | 18311 | As of 5.14, none of these raises an exception if they are not supported on |
| 15594 | 18312 | your platform. However, if warnings are enabled, a warning of the |
| 15595 | C<printf> warning class is issued on an unsupported | |
| 18313 | L<C<printf>|warnings> warning class is issued on an unsupported | |
| 15596 | Should you instead prefer an exception, do this: | |
| 18314 | conversion flag. Should you instead prefer an exception, do this: | |
| 15597 | 18315 | |
| 15598 | 18316 | =end original |
| 15599 | 18317 | |
| 15600 | 18318 | 5.14 から、プラットフォームがこれらに対応していないときでも例外が |
| 15601 | 18319 | 発生しなくなりました。 |
| 15602 | 18320 | しかし、もし警告が有効になっているなら、 |
| 15603 | 非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。 | |
| 18321 | 非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。 | |
| 15604 | 18322 | 例外の方がお好みなら、以下のようにします: |
| 15605 | 18323 | |
| 15606 | 18324 | use warnings FATAL => "printf"; |
| 15607 | 18325 | |
| 15608 | 18326 | =begin original |
| 15609 | 18327 | |
| 15610 | 18328 | If you would like to know about a version dependency before you |
| 15611 | 18329 | start running the program, put something like this at its top: |
| 15612 | 18330 | |
| 15613 | 18331 | =end original |
| 15614 | 18332 | |
| 15615 | 18333 | プログラムの実行開始前にバージョン依存について知りたいなら、先頭に |
| 15616 | 18334 | 以下のようなものを書きます: |
| 15617 | 18335 | |
| 15618 | use 5. | |
| 18336 | use v5.14; # for hh/j/t/z/ printf modifiers | |
| 15619 | 18337 | |
| 15620 | 18338 | =begin original |
| 15621 | 18339 | |
| 15622 | 18340 | You can find out whether your Perl supports quads via L<Config>: |
| 15623 | 18341 | |
| 15624 | 18342 | =end original |
| 15625 | 18343 | |
| 15626 | 18344 | Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って |
| 15627 | 18345 | 調べられます: |
| 15628 | 18346 | |
| 15629 | 18347 | use Config; |
| 15630 | 18348 | if ($Config{use64bitint} eq "define" |
| 15631 | 18349 | || $Config{longsize} >= 8) { |
| 15632 | 18350 | print "Nice quads!\n"; |
| 15633 | 18351 | } |
| 15634 | 18352 | |
| 15635 | 18353 | =begin original |
| 15636 | 18354 | |
| 15637 | 18355 | For floating-point conversions (C<e f g E F G>), numbers are usually assumed |
| 15638 | 18356 | to be the default floating-point size on your platform (double or long double), |
| 15639 | 18357 | but you can force "long double" with C<q>, C<L>, or C<ll> if your |
| 15640 | 18358 | platform supports them. You can find out whether your Perl supports long |
| 15641 | 18359 | doubles via L<Config>: |
| 15642 | 18360 | |
| 15643 | 18361 | =end original |
| 15644 | 18362 | |
| 15645 | 18363 | 浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの |
| 15646 | 不動小数点数のサイズ (double か long double) を仮定します | |
| 18364 | 不動小数点数のサイズ (double か long double) を仮定しますが、 | |
| 18365 | プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して | |
| 18366 | "long double" を強制できます。 | |
| 15647 | 18367 | Perl が long double に対応しているかどうかは L<Config> を使って |
| 15648 | 18368 | 調べられます: |
| 15649 | 18369 | |
| 15650 | 18370 | use Config; |
| 15651 | 18371 | print "long doubles\n" if $Config{d_longdbl} eq "define"; |
| 15652 | 18372 | |
| 15653 | 18373 | =begin original |
| 15654 | 18374 | |
| 15655 | 18375 | You can find out whether Perl considers "long double" to be the default |
| 15656 | 18376 | floating-point size to use on your platform via L<Config>: |
| 15657 | 18377 | |
| 15658 | 18378 | =end original |
| 15659 | 18379 | |
| 15660 | 18380 | Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは |
| 15661 | 18381 | L<Config> を使って調べられます: |
| 15662 | 18382 | |
| 15663 | 18383 | use Config; |
| 15664 | 18384 | if ($Config{uselongdouble} eq "define") { |
| 15665 | 18385 | print "long doubles by default\n"; |
| 15666 | 18386 | } |
| 15667 | 18387 | |
| 15668 | 18388 | =begin original |
| 15669 | 18389 | |
| 15670 | 18390 | It can also be that long doubles and doubles are the same thing: |
| 15671 | 18391 | |
| 15672 | 18392 | =end original |
| 15673 | 18393 | |
| 15674 | 18394 | long double と double が同じ場合もあります: |
| 15675 | 18395 | |
| 15676 | 18396 | use Config; |
| 15677 | 18397 | ($Config{doublesize} == $Config{longdblsize}) && |
| 15678 | 18398 | print "doubles are long doubles\n"; |
| 15679 | 18399 | |
| 15680 | 18400 | =begin original |
| 15681 | 18401 | |
| 15682 | 18402 | The size specifier C<V> has no effect for Perl code, but is supported for |
| 15683 | 18403 | compatibility with XS code. It means "use the standard size for a Perl |
| 15684 | 18404 | integer or floating-point number", which is the default. |
| 15685 | 18405 | |
| 15686 | 18406 | =end original |
| 15687 | 18407 | |
| 15688 | 18408 | サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは |
| 15689 | 18409 | XS コードとの互換性のために対応しています。 |
| 15690 | 18410 | これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを |
| 15691 | 18411 | 意味し、これはデフォルトです。 |
| 15692 | 18412 | |
| 15693 | 18413 | =item order of arguments |
| 15694 | 18414 | |
| 15695 | 18415 | (引数の順序) |
| 15696 | 18416 | |
| 15697 | 18417 | =begin original |
| 15698 | 18418 | |
| 15699 | Normally, sprintf | |
| 18419 | Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused | |
| 18420 | argument as the value to | |
| 15700 | 18421 | format for each format specification. If the format specification |
| 15701 | 18422 | uses C<*> to require additional arguments, these are consumed from |
| 15702 | 18423 | the argument list in the order they appear in the format |
| 15703 | 18424 | specification I<before> the value to format. Where an argument is |
| 15704 | 18425 | specified by an explicit index, this does not affect the normal |
| 15705 | 18426 | order for the arguments, even when the explicitly specified index |
| 15706 | 18427 | would have been the next argument. |
| 15707 | 18428 | |
| 15708 | 18429 | =end original |
| 15709 | 18430 | |
| 15710 | 通常、sprintf | |
| 18431 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、 | |
| 18432 | 使われていない次の引数を | |
| 15711 | 18433 | フォーマットする値として使います。 |
| 15712 | 18434 | 追加の引数を要求するためにフォーマット指定 C<*> を使うと、 |
| 15713 | 18435 | これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に |
| 15714 | 18436 | 引数リストから消費されます。 |
| 15715 | 18437 | 引数の位置が明示的なインデックスを使って指定された場合、 |
| 15716 | 18438 | (明示的に指定したインデックスが次の引数の場合でも) |
| 15717 | 18439 | これは通常の引数の順番に影響を与えません。 |
| 15718 | 18440 | |
| 15719 | 18441 | =begin original |
| 15720 | 18442 | |
| 15721 | 18443 | So: |
| 15722 | 18444 | |
| 15723 | 18445 | =end original |
| 15724 | 18446 | |
| 15725 | 18447 | それで: |
| 15726 | 18448 | |
| 15727 | 18449 | printf "<%*.*s>", $a, $b, $c; |
| 15728 | 18450 | |
| 15729 | 18451 | =begin original |
| 15730 | 18452 | |
| 15731 | 18453 | uses C<$a> for the width, C<$b> for the precision, and C<$c> |
| 15732 | 18454 | as the value to format; while: |
| 15733 | 18455 | |
| 15734 | 18456 | =end original |
| 15735 | 18457 | |
| 15736 | 18458 | とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に |
| 15737 | 18459 | 使います; 一方: |
| 15738 | 18460 | |
| 15739 | 18461 | printf '<%*1$.*s>', $a, $b; |
| 15740 | 18462 | |
| 15741 | 18463 | =begin original |
| 15742 | 18464 | |
| 15743 | 18465 | would use C<$a> for the width and precision, and C<$b> as the |
| 15744 | 18466 | value to format. |
| 15745 | 18467 | |
| 15746 | 18468 | =end original |
| 15747 | 18469 | |
| 15748 | 18470 | とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。 |
| 15749 | 18471 | |
| 15750 | 18472 | =begin original |
| 15751 | 18473 | |
| 15752 | 18474 | Here are some more examples; be aware that when using an explicit |
| 15753 | 18475 | index, the C<$> may need escaping: |
| 15754 | 18476 | |
| 15755 | 18477 | =end original |
| 15756 | 18478 | |
| 15757 | 18479 | 以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は |
| 15758 | 18480 | エスケープする必要があることに注意してください: |
| 15759 | 18481 | |
| 15760 | | |
| 18482 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" | |
| 15761 | | |
| 18483 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" | |
| 15762 | | |
| 18484 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" | |
| 15763 | | |
| 18485 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" | |
| 18486 | printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n" | |
| 15764 | 18487 | |
| 15765 | 18488 | =back |
| 15766 | 18489 | |
| 15767 | 18490 | =begin original |
| 15768 | 18491 | |
| 15769 | If C<use locale> (including C<use locale 'not_characters'>) | |
| 18492 | If L<C<use locale>|locale> (including C<use locale ':not_characters'>) | |
| 15770 | and POSIX::setlocale | |
| 18493 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been | |
| 18494 | called, | |
| 15771 | 18495 | the character used for the decimal separator in formatted floating-point |
| 15772 | numbers is affected by the LC_NUMERIC locale. See L<perllocale> | |
| 18496 | numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale> | |
| 15773 | 18497 | and L<POSIX>. |
| 15774 | 18498 | |
| 15775 | 18499 | =end original |
| 15776 | 18500 | |
| 15777 | (C<use locale 'not_characters'> を含む)C<use locale> が有効で、 | |
| 18501 | (C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、 | |
| 15778 | POSIX::setlocale | |
| 18502 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、 | |
| 15779 | 小数点として使われる文字は | |
| 18503 | フォーマットされた浮動小数点数の小数点として使われる文字は | |
| 18504 | C<LC_NUMERIC> ロケールの影響を受けます。 | |
| 15780 | 18505 | L<perllocale> と L<POSIX> を参照してください。 |
| 15781 | 18506 | |
| 15782 | 18507 | =item sqrt EXPR |
| 15783 | 18508 | X<sqrt> X<root> X<square root> |
| 15784 | 18509 | |
| 15785 | 18510 | =item sqrt |
| 15786 | 18511 | |
| 15787 | 18512 | =for Pod::Functions square root function |
| 15788 | 18513 | |
| 15789 | 18514 | =begin original |
| 15790 | 18515 | |
| 15791 | 18516 | Return the positive square root of EXPR. If EXPR is omitted, uses |
| 15792 | C<$_>. Works only for non-negative operands unless you've | |
| 18517 | L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've | |
| 15793 | loaded the C<Math::Complex> module. | |
| 18518 | loaded the L<C<Math::Complex>|Math::Complex> module. | |
| 15794 | 18519 | |
| 15795 | 18520 | =end original |
| 15796 | 18521 | |
| 15797 | 18522 | EXPR の正の平方根を返します。 |
| 15798 | EXPR が省略されると、C<$_> を使います。 | |
| 18523 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 15799 | C<Math::Complex> モジュールを使わない場合は、負の数の引数は | |
| 18524 | L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は | |
| 18525 | 扱えません。 | |
| 15800 | 18526 | |
| 15801 | 18527 | use Math::Complex; |
| 15802 | 18528 | print sqrt(-4); # prints 2i |
| 15803 | 18529 | |
| 15804 | 18530 | =item srand EXPR |
| 15805 | 18531 | X<srand> X<seed> X<randseed> |
| 15806 | 18532 | |
| 15807 | 18533 | =item srand |
| 15808 | 18534 | |
| 15809 | 18535 | =for Pod::Functions seed the random number generator |
| 15810 | 18536 | |
| 15811 | 18537 | =begin original |
| 15812 | 18538 | |
| 15813 | Sets and returns the random number seed for the C<rand> | |
| 18539 | Sets and returns the random number seed for the L<C<rand>|/rand EXPR> | |
| 18540 | operator. | |
| 15814 | 18541 | |
| 15815 | 18542 | =end original |
| 15816 | 18543 | |
| 15817 | C<rand> 演算子のためのシード値を設定して返します。 | |
| 18544 | L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。 | |
| 15818 | 18545 | |
| 15819 | 18546 | =begin original |
| 15820 | 18547 | |
| 15821 | The point of the function is to "seed" the C<rand> | |
| 18548 | The point of the function is to "seed" the L<C<rand>|/rand EXPR> | |
| 15822 | can produce a different sequence | |
| 18549 | function so that L<C<rand>|/rand EXPR> can produce a different sequence | |
| 15823 | ||
| 18550 | each time you run your program. When called with a parameter, | |
| 15824 | ||
| 18551 | L<C<srand>|/srand EXPR> uses that for the seed; otherwise it | |
| 18552 | (semi-)randomly chooses a seed (see below). In either case, starting with Perl 5.14, | |
| 15825 | 18553 | it returns the seed. To signal that your code will work I<only> on Perls |
| 15826 | 18554 | of a recent vintage: |
| 15827 | 18555 | |
| 15828 | 18556 | =end original |
| 15829 | 18557 | |
| 15830 | この関数のポイントは、プログラムを実行するごとに C<rand> 関数が | |
| 18558 | この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が | |
| 15831 | 異なる乱数列を生成できるように C<rand> 関数の「種」を | |
| 18559 | 異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を | |
| 15832 | ||
| 18560 | 設定することです。 | |
| 15833 | ||
| 18561 | L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います; | |
| 18562 | さもなければ(だいたい)ランダムに種を選びます(後述)。 | |
| 15834 | 18563 | どちらの場合でも、Perl 5.14 からは種を返します。 |
| 15835 | 18564 | 特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします: |
| 15836 | 18565 | |
| 15837 | use 5. | |
| 18566 | use v5.14; # so srand returns the seed | |
| 15838 | 18567 | |
| 15839 | 18568 | =begin original |
| 15840 | 18569 | |
| 15841 | If C<srand | |
| 18570 | If L<C<srand>|/srand EXPR> is not called explicitly, it is called | |
| 15842 | parameter at the first use of the | |
| 18571 | implicitly without a parameter at the first use of the | |
| 15843 | However, there are a few situations | |
| 18572 | L<C<rand>|/rand EXPR> operator. However, there are a few situations | |
| 15844 | want to call C<srand> | |
| 18573 | where programs are likely to want to call L<C<srand>|/srand EXPR>. One | |
| 15845 | ||
| 18574 | is for generating predictable results, generally for testing or | |
| 15846 | e | |
| 18575 | debugging. There, you use C<srand($seed)>, with the same C<$seed> each | |
| 15847 | ||
| 18576 | time. Another case is that you may want to call L<C<srand>|/srand EXPR> | |
| 15848 | ||
| 18577 | after a L<C<fork>|/fork> to avoid child processes sharing the same seed | |
| 18578 | value as the parent (and consequently each other). | |
| 15849 | 18579 | |
| 15850 | 18580 | =end original |
| 15851 | 18581 | |
| 15852 | C<srand | |
| 18582 | L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に | |
| 15853 | 時点で暗黙に引数なしで呼び出されます。 | |
| 18583 | L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。 | |
| 15854 | しかし、最近の Perl でプログラムが C<srand> を | |
| 18584 | しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を | |
| 15855 | いくつかあります。 | |
| 18585 | 呼び出したいであろう状況がいくつかあります。 | |
| 15856 | 18586 | 一つはテストやデバッグのために予測可能な結果を生成するためです。 |
| 15857 | 18587 | この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。 |
| 15858 | 18588 | もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を |
| 15859 | 共有することを避けるために、C<fork | |
| 18589 | 共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を | |
| 15860 | 18590 | 呼び出したいかもしれません。 |
| 15861 | 18591 | |
| 15862 | 18592 | =begin original |
| 15863 | 18593 | |
| 15864 | 18594 | Do B<not> call C<srand()> (i.e., without an argument) more than once per |
| 15865 | 18595 | process. The internal state of the random number generator should |
| 15866 | 18596 | contain more entropy than can be provided by any seed, so calling |
| 15867 | C<srand | |
| 18597 | L<C<srand>|/srand EXPR> again actually I<loses> randomness. | |
| 15868 | 18598 | |
| 15869 | 18599 | =end original |
| 15870 | 18600 | |
| 15871 | C<srand | |
| 18601 | L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回 | |
| 18602 | 呼び出しては B<いけません>。 | |
| 15872 | 18603 | 乱数生成器の内部状態はどのような種によって提供されるものよりも |
| 15873 | 18604 | 高いエントロピーを持っているので、C<srand()> を再び呼び出すと |
| 15874 | 18605 | ランダム性が I<失われます>。 |
| 15875 | 18606 | |
| 15876 | 18607 | =begin original |
| 15877 | 18608 | |
| 15878 | Most implementations of C<srand> take an integer and will | |
| 18609 | Most implementations of L<C<srand>|/srand EXPR> take an integer and will | |
| 18610 | silently | |
| 15879 | 18611 | truncate decimal numbers. This means C<srand(42)> will usually |
| 15880 | 18612 | produce the same results as C<srand(42.1)>. To be safe, always pass |
| 15881 | C<srand> an integer. | |
| 18613 | L<C<srand>|/srand EXPR> an integer. | |
| 15882 | 18614 | |
| 15883 | 18615 | =end original |
| 15884 | 18616 | |
| 15885 | C<srand> のほとんどの実装では整数を取り、小数を暗黙に | |
| 18617 | L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に | |
| 15886 | ||
| 18618 | 切り捨てます。 | |
| 15887 | 意味します。 | |
| 18619 | これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。 | |
| 15888 | 安全のために、C<srand> には常に整数を渡しましょう。 | |
| 18620 | 安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。 | |
| 15889 | 18621 | |
| 15890 | 18622 | =begin original |
| 15891 | 18623 | |
| 15892 | 18624 | A typical use of the returned seed is for a test program which has too many |
| 15893 | 18625 | combinations to test comprehensively in the time available to it each run. It |
| 15894 | 18626 | can test a random subset each time, and should there be a failure, log the seed |
| 15895 | 18627 | used for that run so that it can later be used to reproduce the same results. |
| 15896 | 18628 | |
| 15897 | 18629 | =end original |
| 15898 | 18630 | |
| 15899 | 18631 | 返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に |
| 15900 | 18632 | 行うには組み合わせが多すぎるテストプログラム用です。 |
| 15901 | 18633 | 毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った |
| 15902 | 18634 | 種をログに出力することで、後で同じ結果を再現するために使えます。 |
| 15903 | 18635 | |
| 15904 | 18636 | =begin original |
| 15905 | 18637 | |
| 15906 | ||
| 18638 | If the C<PERL_RAND_SEED> environment variable is set to a non-negative | |
| 18639 | integer during process startup then calls to C<srand()> with no | |
| 18640 | arguments will initialize the perl random number generator with a | |
| 18641 | consistent seed each time it is called, whether called explicitly with | |
| 18642 | no arguments or implicitly via use of C<rand()>. The exact seeding that | |
| 18643 | a given C<PERL_RAND_SEED> will produce is deliberately unspecified, but | |
| 18644 | using different values for C<PERL_RAND_SEED> should produce different | |
| 18645 | results. This is intended for debugging and performance analysis and is | |
| 18646 | only guaranteed to produce consistent results between invocations of the | |
| 18647 | same perl executable running the same code when all other factors are | |
| 18648 | equal. The environment variable is read only once during process | |
| 18649 | startup, and changing it during the program flow will not affect the | |
| 18650 | currently running process. See L<perlrun> for more details. | |
| 18651 | ||
| 18652 | =end original | |
| 18653 | ||
| 18654 | If the C<PERL_RAND_SEED> environment variable is set to a non-negative | |
| 18655 | integer during process startup then calls to C<srand()> with no | |
| 18656 | arguments will initialize the perl random number generator with a | |
| 18657 | consistent seed each time it is called, whether called explicitly with | |
| 18658 | no arguments or implicitly via use of C<rand()>. The exact seeding that | |
| 18659 | a given C<PERL_RAND_SEED> will produce is deliberately unspecified, but | |
| 18660 | using different values for C<PERL_RAND_SEED> should produce different | |
| 18661 | results. This is intended for debugging and performance analysis and is | |
| 18662 | only guaranteed to produce consistent results between invocations of the | |
| 18663 | same perl executable running the same code when all other factors are | |
| 18664 | equal. The environment variable is read only once during process | |
| 18665 | startup, and changing it during the program flow will not affect the | |
| 18666 | currently running process. See L<perlrun> for more details. | |
| 18667 | (TBT) | |
| 18668 | ||
| 18669 | =begin original | |
| 18670 | ||
| 18671 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
| 15907 | 18672 | on it in security-sensitive situations.> As of this writing, a |
| 15908 | 18673 | number of third-party CPAN modules offer random number generators |
| 15909 | 18674 | intended by their authors to be cryptographically secure, |
| 15910 | 18675 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
| 15911 | 18676 | and L<Math::TrulyRandom>. |
| 15912 | 18677 | |
| 15913 | 18678 | =end original |
| 15914 | 18679 | |
| 15915 | B<C<rand | |
| 18680 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
| 15916 | 18681 | セキュリティ的に重要な状況でこれに頼るべきではありません。> |
| 15917 | 18682 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが |
| 15918 | 18683 | 作者によって暗号学的に安全であることを目的とした乱数生成器を |
| 15919 | 18684 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, |
| 15920 | 18685 | L<Math::TrulyRandom> などです。 |
| 15921 | 18686 | |
| 15922 | 18687 | =item stat FILEHANDLE |
| 15923 | 18688 | X<stat> X<file, status> X<ctime> |
| 15924 | 18689 | |
| 15925 | 18690 | =item stat EXPR |
| 15926 | 18691 | |
| 15927 | 18692 | =item stat DIRHANDLE |
| 15928 | 18693 | |
| 15929 | 18694 | =item stat |
| 15930 | 18695 | |
| 15931 | 18696 | =for Pod::Functions get a file's status information |
| 15932 | 18697 | |
| 15933 | 18698 | =begin original |
| 15934 | 18699 | |
| 15935 | 18700 | Returns a 13-element list giving the status info for a file, either |
| 15936 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is | |
| 18701 | the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is | |
| 15937 | omitted, it stats C<$_> (not C<_>!). Returns the empt | |
| 18702 | omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty | |
| 18703 | list if L<C<stat>|/stat FILEHANDLE> fails. Typically | |
| 15938 | 18704 | used as follows: |
| 15939 | 18705 | |
| 15940 | 18706 | =end original |
| 15941 | 18707 | |
| 15942 | 18708 | FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、 |
| 15943 | 18709 | EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。 |
| 15944 | EXPR が省略されると、 C<$_> が用いられます | |
| 18710 | EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます | |
| 15945 | C< | |
| 18711 | (C<_> ではありません!)。 | |
| 18712 | L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。 | |
| 15946 | 18713 | 普通は、以下のようにして使います: |
| 15947 | 18714 | |
| 15948 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
| 18715 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
| 15949 | $atime,$mtime,$ctime,$blksize,$blocks) | |
| 18716 | $atime,$mtime,$ctime,$blksize,$blocks) | |
| 15950 | 18717 | = stat($filename); |
| 15951 | 18718 | |
| 15952 | 18719 | =begin original |
| 15953 | 18720 | |
| 15954 | 18721 | Not all fields are supported on all filesystem types. Here are the |
| 15955 | 18722 | meanings of the fields: |
| 15956 | 18723 | |
| 15957 | 18724 | =end original |
| 15958 | 18725 | |
| 15959 | 18726 | 全てのファイルシステムで全てのフィールドに対応しているわけではありません。 |
| 15960 | 18727 | フィールドの意味は以下の通りです。 |
| 15961 | 18728 | |
| 15962 | 18729 | =begin original |
| 15963 | 18730 | |
| 15964 | 18731 | 0 dev device number of filesystem |
| 15965 | 18732 | 1 ino inode number |
| 15966 | 18733 | 2 mode file mode (type and permissions) |
| 15967 | 18734 | 3 nlink number of (hard) links to the file |
| 15968 | 18735 | 4 uid numeric user ID of file's owner |
| 15969 | 18736 | 5 gid numeric group ID of file's owner |
| 15970 | 18737 | 6 rdev the device identifier (special files only) |
| 15971 | 18738 | 7 size total size of file, in bytes |
| 15972 | 18739 | 8 atime last access time in seconds since the epoch |
| 15973 | 18740 | 9 mtime last modify time in seconds since the epoch |
| 15974 | 18741 | 10 ctime inode change time in seconds since the epoch (*) |
| 15975 | 18742 | 11 blksize preferred I/O size in bytes for interacting with the |
| 15976 | 18743 | file (may vary from file to file) |
| 15977 | 18744 | 12 blocks actual number of system-specific blocks allocated |
| 15978 | 18745 | on disk (often, but not always, 512 bytes each) |
| 15979 | 18746 | |
| 15980 | 18747 | =end original |
| 15981 | 18748 | |
| 15982 | 18749 | 0 dev ファイルシステムのデバイス番号 |
| 15983 | 18750 | 1 ino inode 番号 |
| 15984 | 18751 | 2 mode ファイルモード (タイプとパーミッション) |
| 15985 | 18752 | 3 nlink ファイルへの(ハード)リンクの数 |
| 15986 | 18753 | 4 uid ファイル所有者のユーザー ID の数値 |
| 15987 | 18754 | 5 gid ファイル所有者のグループ ID の数値 |
| 15988 | 18755 | 6 rdev デバイス識別子(特殊ファイルのみ) |
| 15989 | 18756 | 7 size ファイルサイズ(バイト単位) |
| 15990 | 18757 | 8 atime 紀元から、最後にアクセスされた時刻までの秒数 |
| 15991 | 18758 | 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数 |
| 15992 | 18759 | 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*) |
| 15993 | 18760 | 11 blksize ファイルとの相互作用のために適した I/O バイト数 |
| 15994 | 18761 | (ファイルごとに異なるかもしれない) |
| 15995 | 18762 | 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは |
| 15996 | 18763 | ありませんがたいていはそれぞれ 512 バイト)の数 |
| 15997 | 18764 | |
| 15998 | 18765 | =begin original |
| 15999 | 18766 | |
| 16000 | 18767 | (The epoch was at 00:00 January 1, 1970 GMT.) |
| 16001 | 18768 | |
| 16002 | 18769 | =end original |
| 16003 | 18770 | |
| 16004 | 18771 | (紀元は GMT で 1970/01/01 00:00:00。) |
| 16005 | 18772 | |
| 16006 | 18773 | =begin original |
| 16007 | 18774 | |
| 16008 | 18775 | (*) Not all fields are supported on all filesystem types. Notably, the |
| 16009 | 18776 | ctime field is non-portable. In particular, you cannot expect it to be a |
| 16010 | 18777 | "creation time"; see L<perlport/"Files and Filesystems"> for details. |
| 16011 | 18778 | |
| 16012 | 18779 | =end original |
| 16013 | 18780 | |
| 16014 | 18781 | (*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは |
| 16015 | 18782 | ありません。 |
| 16016 | 18783 | 明らかに、ctime のフィールドは移植性がありません。 |
| 16017 | 18784 | 特に、これから「作成時刻」を想定することは出来ません; |
| 16018 | 18785 | 詳細については L<perlport/"Files and Filesystems"> を参照してください。 |
| 16019 | 18786 | |
| 16020 | 18787 | =begin original |
| 16021 | 18788 | |
| 16022 | If C<stat> is passed the special filehandle | |
| 18789 | If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle | |
| 16023 | stat is done, but the current contents of | |
| 18790 | consisting of an underline, no stat is done, but the current contents of | |
| 16024 | ||
| 18791 | the stat structure from the last L<C<stat>|/stat FILEHANDLE>, | |
| 18792 | L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example: | |
| 16025 | 18793 | |
| 16026 | 18794 | =end original |
| 16027 | 18795 | |
| 16028 | 下線だけの _ という特別なファイルハンドルを C<stat> に | |
| 18796 | 下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に | |
| 16029 | 実際には stat を行なわず、stat 構造体に残っている | |
| 18797 | 渡すと、実際には stat を行なわず、stat 構造体に残っている | |
| 16030 | 前回の stat や | |
| 18798 | 前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や | |
| 18799 | ファイルテストの情報が返されます。 | |
| 16031 | 18800 | 例: |
| 16032 | 18801 | |
| 16033 | 18802 | if (-x $file && (($d) = stat(_)) && $d < 0) { |
| 16034 | 18803 | print "$file is executable NFS file\n"; |
| 16035 | 18804 | } |
| 16036 | 18805 | |
| 16037 | 18806 | =begin original |
| 16038 | 18807 | |
| 16039 | 18808 | (This works on machines only for which the device number is negative |
| 16040 | 18809 | under NFS.) |
| 16041 | 18810 | |
| 16042 | 18811 | =end original |
| 16043 | 18812 | |
| 16044 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
| 18813 | (これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。) | |
| 16045 | のみ動作します。) | |
| 16046 | 18814 | |
| 16047 | 18815 | =begin original |
| 16048 | 18816 | |
| 18817 | On some platforms inode numbers are of a type larger than perl knows how | |
| 18818 | to handle as integer numerical values. If necessary, an inode number will | |
| 18819 | be returned as a decimal string in order to preserve the entire value. | |
| 18820 | If used in a numeric context, this will be converted to a floating-point | |
| 18821 | numerical value, with rounding, a fate that is best avoided. Therefore, | |
| 18822 | you should prefer to compare inode numbers using C<eq> rather than C<==>. | |
| 18823 | C<eq> will work fine on inode numbers that are represented numerically, | |
| 18824 | as well as those represented as strings. | |
| 18825 | ||
| 18826 | =end original | |
| 18827 | ||
| 18828 | 一部のプラットフォームでは、inode 番号は perl が整数値として | |
| 18829 | 扱い方を知っているものよりも大きい型になっています。 | |
| 18830 | もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として | |
| 18831 | 返されます。 | |
| 18832 | 数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、 | |
| 18833 | できるだけ避けるべき結果になります。 | |
| 18834 | 従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。 | |
| 18835 | C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても | |
| 18836 | うまく動作します。 | |
| 18837 | ||
| 18838 | =begin original | |
| 18839 | ||
| 16049 | 18840 | Because the mode contains both the file type and its permissions, you |
| 16050 | 18841 | should mask off the file type portion and (s)printf using a C<"%o"> |
| 16051 | 18842 | if you want to see the real permissions. |
| 16052 | 18843 | |
| 16053 | 18844 | =end original |
| 16054 | 18845 | |
| 16055 | 18846 | モードにはファイルタイプとその権限の両方が含まれているので、 |
| 16056 | 18847 | 本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで |
| 16057 | 18848 | ファイルタイプをマスクするべきです。 |
| 16058 | 18849 | |
| 16059 | $mode = (stat($filename))[2]; | |
| 18850 | my $mode = (stat($filename))[2]; | |
| 16060 | 18851 | printf "Permissions are %04o\n", $mode & 07777; |
| 16061 | 18852 | |
| 16062 | 18853 | =begin original |
| 16063 | 18854 | |
| 16064 | In scalar context, C<stat> returns a boolean value | |
| 18855 | In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value | |
| 18856 | indicating success | |
| 16065 | 18857 | or failure, and, if successful, sets the information associated with |
| 16066 | 18858 | the special filehandle C<_>. |
| 16067 | 18859 | |
| 16068 | 18860 | =end original |
| 16069 | 18861 | |
| 16070 | スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を | |
| 18862 | スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を | |
| 16071 | 成功した場合は、特別なファイルハンドル C<_> に結び付けられた | |
| 18863 | 返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた | |
| 16072 | 18864 | 情報をセットします。 |
| 16073 | 18865 | |
| 16074 | 18866 | =begin original |
| 16075 | 18867 | |
| 16076 | 18868 | The L<File::stat> module provides a convenient, by-name access mechanism: |
| 16077 | 18869 | |
| 16078 | 18870 | =end original |
| 16079 | 18871 | |
| 16080 | 18872 | L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。 |
| 16081 | 18873 | |
| 16082 | 18874 | use File::stat; |
| 16083 | $sb = stat($filename); | |
| 18875 | my $sb = stat($filename); | |
| 16084 | 18876 | printf "File is %s, size is %s, perm %04o, mtime %s\n", |
| 16085 | 18877 | $filename, $sb->size, $sb->mode & 07777, |
| 16086 | 18878 | scalar localtime $sb->mtime; |
| 16087 | 18879 | |
| 16088 | 18880 | =begin original |
| 16089 | 18881 | |
| 16090 | 18882 | You can import symbolic mode constants (C<S_IF*>) and functions |
| 16091 | (C<S_IS*>) from the Fcntl module: | |
| 18883 | (C<S_IS*>) from the L<Fcntl> module: | |
| 16092 | 18884 | |
| 16093 | 18885 | =end original |
| 16094 | 18886 | |
| 16095 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから | |
| 18887 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから | |
| 16096 | 18888 | インポートできます。 |
| 16097 | 18889 | |
| 16098 | 18890 | use Fcntl ':mode'; |
| 16099 | 18891 | |
| 16100 | $mode = (stat($filename))[2]; | |
| 18892 | my $mode = (stat($filename))[2]; | |
| 16101 | 18893 | |
| 16102 | $user_rwx = ($mode & S_IRWXU) >> 6; | |
| 18894 | my $user_rwx = ($mode & S_IRWXU) >> 6; | |
| 16103 | $group_read = ($mode & S_IRGRP) >> 3; | |
| 18895 | my $group_read = ($mode & S_IRGRP) >> 3; | |
| 16104 | $other_execute = $mode & S_IXOTH; | |
| 18896 | my $other_execute = $mode & S_IXOTH; | |
| 16105 | 18897 | |
| 16106 | 18898 | printf "Permissions are %04o\n", S_IMODE($mode), "\n"; |
| 16107 | 18899 | |
| 16108 | $is_setuid = $mode & S_ISUID; | |
| 18900 | my $is_setuid = $mode & S_ISUID; | |
| 16109 | $is_directory = S_ISDIR($mode); | |
| 18901 | my $is_directory = S_ISDIR($mode); | |
| 16110 | 18902 | |
| 16111 | 18903 | =begin original |
| 16112 | 18904 | |
| 16113 | 18905 | You could write the last two using the C<-u> and C<-d> operators. |
| 16114 | 18906 | Commonly available C<S_IF*> constants are: |
| 16115 | 18907 | |
| 16116 | 18908 | =end original |
| 16117 | 18909 | |
| 16118 | 18910 | 最後の二つは C<-u> と C<-d> 演算子を使っても書けます。 |
| 16119 | 18911 | 一般に利用可能な C<S_IF*> 定数は以下のものです。 |
| 16120 | 18912 | |
| 16121 | 18913 | # Permissions: read, write, execute, for user, group, others. |
| 16122 | 18914 | |
| 16123 | 18915 | S_IRWXU S_IRUSR S_IWUSR S_IXUSR |
| 16124 | 18916 | S_IRWXG S_IRGRP S_IWGRP S_IXGRP |
| 16125 | 18917 | S_IRWXO S_IROTH S_IWOTH S_IXOTH |
| 16126 | 18918 | |
| 16127 | 18919 | # Setuid/Setgid/Stickiness/SaveText. |
| 16128 | 18920 | # Note that the exact meaning of these is system-dependent. |
| 16129 | 18921 | |
| 16130 | 18922 | S_ISUID S_ISGID S_ISVTX S_ISTXT |
| 16131 | 18923 | |
| 16132 | 18924 | # File types. Not all are necessarily available on |
| 16133 | 18925 | # your system. |
| 16134 | 18926 | |
| 16135 | 18927 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR |
| 16136 | 18928 | S_IFIFO S_IFSOCK S_IFWHT S_ENFMT |
| 16137 | 18929 | |
| 16138 | 18930 | # The following are compatibility aliases for S_IRUSR, |
| 16139 | 18931 | # S_IWUSR, and S_IXUSR. |
| 16140 | 18932 | |
| 16141 | 18933 | S_IREAD S_IWRITE S_IEXEC |
| 16142 | 18934 | |
| 16143 | 18935 | =begin original |
| 16144 | 18936 | |
| 16145 | 18937 | and the C<S_IF*> functions are |
| 16146 | 18938 | |
| 16147 | 18939 | =end original |
| 16148 | 18940 | |
| 16149 | 18941 | 一般に利用可能な C<S_IF*> 関数は以下のものです。 |
| 16150 | 18942 | |
| 16151 | 18943 | S_IMODE($mode) the part of $mode containing the permission |
| 16152 | 18944 | bits and the setuid/setgid/sticky bits |
| 16153 | 18945 | |
| 16154 | 18946 | S_IFMT($mode) the part of $mode containing the file type |
| 16155 | 18947 | which can be bit-anded with (for example) |
| 16156 | 18948 | S_IFREG or with the following functions |
| 16157 | 18949 | |
| 16158 | 18950 | # The operators -f, -d, -l, -b, -c, -p, and -S. |
| 16159 | 18951 | |
| 16160 | 18952 | S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) |
| 16161 | 18953 | S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) |
| 16162 | 18954 | |
| 16163 | 18955 | # No direct -X operator counterpart, but for the first one |
| 16164 | 18956 | # the -g operator is often equivalent. The ENFMT stands for |
| 16165 | 18957 | # record flocking enforcement, a platform-dependent feature. |
| 16166 | 18958 | |
| 16167 | 18959 | S_ISENFMT($mode) S_ISWHT($mode) |
| 16168 | 18960 | |
| 16169 | 18961 | =begin original |
| 16170 | 18962 | |
| 16171 | See your native chmod(2) and stat(2) documentation for more details | |
| 18963 | See your native L<chmod(2)> and L<stat(2)> documentation for more details | |
| 16172 | 18964 | about the C<S_*> constants. To get status info for a symbolic link |
| 16173 | instead of the target file behind the link, use the | |
| 18965 | instead of the target file behind the link, use the | |
| 18966 | L<C<lstat>|/lstat FILEHANDLE> function. | |
| 16174 | 18967 | |
| 16175 | 18968 | =end original |
| 16176 | 18969 | |
| 16177 | C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の | |
| 18970 | C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)> と L<stat(2)> の | |
| 16178 | 18971 | ドキュメントを参照してください。 |
| 16179 | 18972 | リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を |
| 16180 | 得たい場合は、C<lstat> 関数を使ってください。 | |
| 18973 | 得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。 | |
| 16181 | 18974 | |
| 16182 | 18975 | =begin original |
| 16183 | 18976 | |
| 16184 | 18977 | Portability issues: L<perlport/stat>. |
| 16185 | 18978 | |
| 16186 | 18979 | =end original |
| 16187 | 18980 | |
| 16188 | 18981 | 移植性の問題: L<perlport/stat>。 |
| 16189 | 18982 | |
| 16190 | =item state | |
| 18983 | =item state VARLIST | |
| 16191 | 18984 | X<state> |
| 16192 | 18985 | |
| 16193 | =item state TYPE | |
| 18986 | =item state TYPE VARLIST | |
| 16194 | 18987 | |
| 16195 | =item state | |
| 18988 | =item state VARLIST : ATTRS | |
| 16196 | 18989 | |
| 16197 | =item state TYPE | |
| 18990 | =item state TYPE VARLIST : ATTRS | |
| 16198 | 18991 | |
| 16199 | 18992 | =for Pod::Functions +state declare and assign a persistent lexical variable |
| 16200 | 18993 | |
| 16201 | 18994 | =begin original |
| 16202 | 18995 | |
| 16203 | C<state> declares a lexically scoped variable, just | |
| 18996 | L<C<state>|/state VARLIST> declares a lexically scoped variable, just | |
| 18997 | like L<C<my>|/my VARLIST>. | |
| 16204 | 18998 | However, those variables will never be reinitialized, contrary to |
| 16205 | 18999 | lexical variables that are reinitialized each time their enclosing block |
| 16206 | 19000 | is entered. |
| 16207 | 19001 | See L<perlsub/"Persistent Private Variables"> for details. |
| 16208 | 19002 | |
| 16209 | 19003 | =end original |
| 16210 | 19004 | |
| 16211 | C<state> はちょうど C<my> と同様に、 | |
| 19005 | L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、 | |
| 19006 | レキシカルなスコープの変数を宣言します。 | |
| 16212 | 19007 | しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、 |
| 16213 | 19008 | この変数は決して再初期化されません。 |
| 16214 | 19009 | 詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。 |
| 16215 | 19010 | |
| 16216 | 19011 | =begin original |
| 16217 | 19012 | |
| 16218 | ||
| 19013 | If more than one variable is listed, the list must be placed in | |
| 16219 | ||
| 19014 | parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be | |
| 16220 | ||
| 19015 | used as a | |
| 19016 | dummy placeholder. However, since initialization of state variables in | |
| 19017 | such lists is currently not possible this would serve no purpose. | |
| 16221 | 19018 | |
| 16222 | 19019 | =end original |
| 16223 | 19020 | |
| 16224 | ||
| 19021 | 複数の変数を指定する場合は、リストはかっこで囲まなければなりません。 | |
| 16225 | C< | |
| 19022 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの | |
| 16226 | ||
| 19023 | プレースホルダとして使えます。 | |
| 19024 | しかし、そのようなリストでの state 変数の初期化は現在のところできないので、 | |
| 19025 | これは無意味です。 | |
| 16227 | 19026 | |
| 16228 | =item study SCALAR | |
| 16229 | X<study> | |
| 16230 | ||
| 16231 | =item study | |
| 16232 | ||
| 16233 | =for Pod::Functions optimize input data for repeated searches | |
| 16234 | ||
| 16235 | 19027 | =begin original |
| 16236 | 19028 | |
| 16237 | ||
| 19029 | Redeclaring a variable in the same scope or statement will "shadow" the | |
| 16238 | ||
| 19030 | previous declaration, creating a new instance and preventing access to | |
| 16239 | ||
| 19031 | the previous one. This is usually undesired and, if warnings are enabled, | |
| 16240 | ||
| 19032 | will result in a warning in the C<shadow> category. | |
| 16241 | frequencies in the string to be searched; you probably want to compare | |
| 16242 | run times with and without it to see which is faster. Those loops | |
| 16243 | that scan for many short constant strings (including the constant | |
| 16244 | parts of more complex patterns) will benefit most. | |
| 16245 | (The way C<study> works is this: a linked list of every | |
| 16246 | character in the string to be searched is made, so we know, for | |
| 16247 | example, where all the C<'k'> characters are. From each search string, | |
| 16248 | the rarest character is selected, based on some static frequency tables | |
| 16249 | constructed from some C programs and English text. Only those places | |
| 16250 | that contain this "rarest" character are examined.) | |
| 16251 | 19033 | |
| 16252 | 19034 | =end original |
| 16253 | 19035 | |
| 16254 | ||
| 19036 | 同じスコープや文で変数を再宣言すると、以前の宣言を「隠し」、 | |
| 16255 | ||
| 19037 | 新しい実体を作って、以前の実体にアクセスできなくなります。 | |
| 16256 | ||
| 19038 | これは普通は望まれているものではなく、警告が有効なら、 | |
| 16257 | ||
| 19039 | C<shadow> カテゴリの警告が出ます。 | |
| 16258 | 検索される文字列内の文字頻度の分布によって、時間を節約することに | |
| 16259 | なるかもしれませんし、逆に浪費することになるかもしれません; 予習をした場合と | |
| 16260 | しない場合の実行時間を比較して、どちらが速いか調べることが必要でしょう。 | |
| 16261 | 短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん検索する | |
| 16262 | ループで、もっとも効果があるでしょう。 | |
| 16263 | (この C<study> の仕組みは、まず、検索される文字列内のすべての文字の | |
| 16264 | リンクされたリストが作られ、たとえば、すべての C<'k'> がどこにあるかが | |
| 16265 | わかるようになります。 | |
| 16266 | 各々の検索文字列から、C プログラムや英語のテキストから作られた頻度の | |
| 16267 | 統計情報に基づいて、もっとも珍しい文字が選ばれます。 | |
| 16268 | この「珍しい」文字を含む場所だけが調べられるのです。) | |
| 16269 | 19040 | |
| 16270 | 19041 | =begin original |
| 16271 | 19042 | |
| 16272 | ||
| 19043 | L<C<state>|/state VARLIST> is available only if the | |
| 16273 | ||
| 19044 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
| 19045 | prefixed with C<CORE::>. The | |
| 19046 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
| 19047 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 19048 | scope. | |
| 16274 | 19049 | |
| 16275 | 19050 | =end original |
| 16276 | 19051 | |
| 16277 | ||
| 19052 | L<C<state>|/state VARLIST> は | |
| 16278 | ||
| 19053 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
| 19054 | 前置した場合にのみ利用可能です。 | |
| 19055 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
| 19056 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
| 16279 | 19057 | |
| 16280 | ||
| 19058 | =item study SCALAR | |
| 16281 | ||
| 19059 | X<study> | |
| 16282 | print ".IX foo\n" if /\bfoo\b/; | |
| 16283 | print ".IX bar\n" if /\bbar\b/; | |
| 16284 | print ".IX blurfl\n" if /\bblurfl\b/; | |
| 16285 | # ... | |
| 16286 | print; | |
| 16287 | } | |
| 16288 | 19060 | |
| 19061 | =item study | |
| 19062 | ||
| 19063 | =for Pod::Functions no-op, formerly optimized input data for repeated searches | |
| 19064 | ||
| 16289 | 19065 | =begin original |
| 16290 | 19066 | |
| 16291 | ||
| 19067 | At this time, C<study> does nothing. This may change in the future. | |
| 16292 | will be looked at, because C<f> is rarer than C<o>. In general, this is | |
| 16293 | a big win except in pathological cases. The only question is whether | |
| 16294 | it saves you more time than it took to build the linked list in the | |
| 16295 | first place. | |
| 16296 | 19068 | |
| 16297 | 19069 | =end original |
| 16298 | 19070 | |
| 16299 | ||
| 19071 | 現時点では、C<study> は何もしません。 | |
| 16300 | ||
| 19072 | これは将来変更されるかもしれません。 | |
| 16301 | 一般に、病的な場合を除いて、かなりの結果が得られます。 | |
| 16302 | 唯一の問題は、節約できる時間が、最初にリンクリストを作る | |
| 16303 | 時間よりも多いかどうかです、 | |
| 16304 | 19073 | |
| 16305 | 19074 | =begin original |
| 16306 | 19075 | |
| 16307 | ||
| 19076 | Prior to Perl version 5.16, it would create an inverted index of all characters | |
| 16308 | ||
| 19077 | that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When | |
| 16309 | a | |
| 19078 | matching a pattern, the rarest character from the pattern would be looked up in | |
| 16310 | ||
| 19079 | this index. Rarity was based on some static frequency tables constructed from | |
| 16311 | ||
| 19080 | some C programs and English text. | |
| 16312 | scans a list of files (C<@files>) for a list of words (C<@words>), and prints | |
| 16313 | out the names of those files that contain a match: | |
| 16314 | 19081 | |
| 16315 | 19082 | =end original |
| 16316 | 19083 | |
| 16317 | ||
| 19084 | Perl バージョン 5.16 より前では、 | |
| 16318 | ||
| 19085 | 与えられた SCALAR (または指定されていなかった場合は L<C<$_>|perlvar/$_>)に | |
| 16319 | ||
| 19086 | 現れた全ての文字の転置インデックスを作ります。 | |
| 16320 | ||
| 19087 | パターンにマッチングしたとき、 | |
| 16321 | ||
| 19088 | パターン中の最も頻度の少ない文字がこのインデックスから探されます。 | |
| 16322 | ||
| 19089 | 頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを | |
| 16323 | ||
| 19090 | 基にしています。 | |
| 16324 | 探して、マッチするものがあったファイル名を出力します。 | |
| 16325 | 19091 | |
| 16326 | $search = 'while (<>) { study;'; | |
| 16327 | foreach $word (@words) { | |
| 16328 | $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n"; | |
| 16329 | } | |
| 16330 | $search .= "}"; | |
| 16331 | @ARGV = @files; | |
| 16332 | undef $/; | |
| 16333 | eval $search; # this screams | |
| 16334 | $/ = "\n"; # put back to normal input delimiter | |
| 16335 | foreach $file (sort keys(%seen)) { | |
| 16336 | print $file, "\n"; | |
| 16337 | } | |
| 16338 | ||
| 16339 | 19092 | =item sub NAME BLOCK |
| 16340 | 19093 | X<sub> |
| 16341 | 19094 | |
| 16342 | 19095 | =item sub NAME (PROTO) BLOCK |
| 16343 | 19096 | |
| 16344 | 19097 | =item sub NAME : ATTRS BLOCK |
| 16345 | 19098 | |
| 16346 | 19099 | =item sub NAME (PROTO) : ATTRS BLOCK |
| 16347 | 19100 | |
| 16348 | 19101 | =for Pod::Functions declare a subroutine, possibly anonymously |
| 16349 | 19102 | |
| 16350 | 19103 | =begin original |
| 16351 | 19104 | |
| 16352 | 19105 | This is subroutine definition, not a real function I<per se>. Without a |
| 16353 | 19106 | BLOCK it's just a forward declaration. Without a NAME, it's an anonymous |
| 16354 | 19107 | function declaration, so does return a value: the CODE ref of the closure |
| 16355 | 19108 | just created. |
| 16356 | 19109 | |
| 16357 | 19110 | =end original |
| 16358 | 19111 | |
| 16359 | 19112 | これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。 |
| 16360 | 19113 | BLOCK なしの場合、これは単に前方宣言です。 |
| 16361 | 19114 | NAME なしの場合は、無名関数定義であり、値(作成したブロックの |
| 16362 | 19115 | コードリファレンス)を返します: 単にクロージャの CODE リファレンスが |
| 16363 | 19116 | 作成されます。 |
| 16364 | 19117 | |
| 16365 | 19118 | =begin original |
| 16366 | 19119 | |
| 16367 | 19120 | See L<perlsub> and L<perlref> for details about subroutines and |
| 16368 | 19121 | references; see L<attributes> and L<Attribute::Handlers> for more |
| 16369 | 19122 | information about attributes. |
| 16370 | 19123 | |
| 16371 | 19124 | =end original |
| 16372 | 19125 | |
| 16373 | 19126 | サブルーチンとリファレンスに関する詳細については、L<perlsub> と |
| 16374 | 19127 | L<perlref> を参照してください; 属性に関する更なる情報については |
| 16375 | 19128 | L<attributes> と L<Attribute::Handlers> を参照してください。 |
| 16376 | 19129 | |
| 16377 | 19130 | =item __SUB__ |
| 16378 | 19131 | X<__SUB__> |
| 16379 | 19132 | |
| 16380 | 19133 | =for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine |
| 16381 | 19134 | |
| 16382 | 19135 | =begin original |
| 16383 | 19136 | |
| 16384 | 19137 | A special token that returns a reference to the current subroutine, or |
| 16385 | C<undef> outside of a subroutine. | |
| 19138 | L<C<undef>|/undef EXPR> outside of a subroutine. | |
| 16386 | 19139 | |
| 16387 | 19140 | =end original |
| 16388 | 19141 | |
| 16389 | 19142 | 現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では |
| 16390 | C<undef>。 | |
| 19143 | L<C<undef>|/undef EXPR>。 | |
| 16391 | 19144 | |
| 16392 | 19145 | =begin original |
| 16393 | 19146 | |
| 16394 | The behaviour of C<__SUB__> within a regex code block (such | |
| 19147 | The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such | |
| 16395 | is subject to change. | |
| 19148 | as C</(?{...})/>) is subject to change. | |
| 16396 | 19149 | |
| 16397 | 19150 | =end original |
| 16398 | 19151 | |
| 16399 | (C</(?{...})/> のような) 正規表現コードブロックの中の | |
| 19152 | (C</(?{...})/> のような) 正規表現コードブロックの中の | |
| 16400 | 変更される予定です。 | |
| 19153 | L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。 | |
| 16401 | 19154 | |
| 16402 | 19155 | =begin original |
| 16403 | 19156 | |
| 16404 | This token is only available under C<use v5.16> or the | |
| 19157 | This token is only available under C<use v5.16> or the | |
| 16405 | feature | |
| 19158 | L<C<"current_sub"> feature|feature/The 'current_sub' feature>. | |
| 19159 | See L<feature>. | |
| 16406 | 19160 | |
| 16407 | 19161 | =end original |
| 16408 | 19162 | |
| 16409 | このトークンは C<use v5.16> または | |
| 19163 | このトークンは C<use v5.16> または | |
| 19164 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ | |
| 19165 | 利用可能です。 | |
| 16410 | 19166 | L<feature> を参照してください。 |
| 16411 | 19167 | |
| 16412 | 19168 | =item substr EXPR,OFFSET,LENGTH,REPLACEMENT |
| 16413 | 19169 | X<substr> X<substring> X<mid> X<left> X<right> |
| 16414 | 19170 | |
| 16415 | 19171 | =item substr EXPR,OFFSET,LENGTH |
| 16416 | 19172 | |
| 16417 | 19173 | =item substr EXPR,OFFSET |
| 16418 | 19174 | |
| 16419 | 19175 | =for Pod::Functions get or alter a portion of a string |
| 16420 | 19176 | |
| 16421 | 19177 | =begin original |
| 16422 | 19178 | |
| 16423 | 19179 | Extracts a substring out of EXPR and returns it. First character is at |
| 16424 | 19180 | offset zero. If OFFSET is negative, starts |
| 16425 | 19181 | that far back from the end of the string. If LENGTH is omitted, returns |
| 16426 | 19182 | everything through the end of the string. If LENGTH is negative, leaves that |
| 16427 | 19183 | many characters off the end of the string. |
| 16428 | 19184 | |
| 16429 | 19185 | =end original |
| 16430 | 19186 | |
| 16431 | 19187 | EXPR から、部分文字列を取り出して返します。 |
| 16432 | 19188 | 最初の文字がオフセット 0 となります。 |
| 16433 | 19189 | OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。 |
| 16434 | 19190 | LENGTH を省略すると、EXPR の最後まですべてが返されます。 |
| 16435 | 19191 | LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。 |
| 16436 | 19192 | |
| 16437 | 19193 | my $s = "The black cat climbed the green tree"; |
| 16438 | 19194 | my $color = substr $s, 4, 5; # black |
| 16439 | 19195 | my $middle = substr $s, 4, -11; # black cat climbed the |
| 16440 | 19196 | my $end = substr $s, 14; # climbed the green tree |
| 16441 | 19197 | my $tail = substr $s, -4; # tree |
| 16442 | 19198 | my $z = substr $s, -4, 2; # tr |
| 16443 | 19199 | |
| 16444 | 19200 | =begin original |
| 16445 | 19201 | |
| 16446 | You can use the substr | |
| 19202 | You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> | |
| 19203 | function as an lvalue, in which case EXPR | |
| 16447 | 19204 | must itself be an lvalue. If you assign something shorter than LENGTH, |
| 16448 | 19205 | the string will shrink, and if you assign something longer than LENGTH, |
| 16449 | 19206 | the string will grow to accommodate it. To keep the string the same |
| 16450 | length, you may need to pad or chop your value using | |
| 19207 | length, you may need to pad or chop your value using | |
| 19208 | L<C<sprintf>|/sprintf FORMAT, LIST>. | |
| 16451 | 19209 | |
| 16452 | 19210 | =end original |
| 16453 | 19211 | |
| 16454 | substr | |
| 19212 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として | |
| 16455 | EXPR が自身左辺値でなければなりません。 | |
| 19213 | 使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。 | |
| 16456 | 19214 | LENGTH より短いものを代入したときには、 |
| 16457 | 19215 | EXPR は短くなり、LENGTH より長いものを代入したときには、 |
| 16458 | 19216 | EXPR はそれに合わせて伸びることになります。 |
| 16459 | EXPR の長さを一定に保つためには、C<sprintf> を | |
| 19217 | EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST> を | |
| 16460 | 代入する値の長さを調整することが、必要になるかもしれません。 | |
| 19218 | 使って、代入する値の長さを調整することが、必要になるかもしれません。 | |
| 16461 | 19219 | |
| 16462 | 19220 | =begin original |
| 16463 | 19221 | |
| 16464 | 19222 | If OFFSET and LENGTH specify a substring that is partly outside the |
| 16465 | 19223 | string, only the part within the string is returned. If the substring |
| 16466 | is beyond either end of the string, | |
| 19224 | is beyond either end of the string, | |
| 19225 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined | |
| 16467 | 19226 | value and produces a warning. When used as an lvalue, specifying a |
| 16468 | 19227 | substring that is entirely outside the string raises an exception. |
| 16469 | 19228 | Here's an example showing the behavior for boundary cases: |
| 16470 | 19229 | |
| 16471 | 19230 | =end original |
| 16472 | 19231 | |
| 16473 | 19232 | OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、 |
| 16474 | 19233 | 文字列の内側の部分だけが返されます。 |
| 16475 | 部分文字列が文字列の両端の外側の場合、 | |
| 19234 | 部分文字列が文字列の両端の外側の場合、 | |
| 19235 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、 | |
| 16476 | 19236 | 警告が出力されます。 |
| 16477 | 19237 | 左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると |
| 16478 | 19238 | 例外が発生します。 |
| 16479 | 19239 | 以下は境界条件の振る舞いを示す例です: |
| 16480 | 19240 | |
| 16481 | 19241 | my $name = 'fred'; |
| 16482 | 19242 | substr($name, 4) = 'dy'; # $name is now 'freddy' |
| 16483 | 19243 | my $null = substr $name, 6, 2; # returns "" (no warning) |
| 16484 | 19244 | my $oops = substr $name, 7; # returns undef, with warning |
| 16485 | 19245 | substr($name, 7) = 'gap'; # raises an exception |
| 16486 | 19246 | |
| 16487 | 19247 | =begin original |
| 16488 | 19248 | |
| 16489 | An alternative to using | |
| 19249 | An alternative to using | |
| 16490 | ||
| 19250 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to | |
| 19251 | specify the | |
| 19252 | REPLACEMENT string as the 4th argument. This allows you to replace | |
| 16491 | 19253 | parts of the EXPR and return what was there before in one operation, |
| 16492 | just as you can with | |
| 19254 | just as you can with | |
| 19255 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>. | |
| 16493 | 19256 | |
| 16494 | 19257 | =end original |
| 16495 | 19258 | |
| 16496 | substr | |
| 19259 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う | |
| 16497 | 引数として指定することです。 | |
| 19260 | 代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。 | |
| 16498 | 19261 | これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、 |
| 16499 | ということを(splice | |
| 19262 | ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様) | |
| 19263 | 1 動作で行えます。 | |
| 16500 | 19264 | |
| 16501 | 19265 | my $s = "The black cat climbed the green tree"; |
| 16502 | 19266 | my $z = substr $s, 14, 7, "jumped from"; # climbed |
| 16503 | 19267 | # $s is now "The black cat jumped from the green tree" |
| 16504 | 19268 | |
| 16505 | 19269 | =begin original |
| 16506 | 19270 | |
| 16507 | Note that the lvalue returned by the three-argument version of | |
| 19271 | Note that the lvalue returned by the three-argument version of | |
| 19272 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as | |
| 16508 | 19273 | a 'magic bullet'; each time it is assigned to, it remembers which part |
| 16509 | 19274 | of the original string is being modified; for example: |
| 16510 | 19275 | |
| 16511 | 19276 | =end original |
| 16512 | 19277 | |
| 16513 | 3 引数の substr | |
| 19278 | 3 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された | |
| 16514 | 注意してください; | |
| 19279 | 左辺値は「魔法の弾丸」のように振舞うことに注意してください; | |
| 16515 | 思い出されます; | |
| 19280 | これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます; | |
| 19281 | 例えば: | |
| 16516 | 19282 | |
| 16517 | $x = '1234'; | |
| 19283 | my $x = '1234'; | |
| 16518 | 19284 | for (substr($x,1,2)) { |
| 16519 | 19285 | $_ = 'a'; print $x,"\n"; # prints 1a4 |
| 16520 | 19286 | $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 |
| 16521 | 19287 | $x = '56789'; |
| 16522 | 19288 | $_ = 'pq'; print $x,"\n"; # prints 5pq9 |
| 16523 | 19289 | } |
| 16524 | 19290 | |
| 16525 | 19291 | =begin original |
| 16526 | 19292 | |
| 16527 | 19293 | With negative offsets, it remembers its position from the end of the string |
| 16528 | 19294 | when the target string is modified: |
| 16529 | 19295 | |
| 16530 | 19296 | =end original |
| 16531 | 19297 | |
| 16532 | 19298 | 負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの |
| 16533 | 19299 | 位置を覚えます: |
| 16534 | 19300 | |
| 16535 | $x = '1234'; | |
| 19301 | my $x = '1234'; | |
| 16536 | 19302 | for (substr($x, -3, 2)) { |
| 16537 | 19303 | $_ = 'a'; print $x,"\n"; # prints 1a4, as above |
| 16538 | 19304 | $x = 'abcdefg'; |
| 16539 | 19305 | print $_,"\n"; # prints f |
| 16540 | 19306 | } |
| 16541 | 19307 | |
| 16542 | 19308 | =begin original |
| 16543 | 19309 | |
| 16544 | 19310 | Prior to Perl version 5.10, the result of using an lvalue multiple times was |
| 16545 | 19311 | unspecified. Prior to 5.16, the result with negative offsets was |
| 16546 | 19312 | unspecified. |
| 16547 | 19313 | |
| 16548 | 19314 | =end original |
| 16549 | 19315 | |
| 16550 | 19316 | バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は |
| 16551 | 19317 | 未定義でした。 |
| 16552 | 19318 | 5.16 より前では、負のオフセットの結果は未定義です。 |
| 16553 | 19319 | |
| 16554 | 19320 | =item symlink OLDFILE,NEWFILE |
| 16555 | 19321 | X<symlink> X<link> X<symbolic link> X<link, symbolic> |
| 16556 | 19322 | |
| 16557 | 19323 | =for Pod::Functions create a symbolic link to a file |
| 16558 | 19324 | |
| 16559 | 19325 | =begin original |
| 16560 | 19326 | |
| 16561 | 19327 | Creates a new filename symbolically linked to the old filename. |
| 16562 | 19328 | Returns C<1> for success, C<0> otherwise. On systems that don't support |
| 16563 | 19329 | symbolic links, raises an exception. To check for that, |
| 16564 | 19330 | use eval: |
| 16565 | 19331 | |
| 16566 | 19332 | =end original |
| 16567 | 19333 | |
| 16568 | 19334 | NEWFILE として、OLDFILE へのシンボリックリンクを生成します。 |
| 16569 | 19335 | 成功時には C<1> を返し、失敗時には C<0> を返します。 |
| 16570 | 19336 | シンボリックリンクをサポートしていないシステムでは、 |
| 16571 | 19337 | 例外が発生します。 |
| 16572 | 19338 | これをチェックするには、eval を使用します: |
| 16573 | 19339 | |
| 16574 | $symlink_exists = eval { symlink("",""); 1 }; | |
| 19340 | my $symlink_exists = eval { symlink("",""); 1 }; | |
| 16575 | 19341 | |
| 16576 | 19342 | =begin original |
| 16577 | 19343 | |
| 16578 | 19344 | Portability issues: L<perlport/symlink>. |
| 16579 | 19345 | |
| 16580 | 19346 | =end original |
| 16581 | 19347 | |
| 16582 | 19348 | 移植性の問題: L<perlport/symlink>。 |
| 16583 | 19349 | |
| 16584 | 19350 | =item syscall NUMBER, LIST |
| 16585 | 19351 | X<syscall> X<system call> |
| 16586 | 19352 | |
| 16587 | 19353 | =for Pod::Functions execute an arbitrary system call |
| 16588 | 19354 | |
| 16589 | 19355 | =begin original |
| 16590 | 19356 | |
| 16591 | 19357 | Calls the system call specified as the first element of the list, |
| 16592 | 19358 | passing the remaining elements as arguments to the system call. If |
| 16593 | 19359 | unimplemented, raises an exception. The arguments are interpreted |
| 16594 | 19360 | as follows: if a given argument is numeric, the argument is passed as |
| 16595 | 19361 | an int. If not, the pointer to the string value is passed. You are |
| 16596 | 19362 | responsible to make sure a string is pre-extended long enough to |
| 16597 | 19363 | receive any result that might be written into a string. You can't use a |
| 16598 | string literal (or other read-only string) as an argument to | |
| 19364 | string literal (or other read-only string) as an argument to | |
| 16599 | because Perl has to assume that any | |
| 19365 | L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any | |
| 16600 | through. If your | |
| 19366 | string pointer might be written through. If your | |
| 16601 | 19367 | integer arguments are not literals and have never been interpreted in a |
| 16602 | 19368 | numeric context, you may need to add C<0> to them to force them to look |
| 16603 | like numbers. This emulates the | |
| 19369 | like numbers. This emulates the | |
| 19370 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or | |
| 19371 | vice versa): | |
| 16604 | 19372 | |
| 16605 | 19373 | =end original |
| 16606 | 19374 | |
| 16607 | 19375 | LIST の最初の要素で指定するシステムコールを、残りの要素をその |
| 16608 | 19376 | システムコールの引数として呼び出します。 |
| 16609 | 19377 | 実装されていない場合には、例外が発生します。 |
| 16610 | 19378 | 引数は、以下のように解釈されます: 引数が数字であれば、int として |
| 16611 | 19379 | 引数を渡します。 |
| 16612 | 19380 | そうでなければ、文字列値へのポインタが渡されます。 |
| 16613 | 19381 | 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 |
| 16614 | 19382 | 文字列を予め伸ばしておく必要があります。 |
| 16615 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を | |
| 19383 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を | |
| 16616 | 引数として使うことはできません; | |
| 19384 | L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません; | |
| 16617 | 仮定しなければならないからです。 | |
| 19385 | Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。 | |
| 16618 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
| 19386 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことのない | |
| 16619 | ||
| 19387 | ものであれば、数値として解釈されるように、 | |
| 16620 | 19388 | C<0> を足しておく必要があるかもしれません。 |
| 16621 | 以下は C<syswrite> 関数(あるいは | |
| 19389 | 以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは | |
| 19390 | その逆)をエミュレートします。 | |
| 16622 | 19391 | |
| 16623 | 19392 | require 'syscall.ph'; # may need to run h2ph |
| 16624 | $s = "hi there\n"; | |
| 19393 | my $s = "hi there\n"; | |
| 16625 | syscall( | |
| 19394 | syscall(SYS_write(), fileno(STDOUT), $s, length $s); | |
| 16626 | 19395 | |
| 16627 | 19396 | =begin original |
| 16628 | 19397 | |
| 16629 | 19398 | Note that Perl supports passing of up to only 14 arguments to your syscall, |
| 16630 | 19399 | which in practice should (usually) suffice. |
| 16631 | 19400 | |
| 16632 | 19401 | =end original |
| 16633 | 19402 | |
| 16634 | 19403 | Perl は、システムコールに最大 14 個の引数しか渡せませんが、 |
| 16635 | 19404 | (普通は)実用上問題はないでしょう。 |
| 16636 | 19405 | |
| 16637 | 19406 | =begin original |
| 16638 | 19407 | |
| 16639 | 19408 | Syscall returns whatever value returned by the system call it calls. |
| 16640 | If the system call fails, C<syscall> | |
| 19409 | If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns | |
| 19410 | C<-1> and sets L<C<$!>|perlvar/$!> (errno). | |
| 16641 | 19411 | Note that some system calls I<can> legitimately return C<-1>. The proper |
| 16642 | way to handle such calls is to assign C<$!=0> before the call, then | |
| 19412 | way to handle such calls is to assign C<$! = 0> before the call, then | |
| 16643 | check the value of C<$!> | |
| 19413 | check the value of L<C<$!>|perlvar/$!> if | |
| 19414 | L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>. | |
| 16644 | 19415 | |
| 16645 | 19416 | =end original |
| 16646 | 19417 | |
| 16647 | 19418 | syscall は、呼び出したシステムコールが返した値を返します。 |
| 16648 | システムコールが失敗すると、C<syscall> は C<-1> を | |
| 19419 | システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を | |
| 16649 | C<$!>(errno) を設定します。 | |
| 19420 | 返し、L<C<$!>|perlvar/$!>(errno) を設定します。 | |
| 16650 | 19421 | システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。 |
| 16651 | 19422 | このようなシステムコールを正しく扱うには、 |
| 16652 | C<$!=0> をシステムコールの前に実行し、それから | |
| 19423 | C<$! = 0> をシステムコールの前に実行し、それから | |
| 16653 | C<syscall> が C<-1> を返した時には | |
| 19424 | L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には | |
| 19425 | L<C<$!>|perlvar/$!> の値を調べてください。 | |
| 16654 | 19426 | |
| 16655 | 19427 | =begin original |
| 16656 | 19428 | |
| 16657 | There's a problem with C<syscall( | |
| 19429 | There's a problem with C<syscall(SYS_pipe())>: it returns the file | |
| 16658 | 19430 | number of the read end of the pipe it creates, but there is no way |
| 16659 | 19431 | to retrieve the file number of the other end. You can avoid this |
| 16660 | problem by using C<pipe> instead. | |
| 19432 | problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead. | |
| 16661 | 19433 | |
| 16662 | 19434 | =end original |
| 16663 | 19435 | |
| 16664 | C<syscall(&SYS_pipe)> には問題があり、 | |
| 19436 | C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の | |
| 16665 | ||
| 19437 | ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。 | |
| 16666 | ||
| 19438 | この問題を避けるためには、代わりに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を | |
| 16667 | ||
| 19439 | 使ってください。 | |
| 16668 | 19440 | |
| 16669 | 19441 | =begin original |
| 16670 | 19442 | |
| 16671 | 19443 | Portability issues: L<perlport/syscall>. |
| 16672 | 19444 | |
| 16673 | 19445 | =end original |
| 16674 | 19446 | |
| 16675 | 19447 | 移植性の問題: L<perlport/syscall>。 |
| 16676 | 19448 | |
| 16677 | 19449 | =item sysopen FILEHANDLE,FILENAME,MODE |
| 16678 | 19450 | X<sysopen> |
| 16679 | 19451 | |
| 16680 | 19452 | =item sysopen FILEHANDLE,FILENAME,MODE,PERMS |
| 16681 | 19453 | |
| 16682 | 19454 | =for Pod::Functions +5.002 open a file, pipe, or descriptor |
| 16683 | 19455 | |
| 16684 | 19456 | =begin original |
| 16685 | 19457 | |
| 16686 | 19458 | Opens the file whose filename is given by FILENAME, and associates it with |
| 16687 | 19459 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real |
| 16688 | 19460 | filehandle wanted; an undefined scalar will be suitably autovivified. This |
| 16689 | function calls the underlying operating system's | |
| 19461 | function calls the underlying operating system's L<open(2)> function with the | |
| 16690 | 19462 | parameters FILENAME, MODE, and PERMS. |
| 16691 | 19463 | |
| 16692 | 19464 | =end original |
| 16693 | 19465 | |
| 16694 | 19466 | FILENAME で与えられたファイル名のファイルをオープンし、 |
| 16695 | 19467 | FILEHANDLE と結び付けます。 |
| 16696 | 19468 | FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として |
| 16697 | 19469 | 扱われます; 未定義のスカラは適切に自動有効化されます。 |
| 16698 | この関数呼び出しはシステムの | |
| 19470 | この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の | |
| 16699 | 19471 | 引数で呼び出すことを基礎としています。 |
| 16700 | 19472 | |
| 16701 | 19473 | =begin original |
| 16702 | 19474 | |
| 19475 | Returns true on success and L<C<undef>|/undef EXPR> otherwise. | |
| 19476 | ||
| 19477 | =end original | |
| 19478 | ||
| 19479 | 成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。 | |
| 19480 | ||
| 19481 | =begin original | |
| 19482 | ||
| 19483 | L<PerlIO> layers will be applied to the handle the same way they would in an | |
| 19484 | L<C<open>|/open FILEHANDLE,MODE,EXPR> call that does not specify layers. That is, | |
| 19485 | the current value of L<C<${^OPEN}>|perlvar/${^OPEN}> as set by the L<open> | |
| 19486 | pragma in a lexical scope, or the C<-C> commandline option or C<PERL_UNICODE> | |
| 19487 | environment variable in the main program scope, falling back to the platform | |
| 19488 | defaults as described in L<PerlIO/Defaults and how to override them>. If you | |
| 19489 | want to remove any layers that may transform the byte stream, use | |
| 19490 | L<C<binmode>|/binmode FILEHANDLE, LAYER> after opening it. | |
| 19491 | ||
| 19492 | =end original | |
| 19493 | ||
| 19494 | L<PerlIO> 層は、層を指定しない L<C<open>|/open FILEHANDLE,MODE,EXPR> | |
| 19495 | 呼び出しでするのと同じ方法でハンドルに適用されます。 | |
| 19496 | これは、レキシカルスコープの L<open> プラグマで設定された | |
| 19497 | L<C<${^OPEN}>|perlvar/${^OPEN}> の現在の値、 | |
| 19498 | またはメインプログラムスコープの C<-C> コマンドラインオプションまたは | |
| 19499 | C<PERL_UNICODE> 環境変数、L<PerlIO/Defaults and how to override them> で | |
| 19500 | 記述されているようにプラットフォームのデフォルトに | |
| 19501 | フォールバックしたものです。 | |
| 19502 | バイトストリームを変換する全ての層を除去したい場合は、 | |
| 19503 | それを開いた後に L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。 | |
| 19504 | ||
| 19505 | =begin original | |
| 19506 | ||
| 16703 | 19507 | The possible values and flag bits of the MODE parameter are |
| 16704 | system-dependent; they are available via the standard module | |
| 19508 | system-dependent; they are available via the standard module | |
| 16705 | the documentation of your operating system's | |
| 19509 | L<C<Fcntl>|Fcntl>. See the documentation of your operating system's | |
| 19510 | L<open(2)> syscall to see | |
| 16706 | 19511 | which values and flag bits are available. You may combine several flags |
| 16707 | 19512 | using the C<|>-operator. |
| 16708 | 19513 | |
| 16709 | 19514 | =end original |
| 16710 | 19515 | |
| 16711 | 19516 | MODE パラメータに指定できるフラグビットと値はシステム依存です; |
| 16712 | これは標準モジュール C<Fcntl> 経由で利用可能です。 | |
| 19517 | これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。 | |
| 16713 | 19518 | どのようなフラグビットと値が利用可能であるかについては、 |
| 16714 | OS の | |
| 19519 | OS の L<open(2)> システムコールに関する文書を参照してください。 | |
| 16715 | 19520 | C<|> 演算子を使って複数のフラグを結合することができます。 |
| 16716 | 19521 | |
| 16717 | 19522 | =begin original |
| 16718 | 19523 | |
| 16719 | 19524 | Some of the most common values are C<O_RDONLY> for opening the file in |
| 16720 | 19525 | read-only mode, C<O_WRONLY> for opening the file in write-only mode, |
| 16721 | 19526 | and C<O_RDWR> for opening the file in read-write mode. |
| 16722 | 19527 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
| 16723 | 19528 | |
| 16724 | 19529 | =end original |
| 16725 | 19530 | |
| 16726 | 19531 | もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、 |
| 16727 | 19532 | ファイルを書き込み専用で開く C<O_WRONLY>、 |
| 16728 | 19533 | ファイルを読み書き両用で開く C<O_RDWR> です。 |
| 16729 | 19534 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> |
| 16730 | 19535 | |
| 16731 | 19536 | =begin original |
| 16732 | 19537 | |
| 16733 | 19538 | For historical reasons, some values work on almost every system |
| 16734 | 19539 | supported by Perl: 0 means read-only, 1 means write-only, and 2 |
| 16735 | 19540 | means read/write. We know that these values do I<not> work under |
| 16736 | OS/390 | |
| 19541 | OS/390; you probably don't want to use them in new code. | |
| 16737 | use them in new code. | |
| 16738 | 19542 | |
| 16739 | 19543 | =end original |
| 16740 | 19544 | |
| 16741 | 19545 | 歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が |
| 16742 | 19546 | あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 |
| 16743 | OS/390 | |
| 19547 | OS/390 では動作 I<しない> ことが分かっています; | |
| 16744 | 19548 | 新しく書くコードではこれらは使わないほうがよいでしょう。 |
| 16745 | 19549 | |
| 16746 | 19550 | =begin original |
| 16747 | 19551 | |
| 16748 | If the file named by FILENAME does not exist and the | |
| 19552 | If the file named by FILENAME does not exist and the | |
| 19553 | L<C<open>|/open FILEHANDLE,MODE,EXPR> call creates | |
| 16749 | 19554 | it (typically because MODE includes the C<O_CREAT> flag), then the value of |
| 16750 | 19555 | PERMS specifies the permissions of the newly created file. If you omit |
| 16751 | the PERMS argument to C<sysopen> | |
| 19556 | the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
| 19557 | Perl uses the octal value C<0666>. | |
| 16752 | 19558 | These permission values need to be in octal, and are modified by your |
| 16753 | process's current C<umask>. | |
| 19559 | process's current L<C<umask>|/umask EXPR>. | |
| 16754 | 19560 | X<O_CREAT> |
| 16755 | 19561 | |
| 16756 | 19562 | =end original |
| 16757 | 19563 | |
| 16758 | 19564 | FILENAME という名前のファイルが存在せず、(典型的には MODE が |
| 16759 | C<O_CREAT> フラグを含んでいたために) | |
| 19565 | C<O_CREAT> フラグを含んでいたために) | |
| 19566 | L<C<open>|/open FILEHANDLE,MODE,EXPR> 呼び出しがそれを作った場合、 | |
| 16760 | 19567 | PERMS の値は新しく作られたファイルの権限を指定します。 |
| 16761 | C<sysopen> の PERMS 引数を省略した場合、 | |
| 19568 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、 | |
| 16762 | ||
| 19569 | Perl は 8 進数 C<0666> を使います。 | |
| 16763 | ||
| 19570 | これらの権限は 8 進数である必要があり、プロセスの現在の | |
| 19571 | L<C<umask>|/umask EXPR> で修正されます。 | |
| 16764 | 19572 | X<O_CREAT> |
| 16765 | 19573 | |
| 16766 | 19574 | =begin original |
| 16767 | 19575 | |
| 16768 | 19576 | In many systems the C<O_EXCL> flag is available for opening files in |
| 16769 | 19577 | exclusive mode. This is B<not> locking: exclusiveness means here that |
| 16770 | if the file already exists, | |
| 19578 | if the file already exists, | |
| 19579 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may | |
| 19580 | not work | |
| 16771 | 19581 | on network filesystems, and has no effect unless the C<O_CREAT> flag |
| 16772 | 19582 | is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from |
| 16773 | 19583 | being opened if it is a symbolic link. It does not protect against |
| 16774 | 19584 | symbolic links in the file's path. |
| 16775 | 19585 | X<O_EXCL> |
| 16776 | 19586 | |
| 16777 | 19587 | =end original |
| 16778 | 19588 | |
| 16779 | 19589 | 多くのシステムではファイルを排他モードで開くために C<O_EXCL> が |
| 16780 | 19590 | 利用可能です。 |
| 16781 | 19591 | これはロック B<ではありません>: 排他性というのは既にファイルが |
| 16782 | 存在していた場合、sysopen | |
| 19592 | 存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> が | |
| 19593 | 失敗することを意味します。 | |
| 16783 | 19594 | C<O_EXCL> はネットワークファイルシステムでは動作せず、 |
| 16784 | 19595 | またC<O_CREAT> フラグも有効でない限りは効果がありません。 |
| 16785 | 19596 | C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は |
| 16786 | 19597 | ファイルを開くことを妨げます。 |
| 16787 | 19598 | これはファイルパス中のシンボリックリンクは守りません。 |
| 16788 | 19599 | X<O_EXCL> |
| 16789 | 19600 | |
| 16790 | 19601 | =begin original |
| 16791 | 19602 | |
| 16792 | 19603 | Sometimes you may want to truncate an already-existing file. This |
| 16793 | 19604 | can be done using the C<O_TRUNC> flag. The behavior of |
| 16794 | 19605 | C<O_TRUNC> with C<O_RDONLY> is undefined. |
| 16795 | 19606 | X<O_TRUNC> |
| 16796 | 19607 | |
| 16797 | 19608 | =end original |
| 16798 | 19609 | |
| 16799 | 19610 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません。 |
| 16800 | 19611 | これは C<O_TRUNC> フラグを使うことで行えます。 |
| 16801 | 19612 | C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。 |
| 16802 | 19613 | X<O_TRUNC> |
| 16803 | 19614 | |
| 16804 | 19615 | =begin original |
| 16805 | 19616 | |
| 16806 | You should seldom if ever use C<0644> as argument to | |
| 19617 | You should seldom if ever use C<0644> as argument to | |
| 19618 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because | |
| 16807 | 19619 | that takes away the user's option to have a more permissive umask. |
| 16808 | Better to omit it. See | |
| 19620 | Better to omit it. See L<C<umask>|/umask EXPR> for more on this. | |
| 16809 | on this. | |
| 16810 | 19621 | |
| 16811 | 19622 | =end original |
| 16812 | 19623 | |
| 16813 | めったなことでは C<sysopen> の引数に | |
| 19624 | めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に | |
| 19625 | C<0644> を指定するべきではないでしょう: | |
| 16814 | 19626 | ユーザーがより寛大な umask を指定する選択肢を奪うからです。 |
| 16815 | 19627 | 省略した方がいいです。 |
| 16816 | これに関するさらなる情報については | |
| 19628 | これに関するさらなる情報については L<C<umask>|/umask EXPR> を | |
| 16817 | 19629 | 参照してください。 |
| 16818 | 19630 | |
| 16819 | 19631 | =begin original |
| 16820 | 19632 | |
| 16821 | ||
| 19633 | This function has no direct relation to the usage of | |
| 16822 | ||
| 19634 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 16823 | ||
| 19635 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 16824 | ||
| 19636 | or L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. A handle opened with | |
| 16825 | ||
| 19637 | this function can be used with buffered IO just as one opened with | |
| 19638 | L<C<open>|/open FILEHANDLE,MODE,EXPR> can be used with unbuffered IO. | |
| 16826 | 19639 | |
| 16827 | 19640 | =end original |
| 16828 | 19641 | |
| 16829 | ||
| 19642 | この関数は、 | |
| 16830 | ||
| 19643 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 16831 | ||
| 19644 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 19645 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> の使用法と | |
| 19646 | 直接の関係はありません。 | |
| 19647 | この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、 | |
| 19648 | L<C<open>|/open FILEHANDLE,MODE,EXPR> で開かれたものは | |
| 19649 | バッファリングされない IO で使えます。 | |
| 19650 | ||
| 19651 | =begin original | |
| 19652 | ||
| 19653 | Note that under Perls older than 5.8.0, | |
| 19654 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the | |
| 19655 | L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known | |
| 19656 | to fail when file descriptors exceed a certain value, typically 255. If | |
| 19657 | you need more file descriptors than that, consider using the | |
| 19658 | L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later, | |
| 19659 | PerlIO is (most often) the default. | |
| 19660 | ||
| 19661 | =end original | |
| 19662 | ||
| 19663 | 5.8.0 より古い Perl では、 | |
| 19664 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は | |
| 19665 | C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。 | |
| 19666 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を | |
| 19667 | 超えると失敗することが知られています。 | |
| 16832 | 19668 | これより多くのファイル記述子が必要な場合は、 |
| 16833 | Pe | |
| 19669 | L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討してください。 | |
| 16834 | P | |
| 19670 | 5.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。 | |
| 16835 | 19671 | |
| 16836 | 19672 | =begin original |
| 16837 | 19673 | |
| 16838 | 19674 | See L<perlopentut> for a kinder, gentler explanation of opening files. |
| 16839 | 19675 | |
| 16840 | 19676 | =end original |
| 16841 | 19677 | |
| 16842 | ファイル | |
| 19678 | ファイルを開くことに関するより親切な説明については L<perlopentut> を | |
| 19679 | 参照してください。 | |
| 16843 | 19680 | |
| 16844 | 19681 | =begin original |
| 16845 | 19682 | |
| 16846 | 19683 | Portability issues: L<perlport/sysopen>. |
| 16847 | 19684 | |
| 16848 | 19685 | =end original |
| 16849 | 19686 | |
| 16850 | 19687 | 移植性の問題: L<perlport/sysopen>。 |
| 16851 | 19688 | |
| 16852 | 19689 | =item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 16853 | 19690 | X<sysread> |
| 16854 | 19691 | |
| 16855 | 19692 | =item sysread FILEHANDLE,SCALAR,LENGTH |
| 16856 | 19693 | |
| 16857 | 19694 | =for Pod::Functions fixed-length unbuffered input from a filehandle |
| 16858 | 19695 | |
| 16859 | 19696 | =begin original |
| 16860 | 19697 | |
| 16861 | 19698 | Attempts to read LENGTH bytes of data into variable SCALAR from the |
| 16862 | specified FILEHANDLE, using | |
| 19699 | specified FILEHANDLE, using L<read(2)>. It bypasses any L<PerlIO> layers | |
| 16863 | buffered IO | |
| 19700 | including buffered IO (but is affected by the presence of the C<:utf8> | |
| 16864 | ||
| 19701 | layer as described later), so mixing this with other kinds of reads, | |
| 16865 | p | |
| 19702 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 19703 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 19704 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause | |
| 19705 | confusion because the | |
| 19706 | C<:perlio> or C<:crlf> layers usually buffer data. Returns the number of | |
| 16866 | 19707 | bytes actually read, C<0> at end of file, or undef if there was an |
| 16867 | error (in the latter case C<$!> is also set). SCALAR will | |
| 19708 | error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will | |
| 19709 | be grown or | |
| 16868 | 19710 | shrunk so that the last byte actually read is the last byte of the |
| 16869 | 19711 | scalar after the read. |
| 16870 | 19712 | |
| 16871 | 19713 | =end original |
| 16872 | 19714 | |
| 16873 | read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの | |
| 19715 | L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの | |
| 16874 | 19716 | データの読み込みを試みます。 |
| 16875 | これは、バッファ付き IO ルーチンを | |
| 19717 | これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので | |
| 16876 | ||
| 19718 | (しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、 | |
| 16877 | ||
| 19719 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 16878 | ||
| 19720 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
| 16879 | ||
| 19721 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるかも | |
| 19722 | しれません; | |
| 19723 | C<:perlio> 層や C<:crlf> 層は普通データをバッファリングするからです。 | |
| 19724 | ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に | |
| 19725 | 読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も | |
| 16880 | 19726 | セットされます)。 |
| 16881 | 19727 | 実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、 |
| 16882 | 19728 | SCALAR は伸び縮みします。 |
| 16883 | 19729 | |
| 16884 | 19730 | =begin original |
| 16885 | 19731 | |
| 16886 | 19732 | An OFFSET may be specified to place the read data at some place in the |
| 16887 | 19733 | string other than the beginning. A negative OFFSET specifies |
| 16888 | 19734 | placement at that many characters counting backwards from the end of |
| 16889 | 19735 | the string. A positive OFFSET greater than the length of SCALAR |
| 16890 | 19736 | results in the string being padded to the required size with C<"\0"> |
| 16891 | 19737 | bytes before the result of the read is appended. |
| 16892 | 19738 | |
| 16893 | 19739 | =end original |
| 16894 | 19740 | |
| 16895 | OFFSET を指定すると、文字列の先頭以外の場所から | |
| 19741 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 | |
| 16896 | できます。 | |
| 16897 | 19742 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで |
| 16898 | 19743 | 位置を指定します。 |
| 16899 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は | |
| 19744 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が | |
| 16900 | ||
| 19745 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 | |
| 16901 | パッディングされます。 | |
| 16902 | 19746 | |
| 16903 | 19747 | =begin original |
| 16904 | 19748 | |
| 16905 | There is no syseof() function, which is ok, since | |
| 19749 | There is no syseof() function, which is ok, since | |
| 16906 | well on device files (like ttys) | |
| 19750 | L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys) | |
| 16907 | ||
| 19751 | anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and | |
| 19752 | check for a return value of 0 to decide whether you're done. | |
| 16908 | 19753 | |
| 16909 | 19754 | =end original |
| 16910 | 19755 | |
| 16911 | syseof() 関数はありませんが、問題ありません; どちらにしろ | |
| 19756 | syseof() 関数はありませんが、問題ありません; どちらにしろ | |
| 19757 | L<C<eof>|/eof FILEHANDLE> は | |
| 16912 | 19758 | (tty のような)デバイスファイルに対してはうまく動作しないからです。 |
| 16913 | sysread | |
| 19759 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、 | |
| 16914 | 判断してください。 | |
| 19760 | 返り値が 0 かどうかで最後まで読んだかを判断してください。 | |
| 16915 | 19761 | |
| 16916 | 19762 | =begin original |
| 16917 | 19763 | |
| 16918 | Note that if the filehandle has been marked as C<:utf8> | |
| 19764 | Note that if the filehandle has been marked as C<:utf8>, C<sysread> will | |
| 16919 | ||
| 19765 | throw an exception. The C<:encoding(...)> layer implicitly | |
| 16920 | ||
| 19766 | introduces the C<:utf8> layer. See | |
| 16921 | ||
| 19767 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 16922 | ||
| 19768 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma. | |
| 16923 | 19769 | |
| 16924 | 19770 | =end original |
| 16925 | 19771 | |
| 16926 | ファイルハンドルが C<:utf8> であるとマークが付けられると、 | |
| 19772 | ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
| 16927 | ||
| 19773 | C<sysread> は例外を投げます。 | |
| 16928 | ||
| 19774 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 16929 | C< | |
| 19775 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 16930 | L< | |
| 19776 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください。 | |
| 16931 | 19777 | |
| 16932 | 19778 | =item sysseek FILEHANDLE,POSITION,WHENCE |
| 16933 | 19779 | X<sysseek> X<lseek> |
| 16934 | 19780 | |
| 16935 | 19781 | =for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite |
| 16936 | 19782 | |
| 16937 | 19783 | =begin original |
| 16938 | 19784 | |
| 16939 | Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may | |
| 19785 | Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may | |
| 16940 | 19786 | be an expression whose value gives the name of the filehandle. The values |
| 16941 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set | |
| 19787 | for WHENCE are C<0> to set the new position to POSITION; C<1> to set it | |
| 16942 | 19788 | to the current position plus POSITION; and C<2> to set it to EOF plus |
| 16943 | 19789 | POSITION, typically negative. |
| 16944 | 19790 | |
| 16945 | 19791 | =end original |
| 16946 | 19792 | |
| 16947 | FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。 | |
| 19793 | FILEHANDLE のシステム位置を I<バイト単位> で L<lseek(2)> を使って設定します。 | |
| 16948 | 19794 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
| 16949 | 19795 | WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します; |
| 16950 | 19796 | C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、 |
| 16951 | 19797 | EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を |
| 16952 | 19798 | 設定します。 |
| 16953 | 19799 | |
| 16954 | 19800 | =begin original |
| 16955 | 19801 | |
| 16956 | Note the | |
| 19802 | Note the emphasis on bytes: even if the filehandle has been set to operate | |
| 16957 | on characters (for example | |
| 19803 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the | |
| 16958 | ||
| 19804 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 16959 | ||
| 19805 | L<C<tell>|/tell FILEHANDLE>, and | |
| 19806 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 19807 | family of functions use byte offsets, not character offsets, | |
| 19808 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 16960 | 19809 | |
| 16961 | 19810 | =end original |
| 16962 | 19811 | |
| 16963 | ||
| 19812 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) | |
| 16964 | 設定されてい | |
| 19813 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 | |
| 16965 | ||
| 19814 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 16966 | ||
| 19815 | L<C<tell>|/tell FILEHANDLE>, | |
| 16967 | ||
| 19816 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 19817 | 文字オフセットではなくバイトオフセットを使います; | |
| 19818 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 16968 | 19819 | |
| 16969 | 19820 | =begin original |
| 16970 | 19821 | |
| 16971 | sysseek | |
| 19822 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal | |
| 16972 | ||
| 19823 | buffered IO, so mixing it with reads other than | |
| 16973 | C<se | |
| 19824 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example | |
| 19825 | L<C<readline>|/readline EXPR> or | |
| 19826 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>), | |
| 19827 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 19828 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 19829 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause | |
| 19830 | confusion. | |
| 16974 | 19831 | |
| 16975 | 19832 | =end original |
| 16976 | 19833 | |
| 16977 | sysseek | |
| 19834 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を | |
| 16978 | ||
| 19835 | バイパスしますので、 | |
| 16979 | ||
| 19836 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば | |
| 16980 | ||
| 19837 | L<C<readline>|/readline EXPR> や | |
| 19838 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、 | |
| 19839 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 19840 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
| 19841 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。 | |
| 16981 | 19842 | |
| 16982 | 19843 | =begin original |
| 16983 | 19844 | |
| 16984 | 19845 | For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, |
| 16985 | 19846 | and C<SEEK_END> (start of the file, current position, end of the file) |
| 16986 | from the Fcntl module. Use of the constants is also more portable | |
| 19847 | from the L<Fcntl> module. Use of the constants is also more portable | |
| 16987 | 19848 | than relying on 0, 1, and 2. For example to define a "systell" function: |
| 16988 | 19849 | |
| 16989 | 19850 | =end original |
| 16990 | 19851 | |
| 16991 | WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, | |
| 19852 | WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, | |
| 16992 | 19853 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を |
| 16993 | 19854 | 使うこともできます。 |
| 16994 | 19855 | 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 |
| 16995 | 19856 | 例えば "systell" 関数を定義するには: |
| 16996 | 19857 | |
| 16997 | 19858 | use Fcntl 'SEEK_CUR'; |
| 16998 | 19859 | sub systell { sysseek($_[0], 0, SEEK_CUR) } |
| 16999 | 19860 | |
| 17000 | 19861 | =begin original |
| 17001 | 19862 | |
| 17002 | 19863 | Returns the new position, or the undefined value on failure. A position |
| 17003 | of zero is returned as the string C<"0 but true">; thus | |
| 19864 | of zero is returned as the string C<"0 but true">; thus | |
| 19865 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns | |
| 17004 | 19866 | true on success and false on failure, yet you can still easily determine |
| 17005 | 19867 | the new position. |
| 17006 | 19868 | |
| 17007 | 19869 | =end original |
| 17008 | 19870 | |
| 17009 | 19871 | 新しい位置を返します; 失敗したときは未定義値を返します。 |
| 17010 | 19872 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って |
| 17011 | C<sysseek> は成功時に真を返し、 | |
| 19873 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、 | |
| 17012 | 判定できます。 | |
| 19874 | 失敗時に偽を返しますが、簡単に新しい位置を判定できます。 | |
| 17013 | 19875 | |
| 17014 | 19876 | =item system LIST |
| 17015 | 19877 | X<system> X<shell> |
| 17016 | 19878 | |
| 17017 | 19879 | =item system PROGRAM LIST |
| 17018 | 19880 | |
| 17019 | 19881 | =for Pod::Functions run a separate program |
| 17020 | 19882 | |
| 17021 | 19883 | =begin original |
| 17022 | 19884 | |
| 17023 | Does exactly the same thing as C<exec LIST>, except that a fork is | |
| 19885 | Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is | |
| 17024 | 19886 | done first and the parent process waits for the child process to |
| 17025 | 19887 | exit. Note that argument processing varies depending on the |
| 17026 | 19888 | number of arguments. If there is more than one argument in LIST, |
| 17027 | 19889 | or if LIST is an array with more than one value, starts the program |
| 17028 | 19890 | given by the first element of the list with arguments given by the |
| 17029 | 19891 | rest of the list. If there is only one scalar argument, the argument |
| 17030 | 19892 | is checked for shell metacharacters, and if there are any, the |
| 17031 | 19893 | entire argument is passed to the system's command shell for parsing |
| 17032 | 19894 | (this is C</bin/sh -c> on Unix platforms, but varies on other |
| 17033 | 19895 | platforms). If there are no shell metacharacters in the argument, |
| 17034 | 19896 | it is split into words and passed directly to C<execvp>, which is |
| 17035 | more efficient. | |
| 19897 | more efficient. On Windows, only the C<system PROGRAM LIST> syntax will | |
| 19898 | reliably avoid using the shell; C<system LIST>, even with more than one | |
| 19899 | element, will fall back to the shell if the first spawn fails. | |
| 17036 | 19900 | |
| 17037 | 19901 | =end original |
| 17038 | 19902 | |
| 17039 | C<exec LIST> とほとんど同じですが、まず fork を行ない、 | |
| 19903 | L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、 | |
| 17040 | 19904 | 親プロセスではチャイルドプロセスが終了するのを wait します。 |
| 17041 | 19905 | exec の項で述べたように、引数の処理は、引数の数によって異なることに |
| 17042 | 19906 | 注意してください。 |
| 17043 | 19907 | LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 |
| 17044 | 19908 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として |
| 17045 | 19909 | 起動します。 |
| 17046 | 19910 | スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし |
| 17047 | 19911 | あればパースのために引数全体がシステムコマンドシェル (これは |
| 17048 | 19912 | Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは |
| 17049 | 19913 | 異なります)に渡されます。 |
| 17050 | 19914 | シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に |
| 17051 | 19915 | 渡されます; この方がより効率的です。 |
| 19916 | Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を | |
| 19917 | 回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると | |
| 19918 | シェルにフォールバックします。 | |
| 17052 | 19919 | |
| 17053 | 19920 | =begin original |
| 17054 | 19921 | |
| 17055 | 19922 | Perl will attempt to flush all files opened for |
| 17056 | 19923 | output before any operation that may do a fork, but this may not be |
| 17057 | 19924 | supported on some platforms (see L<perlport>). To be safe, you may need |
| 17058 | to set C<$|> ($AUTOFLUSH in English | |
| 19925 | to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) | |
| 17059 | of C<IO::Handle> | |
| 19926 | or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> | |
| 19927 | on any open handles. | |
| 17060 | 19928 | |
| 17061 | 19929 | =end original |
| 17062 | 19930 | |
| 17063 | ||
| 19931 | Perl は書き込み用に開いている全てのファイルに対して | |
| 17064 | 19932 | fork を行う前にフラッシュしようとしますが、これに対応していない |
| 17065 | 19933 | プラットフォームもあります(L<perlport> を参照してください)。 |
| 17066 | 安全のために、C<$|> (English モジュールでは | |
| 19934 | 安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは | |
| 17067 | 全ての開いているハンドルに対して | |
| 19935 | C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して | |
| 19936 | L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを | |
| 17068 | 19937 | 呼び出す必要があるかもしれません。 |
| 17069 | 19938 | |
| 17070 | 19939 | =begin original |
| 17071 | 19940 | |
| 17072 | 19941 | The return value is the exit status of the program as returned by the |
| 17073 | C<wait> call. To get the actual exit value, shift right by | |
| 19942 | L<C<wait>|/wait> call. To get the actual exit value, shift right by | |
| 17074 | below). See also L</exec>. This is I<not> what | |
| 19943 | eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what | |
| 17075 | the output from a command; for that you | |
| 19944 | you want to use to capture the output from a command; for that you | |
| 17076 | ||
| 19945 | should use merely backticks or | |
| 17077 | ||
| 19946 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in | |
| 17078 | ||
| 19947 | L<perlop/"`STRING`">. Return value of -1 indicates a failure to start | |
| 19948 | the program or an error of the L<wait(2)> system call (inspect | |
| 19949 | L<C<$!>|perlvar/$!> for the reason). | |
| 17079 | 19950 | |
| 17080 | 19951 | =end original |
| 17081 | 19952 | |
| 17082 | 返り値は、C<wait> が返すプログラムの exit 状態です。 | |
| 19953 | 返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。 | |
| 17083 | 19954 | 実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。 |
| 17084 | L</exec> も参照してください。 | |
| 19955 | L<C<exec>|/exec LIST> も参照してください。 | |
| 17085 | 19956 | これはコマンドからの出力を捕らえるために使うものI<ではありません>; |
| 17086 | 19957 | そのような用途には、L<perlop/"`STRING`"> に記述されている |
| 17087 | 逆クォートや C<qx/ | |
| 19958 | 逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。 | |
| 17088 | -1 の返り値はプログラムを開始させることに失敗したか、wait(2) | |
| 19959 | -1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)> | |
| 17089 | 19960 | システムコールがエラーを出したことを示します |
| 17090 | (理由は $! を調べてください)。 | |
| 19961 | (理由は L<C<$!>|perlvar/$!> を調べてください)。 | |
| 17091 | 19962 | |
| 17092 | 19963 | =begin original |
| 17093 | 19964 | |
| 17094 | If you'd like to make C<system> (and many other bits of | |
| 19965 | If you'd like to make L<C<system>|/system LIST> (and many other bits of | |
| 17095 | have a look at the L<autodie> pragma. | |
| 19966 | Perl) die on error, have a look at the L<autodie> pragma. | |
| 17096 | 19967 | |
| 17097 | 19968 | =end original |
| 17098 | 19969 | |
| 17099 | もし C<system> (及び Perl のその他の多くの部分) でエラー時に | |
| 19970 | もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に | |
| 17100 | 19971 | die したいなら、L<autodie> プラグマを見てみてください。 |
| 17101 | 19972 | |
| 17102 | 19973 | =begin original |
| 17103 | 19974 | |
| 17104 | Like C<exec>, C<system> allows you to lie | |
| 19975 | Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie | |
| 17105 | you use the C<system PROGRAM LIST> | |
| 19976 | to a program about its name if you use the C<system PROGRAM LIST> | |
| 19977 | syntax. Again, see L<C<exec>|/exec LIST>. | |
| 17106 | 19978 | |
| 17107 | 19979 | =end original |
| 17108 | 19980 | |
| 17109 | C<exec> と同様に、C<system> | |
| 19981 | L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも | |
| 17110 | 使うことで、プログラムに対してその名前を | |
| 19982 | C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を | |
| 17111 | ||
| 19983 | 嘘をつくことができます。 | |
| 19984 | 再び、L<C<exec>|/exec LIST> を参照してください。 | |
| 17112 | 19985 | |
| 17113 | 19986 | =begin original |
| 17114 | 19987 | |
| 17115 | 19988 | Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of |
| 17116 | C<system>, if you expect your program to terminate on | |
| 19989 | L<C<system>|/system LIST>, if you expect your program to terminate on | |
| 17117 | signals you will need to arrange to do so yourself | |
| 19990 | receipt of these signals you will need to arrange to do so yourself | |
| 17118 | value. | |
| 19991 | based on the return value. | |
| 17119 | 19992 | |
| 17120 | 19993 | =end original |
| 17121 | 19994 | |
| 17122 | C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、 | |
| 19995 | C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、 | |
| 17123 | 19996 | これらのシグナルを受信して終了させることを想定したプログラムの場合、 |
| 17124 | 19997 | 返り値を利用するように変更する必要があります。 |
| 17125 | 19998 | |
| 17126 | @args = ("command", "arg1", "arg2"); | |
| 19999 | my @args = ("command", "arg1", "arg2"); | |
| 17127 | 20000 | system(@args) == 0 |
| 17128 | or die "system @args failed: $?" | |
| 20001 | or die "system @args failed: $?"; | |
| 17129 | 20002 | |
| 17130 | 20003 | =begin original |
| 17131 | 20004 | |
| 17132 | If you'd like to manually inspect C<system>'s failure, | |
| 20005 | If you'd like to manually inspect L<C<system>|/system LIST>'s failure, | |
| 17133 | possible failure modes by inspecting | |
| 20006 | you can check all possible failure modes by inspecting | |
| 20007 | L<C<$?>|perlvar/$?> like this: | |
| 17134 | 20008 | |
| 17135 | 20009 | =end original |
| 17136 | 20010 | |
| 17137 | C<system> の失敗を手動で検査したいなら、 | |
| 20011 | L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように | |
| 17138 | ||
| 20012 | L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます: | |
| 17139 | チェックできます: | |
| 17140 | 20013 | |
| 17141 | 20014 | if ($? == -1) { |
| 17142 | 20015 | print "failed to execute: $!\n"; |
| 17143 | 20016 | } |
| 17144 | 20017 | elsif ($? & 127) { |
| 17145 | 20018 | printf "child died with signal %d, %s coredump\n", |
| 17146 | 20019 | ($? & 127), ($? & 128) ? 'with' : 'without'; |
| 17147 | 20020 | } |
| 17148 | 20021 | else { |
| 17149 | 20022 | printf "child exited with value %d\n", $? >> 8; |
| 17150 | 20023 | } |
| 17151 | 20024 | |
| 17152 | 20025 | =begin original |
| 17153 | 20026 | |
| 17154 | Alternatively, you may inspect the value of | |
| 20027 | Alternatively, you may inspect the value of | |
| 17155 | ||
| 20028 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the | |
| 20029 | L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module. | |
| 17156 | 20030 | |
| 17157 | 20031 | =end original |
| 17158 | 20032 | |
| 17159 | または、POSIX モジュールの C<W*()> 呼び出しを使って | |
| 20033 | または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って | |
| 17160 | C<${^CHILD_ERROR_NATIVE}> の値を | |
| 20034 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を | |
| 20035 | 調べることもできます。 | |
| 17161 | 20036 | |
| 17162 | 20037 | =begin original |
| 17163 | 20038 | |
| 17164 | When C<system>'s arguments are executed indirectly by | |
| 20039 | When L<C<system>|/system LIST>'s arguments are executed indirectly by | |
| 17165 | results and return codes are subject to its quirks. | |
| 20040 | the shell, results and return codes are subject to its quirks. | |
| 17166 | See L<perlop/"`STRING`"> and L</exec> for details. | |
| 20041 | See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details. | |
| 17167 | 20042 | |
| 17168 | 20043 | =end original |
| 17169 | 20044 | |
| 17170 | C<system> の引数がシェルによって間接的に実行された場合、 | |
| 20045 | L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、 | |
| 17171 | 20046 | 結果と返り値はシェルの癖によって変更されることがあります。 |
| 17172 | 詳細については L<perlop/"`STRING`"> と L</exec> を | |
| 20047 | 詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を | |
| 20048 | 参照してください。 | |
| 17173 | 20049 | |
| 17174 | 20050 | =begin original |
| 17175 | 20051 | |
| 17176 | Since C<system> does a C<fork> and | |
| 20052 | Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and | |
| 17177 | handler. See L<perlipc> for | |
| 20053 | L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for | |
| 20054 | details. | |
| 17178 | 20055 | |
| 17179 | 20056 | =end original |
| 17180 | 20057 | |
| 17181 | C<system> は C<fork> と C<wait> を行うので、 | |
| 20058 | L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、 | |
| 17182 | 受けます。 | |
| 20059 | C<SIGCHLD> ハンドラの影響を受けます。 | |
| 17183 | 20060 | 詳しくは L<perlipc> を参照してください。 |
| 17184 | 20061 | |
| 17185 | 20062 | =begin original |
| 17186 | 20063 | |
| 17187 | 20064 | Portability issues: L<perlport/system>. |
| 17188 | 20065 | |
| 17189 | 20066 | =end original |
| 17190 | 20067 | |
| 17191 | 20068 | 移植性の問題: L<perlport/system>。 |
| 17192 | 20069 | |
| 17193 | 20070 | =item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 17194 | 20071 | X<syswrite> |
| 17195 | 20072 | |
| 17196 | 20073 | =item syswrite FILEHANDLE,SCALAR,LENGTH |
| 17197 | 20074 | |
| 17198 | 20075 | =item syswrite FILEHANDLE,SCALAR |
| 17199 | 20076 | |
| 17200 | 20077 | =for Pod::Functions fixed-length unbuffered output to a filehandle |
| 17201 | 20078 | |
| 17202 | 20079 | =begin original |
| 17203 | 20080 | |
| 17204 | 20081 | Attempts to write LENGTH bytes of data from variable SCALAR to the |
| 17205 | specified FILEHANDLE, using write(2). If LENGTH is | |
| 20082 | specified FILEHANDLE, using L<write(2)>. If LENGTH is | |
| 17206 | not specified, writes whole SCALAR. It bypasses | |
| 20083 | not specified, writes whole SCALAR. It bypasses any L<PerlIO> layers | |
| 17207 | ||
| 20084 | including buffered IO (but is affected by the presence of the C<:utf8> | |
| 17208 | ||
| 20085 | layer as described later), so | |
| 17209 | ||
| 20086 | mixing this with reads (other than C<sysread)>), | |
| 17210 | ||
| 20087 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 17211 | ||
| 20088 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 20089 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause | |
| 20090 | confusion because the C<:perlio> and C<:crlf> layers usually buffer data. | |
| 20091 | Returns the number of bytes actually written, or L<C<undef>|/undef EXPR> | |
| 20092 | if there was an error (in this case the errno variable | |
| 20093 | L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the | |
| 17212 | 20094 | data available in the SCALAR after the OFFSET, only as much data as is |
| 17213 | 20095 | available will be written. |
| 17214 | 20096 | |
| 17215 | 20097 | =end original |
| 17216 | 20098 | |
| 17217 | write(2) を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの | |
| 20099 | L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの | |
| 17218 | 20100 | データの書き込みを試みます。 |
| 17219 | 20101 | LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 |
| 17220 | これは、バッファ付き IO ルーチンを通 | |
| 20102 | これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので | |
| 17221 | ( | |
| 20103 | (しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、 | |
| 17222 | ||
| 20104 | 他の入力関数 (C<sysread> 以外), | |
| 17223 | ||
| 20105 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 17224 | ||
| 20106 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
| 17225 | ||
| 20107 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません; | |
| 20108 | C<:perlio> 層と C<:crlf> 層は普通データをバッファリングするからです。 | |
| 20109 | 実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が | |
| 20110 | 返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。 | |
| 17226 | 20111 | LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 |
| 17227 | 20112 | 利用可能なデータのみが書き込まれます。 |
| 17228 | 20113 | |
| 17229 | 20114 | =begin original |
| 17230 | 20115 | |
| 17231 | 20116 | An OFFSET may be specified to write the data from some part of the |
| 17232 | 20117 | string other than the beginning. A negative OFFSET specifies writing |
| 17233 | 20118 | that many characters counting backwards from the end of the string. |
| 17234 | 20119 | If SCALAR is of length zero, you can only use an OFFSET of 0. |
| 17235 | 20120 | |
| 17236 | 20121 | =end original |
| 17237 | 20122 | |
| 17238 | 20123 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 |
| 17239 | 20124 | データを取り出して、書き込みを行なうことができます。 |
| 17240 | 20125 | OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて |
| 17241 | 20126 | 何バイト目から書き込むかを示します。 |
| 17242 | 20127 | SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。 |
| 17243 | 20128 | |
| 17244 | 20129 | =begin original |
| 17245 | 20130 | |
| 17246 | B<WARNING>: If the filehandle is marked C<:utf8>, | |
| 20131 | B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception. | |
| 17247 | encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and | |
| 17248 | return value of syswrite() are in (UTF8-encoded Unicode) characters. | |
| 17249 | 20132 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. |
| 17250 | 20133 | Alternately, if the handle is not marked with an encoding but you |
| 17251 | 20134 | attempt to write characters with code points over 255, raises an exception. |
| 17252 | See L< | |
| 20135 | See L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 20136 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma. | |
| 17253 | 20137 | |
| 17254 | 20138 | =end original |
| 17255 | 20139 | |
| 17256 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、 | |
| 20140 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
| 17257 | ||
| 20141 | C<syswrite> は例外を投げます。 | |
| 17258 | ||
| 20142 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 17259 | Unicode) 文字単位になります。 | |
| 17260 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 | |
| 17261 | 20143 | または、もしハンドルにエンコーディングが記録されていない状態で |
| 17262 | 20144 | 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 |
| 17263 | L< | |
| 20145 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 20146 | L<C<open>|/open FILEHANDLE,MODE,EXPR>, | |
| 20147 | L<open> プラグマを参照してください。 | |
| 17264 | 20148 | |
| 17265 | 20149 | =item tell FILEHANDLE |
| 17266 | 20150 | X<tell> |
| 17267 | 20151 | |
| 17268 | 20152 | =item tell |
| 17269 | 20153 | |
| 17270 | 20154 | =for Pod::Functions get current seekpointer on a filehandle |
| 17271 | 20155 | |
| 17272 | 20156 | =begin original |
| 17273 | 20157 | |
| 17274 | 20158 | Returns the current position I<in bytes> for FILEHANDLE, or -1 on |
| 17275 | 20159 | error. FILEHANDLE may be an expression whose value gives the name of |
| 17276 | 20160 | the actual filehandle. If FILEHANDLE is omitted, assumes the file |
| 17277 | 20161 | last read. |
| 17278 | 20162 | |
| 17279 | 20163 | =end original |
| 17280 | 20164 | |
| 17281 | 20165 | FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を |
| 17282 | 20166 | 返します。 |
| 17283 | 20167 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
| 17284 | FILEHANDLE が省略された場合には、 | |
| 20168 | FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて | |
| 17285 | ||
| 20169 | 調べます。 | |
| 17286 | 20170 | |
| 17287 | 20171 | =begin original |
| 17288 | 20172 | |
| 17289 | Note the | |
| 20173 | Note the emphasis on bytes: even if the filehandle has been set to operate | |
| 17290 | o | |
| 20174 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the | |
| 17291 | ||
| 20175 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 17292 | t | |
| 20176 | L<C<tell>|/tell FILEHANDLE>, and | |
| 20177 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 20178 | family of functions use byte offsets, not character offsets, | |
| 20179 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 17293 | 20180 | |
| 17294 | 20181 | =end original |
| 17295 | 20182 | |
| 17296 | ||
| 20183 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) | |
| 17297 | ||
| 20184 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 | |
| 17298 | ||
| 20185 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 17299 | ||
| 20186 | L<C<tell>|/tell FILEHANDLE>, | |
| 17300 | ||
| 20187 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 20188 | 文字オフセットではなくバイトオフセットを使います; | |
| 20189 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 17301 | 20190 | |
| 17302 | 20191 | =begin original |
| 17303 | 20192 | |
| 17304 | The return value of tell | |
| 20193 | The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams | |
| 17305 | depends on the operating system: it may return -1 or | |
| 20194 | like the STDIN depends on the operating system: it may return -1 or | |
| 17306 | tell | |
| 20195 | something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and | |
| 20196 | sockets usually returns -1. | |
| 17307 | 20197 | |
| 17308 | 20198 | =end original |
| 17309 | 20199 | |
| 17310 | STDIN のような標準ストリームに対する tell | |
| 20200 | STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は | |
| 20201 | OS に依存します: | |
| 17311 | 20202 | -1 やその他の値が返ってくるかもしれません。 |
| 17312 | パイプ、FIFO、ソケットに対して tell | |
| 20203 | パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は | |
| 20204 | -1 が返ります。 | |
| 17313 | 20205 | |
| 17314 | 20206 | =begin original |
| 17315 | 20207 | |
| 17316 | There is no C<systell> function. Use | |
| 20208 | There is no C<systell> function. Use | |
| 20209 | L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that. | |
| 17317 | 20210 | |
| 17318 | 20211 | =end original |
| 17319 | 20212 | |
| 17320 | 20213 | C<systell> 関数はありません。 |
| 17321 | 代わりに C<sysseek( | |
| 20214 | 代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> を | |
| 20215 | 使ってください。 | |
| 17322 | 20216 | |
| 17323 | 20217 | =begin original |
| 17324 | 20218 | |
| 17325 | Do not use tell | |
| 20219 | Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O | |
| 17326 | that has been manipulated by | |
| 20220 | operations) on a filehandle that has been manipulated by | |
| 17327 | ||
| 20221 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 20222 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or | |
| 20223 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions | |
| 20224 | ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not. | |
| 17328 | 20225 | |
| 17329 | 20226 | =end original |
| 17330 | 20227 | |
| 17331 | sysread | |
| 20228 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 20229 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 20230 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された | |
| 20231 | ファイルハンドルに L<C<tell>|/tell FILEHANDLE> | |
| 17332 | 20232 | (またはその他のバッファリング I/O 操作) を使わないでください。 |
| 17333 | これらの関数はバッファリングを無視しますが、tell | |
| 20233 | これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は | |
| 20234 | 違います。 | |
| 17334 | 20235 | |
| 17335 | 20236 | =item telldir DIRHANDLE |
| 17336 | 20237 | X<telldir> |
| 17337 | 20238 | |
| 17338 | 20239 | =for Pod::Functions get current seekpointer on a directory handle |
| 17339 | 20240 | |
| 17340 | 20241 | =begin original |
| 17341 | 20242 | |
| 17342 | Returns the current position of the C<readdir> | |
| 20243 | Returns the current position of the L<C<readdir>|/readdir DIRHANDLE> | |
| 17343 | Value may be given to | |
| 20244 | routines on DIRHANDLE. Value may be given to | |
| 17344 | dire | |
| 20245 | L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in | |
| 17345 | ||
| 20246 | a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats | |
| 20247 | about possible directory compaction as the corresponding system library | |
| 20248 | routine. | |
| 17346 | 20249 | |
| 17347 | 20250 | =end original |
| 17348 | 20251 | |
| 17349 | DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を | |
| 20252 | DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を | |
| 20253 | 返します。 | |
| 17350 | 20254 | 値は、そのディレクトリで特定の位置をアクセスするため、 |
| 17351 | C<seekdir> に渡すことができます。 | |
| 20255 | L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。 | |
| 17352 | C<telldir> は同名のシステムライブラリルーチンと同じく、 | |
| 20256 | L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、 | |
| 17353 | 20257 | ディレクトリ縮小時の問題が考えられます。 |
| 17354 | 20258 | |
| 17355 | 20259 | =item tie VARIABLE,CLASSNAME,LIST |
| 17356 | 20260 | X<tie> |
| 17357 | 20261 | |
| 17358 | 20262 | =for Pod::Functions +5.002 bind a variable to an object class |
| 17359 | 20263 | |
| 17360 | 20264 | =begin original |
| 17361 | 20265 | |
| 17362 | 20266 | This function binds a variable to a package class that will provide the |
| 17363 | 20267 | implementation for the variable. VARIABLE is the name of the variable |
| 17364 | 20268 | to be enchanted. CLASSNAME is the name of a class implementing objects |
| 17365 | 20269 | of correct type. Any additional arguments are passed to the |
| 17366 | 20270 | appropriate constructor |
| 17367 | 20271 | method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, |
| 17368 | 20272 | or C<TIEHASH>). Typically these are arguments such as might be passed |
| 17369 | to the | |
| 20273 | to the L<dbm_open(3)> function of C. The object returned by the | |
| 17370 | constructor is also returned by the | |
| 20274 | constructor is also returned by the | |
| 20275 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful | |
| 17371 | 20276 | if you want to access other methods in CLASSNAME. |
| 17372 | 20277 | |
| 17373 | 20278 | =end original |
| 17374 | 20279 | |
| 17375 | 20280 | この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 |
| 17376 | 20281 | VARIABLE は、魔法をかける変数の名前です。 |
| 17377 | 20282 | CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 |
| 17378 | 20283 | 他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます |
| 17379 | 20284 | (つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。 |
| 17380 | 通常、これらは、C の | |
| 20285 | 通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。 | |
| 17381 | コンストラクタで返されるオブジェクトはまた | |
| 20286 | コンストラクタで返されるオブジェクトはまた | |
| 20287 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます; | |
| 17382 | 20288 | これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。 |
| 17383 | 20289 | |
| 17384 | 20290 | =begin original |
| 17385 | 20291 | |
| 17386 | Note that functions such as C<keys> | |
| 20292 | Note that functions such as L<C<keys>|/keys HASH> and | |
| 17387 | ||
| 20293 | L<C<values>|/values HASH> may return huge lists when used on large | |
| 17388 | ||
| 20294 | objects, like DBM files. You may prefer to use the L<C<each>|/each | |
| 20295 | HASH> function to iterate over such. Example: | |
| 17389 | 20296 | |
| 17390 | 20297 | =end original |
| 17391 | 20298 | |
| 17392 | DBM ファイルのような大きなオブジェクトでは、C<keys> | |
| 20299 | DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH> や | |
| 17393 | 関数は、大きなリストを返す可能性があります。 | |
| 20300 | L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。 | |
| 17394 | そのような場合では、C<each> 関数を使って繰り返しを行なった方が | |
| 20301 | そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が | |
| 17395 | 20302 | よいかもしれません。 |
| 17396 | 20303 | 例: |
| 17397 | 20304 | |
| 17398 | 20305 | # print out history file offsets |
| 17399 | 20306 | use NDBM_File; |
| 17400 | tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); | |
| 20307 | tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); | |
| 17401 | while (($key,$val) = each %HIST) { | |
| 20308 | while (my ($key,$val) = each %HIST) { | |
| 17402 | print $key, ' = ', unpack('L',$val), "\n"; | |
| 20309 | print $key, ' = ', unpack('L', $val), "\n"; | |
| 17403 | 20310 | } |
| 17404 | untie(%HIST); | |
| 17405 | 20311 | |
| 17406 | 20312 | =begin original |
| 17407 | 20313 | |
| 17408 | 20314 | A class implementing a hash should have the following methods: |
| 17409 | 20315 | |
| 17410 | 20316 | =end original |
| 17411 | 20317 | |
| 17412 | 20318 | ハッシュを実装するクラスでは、次のようなメソッドを用意します: |
| 17413 | 20319 | |
| 17414 | 20320 | TIEHASH classname, LIST |
| 17415 | 20321 | FETCH this, key |
| 17416 | 20322 | STORE this, key, value |
| 17417 | 20323 | DELETE this, key |
| 17418 | 20324 | CLEAR this |
| 17419 | 20325 | EXISTS this, key |
| 17420 | 20326 | FIRSTKEY this |
| 17421 | 20327 | NEXTKEY this, lastkey |
| 17422 | 20328 | SCALAR this |
| 17423 | 20329 | DESTROY this |
| 17424 | 20330 | UNTIE this |
| 17425 | 20331 | |
| 17426 | 20332 | =begin original |
| 17427 | 20333 | |
| 17428 | 20334 | A class implementing an ordinary array should have the following methods: |
| 17429 | 20335 | |
| 17430 | 20336 | =end original |
| 17431 | 20337 | |
| 17432 | 20338 | 通常の配列を実装するクラスでは、次のようなメソッドを用意します: |
| 17433 | 20339 | |
| 17434 | 20340 | TIEARRAY classname, LIST |
| 17435 | 20341 | FETCH this, key |
| 17436 | 20342 | STORE this, key, value |
| 17437 | 20343 | FETCHSIZE this |
| 17438 | 20344 | STORESIZE this, count |
| 17439 | 20345 | CLEAR this |
| 17440 | 20346 | PUSH this, LIST |
| 17441 | 20347 | POP this |
| 17442 | 20348 | SHIFT this |
| 17443 | 20349 | UNSHIFT this, LIST |
| 17444 | 20350 | SPLICE this, offset, length, LIST |
| 17445 | 20351 | EXTEND this, count |
| 17446 | 20352 | DELETE this, key |
| 17447 | 20353 | EXISTS this, key |
| 17448 | 20354 | DESTROY this |
| 17449 | 20355 | UNTIE this |
| 17450 | 20356 | |
| 17451 | 20357 | =begin original |
| 17452 | 20358 | |
| 17453 | 20359 | A class implementing a filehandle should have the following methods: |
| 17454 | 20360 | |
| 17455 | 20361 | =end original |
| 17456 | 20362 | |
| 17457 | 20363 | ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します: |
| 17458 | 20364 | |
| 17459 | 20365 | TIEHANDLE classname, LIST |
| 17460 | 20366 | READ this, scalar, length, offset |
| 17461 | 20367 | READLINE this |
| 17462 | 20368 | GETC this |
| 17463 | 20369 | WRITE this, scalar, length, offset |
| 17464 | 20370 | PRINT this, LIST |
| 17465 | 20371 | PRINTF this, format, LIST |
| 17466 | 20372 | BINMODE this |
| 17467 | 20373 | EOF this |
| 17468 | 20374 | FILENO this |
| 17469 | 20375 | SEEK this, position, whence |
| 17470 | 20376 | TELL this |
| 17471 | 20377 | OPEN this, mode, LIST |
| 17472 | 20378 | CLOSE this |
| 17473 | 20379 | DESTROY this |
| 17474 | 20380 | UNTIE this |
| 17475 | 20381 | |
| 17476 | 20382 | =begin original |
| 17477 | 20383 | |
| 17478 | 20384 | A class implementing a scalar should have the following methods: |
| 17479 | 20385 | |
| 17480 | 20386 | =end original |
| 17481 | 20387 | |
| 17482 | 20388 | スカラ変数を実装するクラスでは、次のようなメソッドを用意します: |
| 17483 | 20389 | |
| 17484 | 20390 | TIESCALAR classname, LIST |
| 17485 | 20391 | FETCH this, |
| 17486 | 20392 | STORE this, value |
| 17487 | 20393 | DESTROY this |
| 17488 | 20394 | UNTIE this |
| 17489 | 20395 | |
| 17490 | 20396 | =begin original |
| 17491 | 20397 | |
| 17492 | 20398 | Not all methods indicated above need be implemented. See L<perltie>, |
| 17493 | 20399 | L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>. |
| 17494 | 20400 | |
| 17495 | 20401 | =end original |
| 17496 | 20402 | |
| 17497 | 20403 | 上記の全てのメソッドを実装する必要はありません。 |
| 17498 | 20404 | L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, |
| 17499 | 20405 | L<Tie::Handle> を参照してください。 |
| 17500 | 20406 | |
| 17501 | 20407 | =begin original |
| 17502 | 20408 | |
| 17503 | Unlike C<dbmopen> | |
| 20409 | Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the | |
| 17504 | ||
| 20410 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not | |
| 17505 | ||
| 20411 | L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a | |
| 20412 | module for you; you need to do that explicitly yourself. See L<DB_File> | |
| 20413 | or the L<Config> module for interesting | |
| 20414 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations. | |
| 17506 | 20415 | |
| 17507 | 20416 | =end original |
| 17508 | 20417 | |
| 17509 | C<dbmopen> と違い、 | |
| 20418 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、 | |
| 17510 | C< | |
| 20419 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを | |
| 17511 | C< | |
| 20420 | L<C<use>|/use Module VERSION LIST> したり | |
| 17512 | ||
| 20421 | L<C<require>|/require VERSION> したりしません; | |
| 20422 | 自分で明示的に行う必要があります。 | |
| 20423 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については | |
| 20424 | L<DB_File> や L<Config> モジュールを参照してください。 | |
| 17513 | 20425 | |
| 17514 | 20426 | =begin original |
| 17515 | 20427 | |
| 17516 | For further details see L<perltie>, L< | |
| 20428 | For further details see L<perltie>, L<C<tied>|/tied VARIABLE>. | |
| 17517 | 20429 | |
| 17518 | 20430 | =end original |
| 17519 | 20431 | |
| 17520 | 更なる詳細については L<perltie> や L< | |
| 20432 | 更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を | |
| 20433 | 参照してください。 | |
| 17521 | 20434 | |
| 17522 | 20435 | =item tied VARIABLE |
| 17523 | 20436 | X<tied> |
| 17524 | 20437 | |
| 17525 | 20438 | =for Pod::Functions get a reference to the object underlying a tied variable |
| 17526 | 20439 | |
| 17527 | 20440 | =begin original |
| 17528 | 20441 | |
| 17529 | 20442 | Returns a reference to the object underlying VARIABLE (the same value |
| 17530 | that was originally returned by the | |
| 20443 | that was originally returned by the | |
| 20444 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable | |
| 17531 | 20445 | to a package.) Returns the undefined value if VARIABLE isn't tied to a |
| 17532 | 20446 | package. |
| 17533 | 20447 | |
| 17534 | 20448 | =end original |
| 17535 | 20449 | |
| 17536 | 20450 | VARIABLE の基となるオブジェクトへのリファレンスを返します |
| 17537 | (変数をパッケージに結びつけるために | |
| 20451 | (変数をパッケージに結びつけるために | |
| 20452 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの | |
| 17538 | 20453 | 返り値と同じものです)。 |
| 17539 | 20454 | VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。 |
| 17540 | 20455 | |
| 17541 | 20456 | =item time |
| 17542 | 20457 | X<time> X<epoch> |
| 17543 | 20458 | |
| 17544 | 20459 | =for Pod::Functions return number of seconds since 1970 |
| 17545 | 20460 | |
| 17546 | 20461 | =begin original |
| 17547 | 20462 | |
| 17548 | 20463 | Returns the number of non-leap seconds since whatever time the system |
| 17549 | considers to be the epoch, suitable for feeding to | |
| 20464 | considers to be the epoch, suitable for feeding to | |
| 17550 | C< | |
| 20465 | L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most | |
| 20466 | systems the epoch is 00:00:00 UTC, January 1, 1970; | |
| 17551 | 20467 | a prominent exception being Mac OS Classic which uses 00:00:00, January 1, |
| 17552 | 20468 | 1904 in the current local time zone for its epoch. |
| 17553 | 20469 | |
| 17554 | 20470 | =end original |
| 17555 | 20471 | |
| 17556 | C<gmtime> や C<localtime> への入力形式に | |
| 20472 | L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に | |
| 17557 | システムが紀元と考える時点からの連続秒数を返します。 | |
| 20473 | 合っている、システムが紀元と考える時点からの連続秒数を返します。 | |
| 17558 | 20474 | ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です; |
| 17559 | 20475 | 特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの |
| 17560 | 20476 | 1904 年 1 月 1 日 00:00:00 を紀元として使います。 |
| 17561 | 20477 | |
| 17562 | 20478 | =begin original |
| 17563 | 20479 | |
| 17564 | 20480 | For measuring time in better granularity than one second, use the |
| 17565 | 20481 | L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or, |
| 17566 | if you have gettimeofday(2), you may be able to use the | |
| 20482 | if you have L<gettimeofday(2)>, you may be able to use the | |
| 17567 | interface of Perl. See L<perlfaq8> | |
| 20483 | L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8> | |
| 20484 | for details. | |
| 17568 | 20485 | |
| 17569 | 20486 | =end original |
| 17570 | 20487 | |
| 17571 | 20488 | 1 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では |
| 17572 | 20489 | CPANから)の L<Time::HiRes> モジュールを使うか、 |
| 17573 | gettimeofday(2) があるなら、Perl の | |
| 20490 | L<gettimeofday(2)> があるなら、Perl の | |
| 17574 | 使ってください。 | |
| 20491 | L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。 | |
| 17575 | 20492 | 詳しくは L<perlfaq8> を参照してください。 |
| 17576 | 20493 | |
| 17577 | 20494 | =begin original |
| 17578 | 20495 | |
| 17579 | 20496 | For date and time processing look at the many related modules on CPAN. |
| 17580 | 20497 | For a comprehensive date and time representation look at the |
| 17581 | 20498 | L<DateTime> module. |
| 17582 | 20499 | |
| 17583 | 20500 | =end original |
| 17584 | 20501 | |
| 17585 | 20502 | 日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。 |
| 17586 | 20503 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを |
| 17587 | 20504 | 参照してください。 |
| 17588 | 20505 | |
| 17589 | 20506 | =item times |
| 17590 | 20507 | X<times> |
| 17591 | 20508 | |
| 17592 | 20509 | =for Pod::Functions return elapsed time for self and child processes |
| 17593 | 20510 | |
| 17594 | 20511 | =begin original |
| 17595 | 20512 | |
| 17596 | 20513 | Returns a four-element list giving the user and system times in |
| 17597 | 20514 | seconds for this process and any exited children of this process. |
| 17598 | 20515 | |
| 17599 | 20516 | =end original |
| 17600 | 20517 | |
| 17601 | 20518 | 現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を |
| 17602 | 20519 | 秒で示した、4 要素のリスト値を返します。 |
| 17603 | 20520 | |
| 17604 | ($user,$system,$cuser,$csystem) = times; | |
| 20521 | my ($user,$system,$cuser,$csystem) = times; | |
| 17605 | 20522 | |
| 17606 | 20523 | =begin original |
| 17607 | 20524 | |
| 17608 | In scalar context, C<times> returns C<$user>. | |
| 20525 | In scalar context, L<C<times>|/times> returns C<$user>. | |
| 17609 | 20526 | |
| 17610 | 20527 | =end original |
| 17611 | 20528 | |
| 17612 | スカラコンテキストでは、C<times> は C<$user> を返します。 | |
| 20529 | スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。 | |
| 17613 | 20530 | |
| 17614 | 20531 | =begin original |
| 17615 | 20532 | |
| 17616 | 20533 | Children's times are only included for terminated children. |
| 17617 | 20534 | |
| 17618 | 20535 | =end original |
| 17619 | 20536 | |
| 17620 | 20537 | 子プロセスに対する times は、終了した子プロセスのみ含められます。 |
| 17621 | 20538 | |
| 17622 | 20539 | =begin original |
| 17623 | 20540 | |
| 17624 | 20541 | Portability issues: L<perlport/times>. |
| 17625 | 20542 | |
| 17626 | 20543 | =end original |
| 17627 | 20544 | |
| 17628 | 20545 | 移植性の問題: L<perlport/times>。 |
| 17629 | 20546 | |
| 17630 | 20547 | =item tr/// |
| 17631 | 20548 | |
| 17632 | 20549 | =for Pod::Functions transliterate a string |
| 17633 | 20550 | |
| 17634 | 20551 | =begin original |
| 17635 | 20552 | |
| 17636 | The transliteration operator. Same as | |
| 20553 | The transliteration operator. Same as | |
| 17637 | L< | |
| 20554 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See | |
| 20555 | L<perlop/"Quote-Like Operators">. | |
| 17638 | 20556 | |
| 17639 | 20557 | =end original |
| 17640 | 20558 | |
| 17641 | 20559 | 文字変換演算子です。 |
| 17642 | C<y/ | |
| 20560 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。 | |
| 17643 | L<perlop/"Quote | |
| 20561 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
| 17644 | 20562 | |
| 17645 | 20563 | =item truncate FILEHANDLE,LENGTH |
| 17646 | 20564 | X<truncate> |
| 17647 | 20565 | |
| 17648 | 20566 | =item truncate EXPR,LENGTH |
| 17649 | 20567 | |
| 17650 | 20568 | =for Pod::Functions shorten a file |
| 17651 | 20569 | |
| 17652 | 20570 | =begin original |
| 17653 | 20571 | |
| 17654 | 20572 | Truncates the file opened on FILEHANDLE, or named by EXPR, to the |
| 17655 | 20573 | specified length. Raises an exception if truncate isn't implemented |
| 17656 | on your system. Returns true if successful, C<undef> | |
| 20574 | on your system. Returns true if successful, L<C<undef>|/undef EXPR> on | |
| 20575 | error. | |
| 17657 | 20576 | |
| 17658 | 20577 | =end original |
| 17659 | 20578 | |
| 17660 | 20579 | FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、 |
| 17661 | 20580 | 指定した長さに切り詰めます。 |
| 17662 | 20581 | システム上に truncate が実装されていなければ、例外が発生します。 |
| 17663 | 成功すれば真を、エラー時には C<undef> を返します。 | |
| 20582 | 成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。 | |
| 17664 | 20583 | |
| 17665 | 20584 | =begin original |
| 17666 | 20585 | |
| 17667 | 20586 | The behavior is undefined if LENGTH is greater than the length of the |
| 17668 | 20587 | file. |
| 17669 | 20588 | |
| 17670 | 20589 | =end original |
| 17671 | 20590 | |
| 17672 | 20591 | LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。 |
| 17673 | 20592 | |
| 17674 | 20593 | =begin original |
| 17675 | 20594 | |
| 17676 | 20595 | The position in the file of FILEHANDLE is left unchanged. You may want to |
| 17677 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the | |
| 20596 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the | |
| 20597 | file. | |
| 17678 | 20598 | |
| 17679 | 20599 | =end original |
| 17680 | 20600 | |
| 17681 | 20601 | FILEHANDLE のファイルの位置は変わりません。 |
| 17682 | 20602 | ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を |
| 17683 | 20603 | 呼び出したいかもしれません。 |
| 17684 | 20604 | |
| 17685 | 20605 | =begin original |
| 17686 | 20606 | |
| 17687 | 20607 | Portability issues: L<perlport/truncate>. |
| 17688 | 20608 | |
| 17689 | 20609 | =end original |
| 17690 | 20610 | |
| 17691 | 20611 | 移植性の問題: L<perlport/truncate>。 |
| 17692 | 20612 | |
| 17693 | 20613 | =item uc EXPR |
| 17694 | 20614 | X<uc> X<uppercase> X<toupper> |
| 17695 | 20615 | |
| 17696 | 20616 | =item uc |
| 17697 | 20617 | |
| 17698 | 20618 | =for Pod::Functions return upper-case version of a string |
| 17699 | 20619 | |
| 17700 | 20620 | =begin original |
| 17701 | 20621 | |
| 17702 | Returns an uppercased version of EXPR. | |
| 20622 | Returns an uppercased version of EXPR. If EXPR is omitted, uses | |
| 17703 | ||
| 20623 | L<C<$_>|perlvar/$_>. | |
| 17704 | It does not attempt to do titlecase mapping on initial letters. See | |
| 17705 | L</ucfirst> for that. | |
| 17706 | 20624 | |
| 17707 | 20625 | =end original |
| 17708 | 20626 | |
| 17709 | EXPR | |
| 20627 | EXPR の大文字版を返します。 | |
| 17710 | ||
| 20628 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 17711 | 実装する内部関数です。 | |
| 17712 | 先頭文字の タイトル文字マッピングは試みません。 | |
| 17713 | このためには L</ucfirst> を参照してください。 | |
| 17714 | 20629 | |
| 20630 | my $str = uc("Perl is GREAT"); # "PERL IS GREAT" | |
| 20631 | ||
| 17715 | 20632 | =begin original |
| 17716 | 20633 | |
| 17717 | ||
| 20634 | This function behaves the same way under various pragmas, such as in a locale, | |
| 20635 | as L<C<lc>|/lc EXPR> does. | |
| 17718 | 20636 | |
| 17719 | 20637 | =end original |
| 17720 | 20638 | |
| 17721 | ||
| 20639 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
| 20640 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 17722 | 20641 | |
| 17723 | 20642 | =begin original |
| 17724 | 20643 | |
| 17725 | ||
| 20644 | If you want titlecase mapping on initial letters see | |
| 17726 | ||
| 20645 | L<C<ucfirst>|/ucfirst EXPR> instead. | |
| 17727 | 20646 | |
| 17728 | 20647 | =end original |
| 17729 | 20648 | |
| 17730 | ||
| 20649 | 最初の文字のタイトル文字マッピングがほしい場合は、 | |
| 17731 | L</ | |
| 20650 | 代わりに L<C<ucfirst>|/ucfirst EXPR> を使ってください。 | |
| 17732 | 20651 | |
| 20652 | =begin original | |
| 20653 | ||
| 20654 | B<Note:> This is the internal function implementing the | |
| 20655 | L<C<\U>|perlop/"Quote and Quote-like Operators"> escape in double-quoted | |
| 20656 | strings. | |
| 20657 | ||
| 20658 | =end original | |
| 20659 | ||
| 20660 | B<注意:> これは、ダブルクォート文字列における、 | |
| 20661 | L<C<\U>|perlop/"Quote and Quote-like Operators"> エスケープを | |
| 20662 | 実装する内部関数です。 | |
| 20663 | ||
| 20664 | my $str = "Perl is \Ugreat\E"; # "Perl is GREAT" | |
| 20665 | ||
| 17733 | 20666 | =item ucfirst EXPR |
| 17734 | 20667 | X<ucfirst> X<uppercase> |
| 17735 | 20668 | |
| 17736 | 20669 | =item ucfirst |
| 17737 | 20670 | |
| 17738 | =for Pod::Functions return a string with | |
| 20671 | =for Pod::Functions return a string with the first letter in upper case | |
| 17739 | 20672 | |
| 17740 | 20673 | =begin original |
| 17741 | 20674 | |
| 17742 | Returns the value of EXPR with the first character in uppercase | |
| 20675 | Returns the value of EXPR with the B<first> character in uppercase | |
| 17743 | ( | |
| 20676 | (Unicode calls this titlecase). If EXPR is omitted, C<ucfirst> uses L<C<$_>|perlvar/$_>. | |
| 17744 | the C<\u> escape in double-quoted strings. | |
| 17745 | 20677 | |
| 17746 | 20678 | =end original |
| 17747 | 20679 | |
| 17748 | 最初の文字だけを大文字 | |
| 20680 | B<最初の> 文字だけを大文字(Unicode ではこれをタイトル文字と呼びます)にした、 | |
| 17749 | ||
| 20681 | EXPR を返します。 | |
| 17750 | ||
| 20682 | EXPR が省略されると、C<ucfirst> は L<C<$_>|perlvar/$_> を使います。 | |
| 17751 | 実装する内部関数です。 | |
| 17752 | 20683 | |
| 20684 | my $str = ucfirst("hello world!"); # "Hello world!" | |
| 20685 | ||
| 17753 | 20686 | =begin original |
| 17754 | 20687 | |
| 17755 | ||
| 20688 | This function behaves the same way under various pragmas, such as in a locale, | |
| 20689 | as L<C<lc>|/lc EXPR> does. | |
| 17756 | 20690 | |
| 17757 | 20691 | =end original |
| 17758 | 20692 | |
| 17759 | ||
| 20693 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
| 20694 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 17760 | 20695 | |
| 17761 | 20696 | =begin original |
| 17762 | 20697 | |
| 17763 | This | |
| 20698 | B<Note:> This is the internal function implementing the C<\u> escape in | |
| 17764 | ||
| 20699 | double-quoted strings. | |
| 17765 | 20700 | |
| 17766 | 20701 | =end original |
| 17767 | 20702 | |
| 17768 | こ | |
| 20703 | B<注意:> これは、ダブルクォート文字列における、C<\u> エスケープを | |
| 17769 | ||
| 20704 | 実装する内部関数です。 | |
| 17770 | 20705 | |
| 20706 | my $str = "\uperl\E is great"; # "Perl is great" | |
| 20707 | ||
| 17771 | 20708 | =item umask EXPR |
| 17772 | 20709 | X<umask> |
| 17773 | 20710 | |
| 17774 | 20711 | =item umask |
| 17775 | 20712 | |
| 17776 | 20713 | =for Pod::Functions set file creation mode mask |
| 17777 | 20714 | |
| 17778 | 20715 | =begin original |
| 17779 | 20716 | |
| 17780 | 20717 | Sets the umask for the process to EXPR and returns the previous value. |
| 17781 | 20718 | If EXPR is omitted, merely returns the current umask. |
| 17782 | 20719 | |
| 17783 | 20720 | =end original |
| 17784 | 20721 | |
| 17785 | 20722 | 現在のプロセスの umask を EXPR に設定し、以前の値を返します。 |
| 17786 | 20723 | EXPR が省略されると、単にその時点の umask の値を返します。 |
| 17787 | 20724 | |
| 17788 | 20725 | =begin original |
| 17789 | 20726 | |
| 17790 | 20727 | The Unix permission C<rwxr-x---> is represented as three sets of three |
| 17791 | 20728 | bits, or three octal digits: C<0750> (the leading 0 indicates octal |
| 17792 | and isn't one of the digits). The C<umask> value is such | |
| 20729 | and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such | |
| 17793 | representing disabled permissions bits. The permission (or | |
| 20730 | a number representing disabled permissions bits. The permission (or | |
| 17794 | values you pass C<mkdir> | |
| 20731 | "mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or | |
| 17795 | ||
| 20732 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your | |
| 17796 | ||
| 20733 | umask, so even if you tell | |
| 17797 | pe | |
| 20734 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with | |
| 17798 | ||
| 20735 | permissions C<0777>, if your umask is C<0022>, then the file will | |
| 17799 | ||
| 20736 | actually be created with permissions C<0755>. If your | |
| 17800 | C< | |
| 20737 | L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't | |
| 20738 | read, write, or execute), then passing | |
| 20739 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a | |
| 20740 | file with mode C<0640> (because C<0666 &~ 027> is C<0640>). | |
| 17801 | 20741 | |
| 17802 | 20742 | =end original |
| 17803 | 20743 | |
| 17804 | 20744 | Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、 |
| 17805 | 20745 | または 3 桁の 8 進数として表現されます: |
| 17806 | 20746 | C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。 |
| 17807 | C<umask> の値は無効にするパーミッションビットのこのような | |
| 20747 | L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような | |
| 17808 | ||
| 20748 | 数値表現です。 | |
| 17809 | ||
| 20749 | L<C<mkdir>|/mkdir FILENAME,MODE> や | |
| 20750 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション | |
| 20751 | (または「モード」)の値は umask で修正され、たとえ | |
| 20752 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで | |
| 17810 | 20753 | ファイルを作るように指定しても、umask が C<0022> なら、 |
| 17811 | 20754 | 結果としてファイルは C<0755> のパーミッションで作成されます。 |
| 17812 | C<umask> が C<0027> (グループは書き込めない; その他は読み | |
| 20755 | L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、 | |
| 17813 | 実行できない) のとき | |
| 20756 | 書き込み、実行できない) のとき | |
| 20757 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、 | |
| 17814 | 20758 | ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。 |
| 17815 | 20759 | |
| 17816 | 20760 | =begin original |
| 17817 | 20761 | |
| 17818 | 20762 | Here's some advice: supply a creation mode of C<0666> for regular |
| 17819 | files (in C<sysopen>) and one of | |
| 20763 | files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of | |
| 17820 | C< | |
| 20764 | C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and | |
| 20765 | executable files. This gives users the freedom of | |
| 17821 | 20766 | choice: if they want protected files, they might choose process umasks |
| 17822 | 20767 | of C<022>, C<027>, or even the particularly antisocial mask of C<077>. |
| 17823 | 20768 | Programs should rarely if ever make policy decisions better left to |
| 17824 | 20769 | the user. The exception to this is when writing files that should be |
| 17825 | kept private: mail files, web browser cookies, | |
| 20770 | kept private: mail files, web browser cookies, F<.rhosts> files, and | |
| 17826 | 20771 | so on. |
| 17827 | 20772 | |
| 17828 | 20773 | =end original |
| 17829 | 20774 | |
| 17830 | 以下は助言です: 作成モードとして、 | |
| 20775 | 以下は助言です: 作成モードとして、 | |
| 17831 | C< | |
| 20776 | (L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは | |
| 20777 | C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは | |
| 20778 | C<0777> を指定しましょう。 | |
| 17832 | 20779 | これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、 |
| 17833 | 20780 | プロセスの umask として C<022>, C<027>, あるいは特に非社交的な |
| 17834 | 20781 | C<077> を選択できます。 |
| 17835 | 20782 | プログラムがユーザーより適切なポリシー選択ができることは稀です。 |
| 17836 | 20783 | 例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、 |
| 17837 | ||
| 20784 | F<.rhosts> ファイルなど)を書く場合です。 | |
| 17838 | 20785 | |
| 17839 | 20786 | =begin original |
| 17840 | 20787 | |
| 17841 | If umask(2) is not implemented on your system and you are trying to | |
| 20788 | If L<umask(2)> is not implemented on your system and you are trying to | |
| 17842 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), | |
| 20789 | restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>), | |
| 17843 | raises an exception. If umask(2) is not implemented and you are | |
| 20790 | raises an exception. If L<umask(2)> is not implemented and you are | |
| 17844 | not trying to restrict access for yourself, returns | |
| 20791 | not trying to restrict access for yourself, returns | |
| 20792 | L<C<undef>|/undef EXPR>. | |
| 17845 | 20793 | |
| 17846 | 20794 | =end original |
| 17847 | 20795 | |
| 17848 | umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを | |
| 20796 | L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを | |
| 17849 | 20797 | 制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。 |
| 17850 | umask(2) が実装されていないシステムで、自分自身へのアクセスは | |
| 20798 | L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは | |
| 17851 | 制限しようとしなかった場合、C<undef> を返します。 | |
| 20799 | 制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。 | |
| 17852 | 20800 | |
| 17853 | 20801 | =begin original |
| 17854 | 20802 | |
| 17855 | 20803 | Remember that a umask is a number, usually given in octal; it is I<not> a |
| 17856 | string of octal digits. See also L</oct>, if all you have | |
| 20804 | string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have | |
| 20805 | is a string. | |
| 17857 | 20806 | |
| 17858 | 20807 | =end original |
| 17859 | 20808 | |
| 17860 | 20809 | umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の |
| 17861 | 20810 | 文字列 I<ではありません>。 |
| 17862 | 文字列しかない場合、 L</oct> も参照してください。 | |
| 20811 | 文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。 | |
| 17863 | 20812 | |
| 17864 | 20813 | =begin original |
| 17865 | 20814 | |
| 17866 | 20815 | Portability issues: L<perlport/umask>. |
| 17867 | 20816 | |
| 17868 | 20817 | =end original |
| 17869 | 20818 | |
| 17870 | 20819 | 移植性の問題: L<perlport/umask>。 |
| 17871 | 20820 | |
| 17872 | 20821 | =item undef EXPR |
| 17873 | 20822 | X<undef> X<undefine> |
| 17874 | 20823 | |
| 17875 | 20824 | =item undef |
| 17876 | 20825 | |
| 17877 | 20826 | =for Pod::Functions remove a variable or function definition |
| 17878 | 20827 | |
| 17879 | 20828 | =begin original |
| 17880 | 20829 | |
| 17881 | 20830 | Undefines the value of EXPR, which must be an lvalue. Use only on a |
| 17882 | 20831 | scalar value, an array (using C<@>), a hash (using C<%>), a subroutine |
| 17883 | 20832 | (using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}> |
| 17884 | 20833 | will probably not do what you expect on most predefined variables or |
| 17885 | DBM list values, so don't do that; see L< | |
| 20834 | DBM list values, so don't do that; see L<C<delete>|/delete EXPR>. | |
| 17886 | undefined value. | |
| 20835 | Always returns the undefined value. | |
| 20836 | You can omit the EXPR, in which case nothing is | |
| 17887 | 20837 | undefined, but you still get an undefined value that you could, for |
| 17888 | 20838 | instance, return from a subroutine, assign to a variable, or pass as a |
| 17889 | 20839 | parameter. Examples: |
| 17890 | 20840 | |
| 17891 | 20841 | =end original |
| 17892 | 20842 | |
| 17893 | 20843 | 左辺値である EXPR の値を未定義にします。 |
| 17894 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) | |
| 20844 | スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った) | |
| 17895 | 20845 | サブルーチン、(C<*> を使った)型グロブだけに使用します。 |
| 17896 | 20846 | 特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても |
| 17897 | 20847 | おそらく期待通りの結果にはなりませんから、しないでください; |
| 17898 | L</delete> を参照してください。 | |
| 20848 | L<C<delete>|/delete EXPR> を参照してください。 | |
| 17899 | 20849 | 常に未定義値を返します。 |
| 17900 | 20850 | EXPR は省略することができ、その場合には何も未定義にされませんが |
| 17901 | 20851 | 未定義値は返されますので、それをたとえば、 |
| 17902 | 20852 | サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。 |
| 17903 | 20853 | 例: |
| 17904 | 20854 | |
| 17905 | 20855 | undef $foo; |
| 17906 | 20856 | undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'}; |
| 17907 | 20857 | undef @ary; |
| 17908 | 20858 | undef %hash; |
| 17909 | 20859 | undef &mysub; |
| 17910 | 20860 | undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc. |
| 17911 | 20861 | return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it; |
| 17912 | 20862 | select undef, undef, undef, 0.25; |
| 17913 | ($ | |
| 20863 | my ($x, $y, undef, $z) = foo(); # Ignore third value returned | |
| 17914 | 20864 | |
| 17915 | 20865 | =begin original |
| 17916 | 20866 | |
| 17917 | 20867 | Note that this is a unary operator, not a list operator. |
| 17918 | 20868 | |
| 17919 | 20869 | =end original |
| 17920 | 20870 | |
| 17921 | 20871 | これはリスト演算子ではなく、単項演算子であることに注意してください。 |
| 17922 | 20872 | |
| 17923 | 20873 | =item unlink LIST |
| 17924 | 20874 | X<unlink> X<delete> X<remove> X<rm> X<del> |
| 17925 | 20875 | |
| 17926 | 20876 | =item unlink |
| 17927 | 20877 | |
| 17928 | 20878 | =for Pod::Functions remove one link to a file |
| 17929 | 20879 | |
| 17930 | 20880 | =begin original |
| 17931 | 20881 | |
| 17932 | 20882 | Deletes a list of files. On success, it returns the number of files |
| 17933 | it successfully deleted. On failure, it returns false and sets | |
| 20883 | it successfully deleted. On failure, it returns false and sets | |
| 17934 | (errno): | |
| 20884 | L<C<$!>|perlvar/$!> (errno): | |
| 17935 | 20885 | |
| 17936 | 20886 | =end original |
| 17937 | 20887 | |
| 17938 | 20888 | LIST に含まれるファイルを削除します。 |
| 17939 | 20889 | 成功時は削除に成功したファイルの数を返します。 |
| 17940 | 失敗時は偽を返して C<$!> (error) をセットします: | |
| 20890 | 失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします: | |
| 17941 | 20891 | |
| 17942 | 20892 | my $unlinked = unlink 'a', 'b', 'c'; |
| 17943 | 20893 | unlink @goners; |
| 17944 | 20894 | unlink glob "*.bak"; |
| 17945 | 20895 | |
| 17946 | 20896 | =begin original |
| 17947 | 20897 | |
| 17948 | On error, C<unlink> will not tell you which files it | |
| 20898 | On error, L<C<unlink>|/unlink LIST> will not tell you which files it | |
| 20899 | could not remove. | |
| 17949 | 20900 | If you want to know which files you could not remove, try them one |
| 17950 | 20901 | at a time: |
| 17951 | 20902 | |
| 17952 | 20903 | =end original |
| 17953 | 20904 | |
| 17954 | エラーの場合、C<unlink> はどのファイルが削除できなかったかを | |
| 20905 | エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを | |
| 20906 | 知らせません。 | |
| 17955 | 20907 | どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください: |
| 17956 | 20908 | |
| 17957 | 20909 | foreach my $file ( @goners ) { |
| 17958 | 20910 | unlink $file or warn "Could not unlink $file: $!"; |
| 17959 | 20911 | } |
| 17960 | 20912 | |
| 17961 | 20913 | =begin original |
| 17962 | 20914 | |
| 17963 | Note: C<unlink> will not attempt to delete directories | |
| 20915 | Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories | |
| 20916 | unless you are | |
| 17964 | 20917 | superuser and the B<-U> flag is supplied to Perl. Even if these |
| 17965 | 20918 | conditions are met, be warned that unlinking a directory can inflict |
| 17966 | damage on your filesystem. Finally, using C<unlink> | |
| 20919 | damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on | |
| 17967 | not supported on many operating systems. Use | |
| 20920 | directories is not supported on many operating systems. Use | |
| 20921 | L<C<rmdir>|/rmdir FILENAME> instead. | |
| 17968 | 20922 | |
| 17969 | 20923 | =end original |
| 17970 | 20924 | |
| 17971 | 注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、 | |
| 20925 | 注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、 | |
| 17972 | C<unlink> はディレクトリを削除しようとすることはありません。 | |
| 20926 | L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。 | |
| 17973 | 20927 | この条件にあう場合にも、ディレクトリの削除は、 |
| 17974 | 20928 | ファイルシステムに多大な損害を与える可能性があります。 |
| 17975 | 最後に、C<unlink> をディレクトリに使うのはほとんどの OS では | |
| 20929 | 最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では | |
| 17976 | 20930 | 対応していません。 |
| 17977 | 代わりに C<rmdir> を使ってください。 | |
| 20931 | 代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。 | |
| 17978 | 20932 | |
| 17979 | 20933 | =begin original |
| 17980 | 20934 | |
| 17981 | If LIST is omitted, C<unlink> uses C<$_>. | |
| 20935 | If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>. | |
| 17982 | 20936 | |
| 17983 | 20937 | =end original |
| 17984 | 20938 | |
| 17985 | LIST が省略されると、C<unlink> は C<$_> を | |
| 20939 | LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を | |
| 20940 | 使います。 | |
| 17986 | 20941 | |
| 17987 | 20942 | =item unpack TEMPLATE,EXPR |
| 17988 | 20943 | X<unpack> |
| 17989 | 20944 | |
| 17990 | 20945 | =item unpack TEMPLATE |
| 17991 | 20946 | |
| 17992 | 20947 | =for Pod::Functions convert binary structure into normal perl variables |
| 17993 | 20948 | |
| 17994 | 20949 | =begin original |
| 17995 | 20950 | |
| 17996 | C<unpack> does the reverse of | |
| 20951 | L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of | |
| 20952 | L<C<pack>|/pack TEMPLATE,LIST>: it takes a string | |
| 17997 | 20953 | and expands it out into a list of values. |
| 17998 | 20954 | (In scalar context, it returns merely the first value produced.) |
| 17999 | 20955 | |
| 18000 | 20956 | =end original |
| 18001 | 20957 | |
| 18002 | C<unpack> は C<pack> の逆を | |
| 20958 | L<C<unpack>|/unpack TEMPLATE,EXPR> は L<C<pack>|/pack TEMPLATE,LIST> の逆を | |
| 20959 | 行ないます: 構造体を表わす文字列をとり、 | |
| 18003 | 20960 | リスト値に展開し、その配列値を返します。 |
| 18004 | 20961 | (スカラコンテキストでは、単に最初の値を返します。) |
| 18005 | 20962 | |
| 18006 | 20963 | =begin original |
| 18007 | 20964 | |
| 18008 | If EXPR is omitted, unpacks the C<$_> string. | |
| 20965 | If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string. | |
| 18009 | 20966 | See L<perlpacktut> for an introduction to this function. |
| 18010 | 20967 | |
| 18011 | 20968 | =end original |
| 18012 | 20969 | |
| 18013 | EXPR が省略されると、C<$_> の文字列を unpack します。 | |
| 20970 | EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。 | |
| 18014 | 20971 | この関数の説明については L<perlpacktut> を参照してください。 |
| 18015 | 20972 | |
| 18016 | 20973 | =begin original |
| 18017 | 20974 | |
| 18018 | 20975 | The string is broken into chunks described by the TEMPLATE. Each chunk |
| 18019 | 20976 | is converted separately to a value. Typically, either the string is a result |
| 18020 | of C<pack>, or the characters of the string | |
| 20977 | of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string | |
| 18021 | kind. | |
| 20978 | represent a C structure of some kind. | |
| 18022 | 20979 | |
| 18023 | 20980 | =end original |
| 18024 | 20981 | |
| 18025 | 20982 | 文字列は TEMPLATE で示された固まりに分割されます。 |
| 18026 | 20983 | それぞれの固まりは別々に値に変換されます。 |
| 18027 | 典型的には、文字列は C<pack> の結果あるいはある種 | |
| 20984 | 典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の | |
| 18028 | 文字列表現の文字列です。 | |
| 20985 | C の構造体の文字列表現の文字列です。 | |
| 18029 | 20986 | |
| 18030 | 20987 | =begin original |
| 18031 | 20988 | |
| 18032 | The TEMPLATE has the same format as in the | |
| 20989 | The TEMPLATE has the same format as in the | |
| 20990 | L<C<pack>|/pack TEMPLATE,LIST> function. | |
| 18033 | 20991 | Here's a subroutine that does substring: |
| 18034 | 20992 | |
| 18035 | 20993 | =end original |
| 18036 | 20994 | |
| 18037 | TEMPLATE は、C<pack> 関数と同じフォーマットを使います。 | |
| 20995 | TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。 | |
| 18038 | 20996 | 部分文字列を取り出すうサブルーチンの例を示します: |
| 18039 | 20997 | |
| 18040 | 20998 | sub substr { |
| 18041 | my($what,$where,$howmuch) = @_; | |
| 20999 | my ($what, $where, $howmuch) = @_; | |
| 18042 | 21000 | unpack("x$where a$howmuch", $what); |
| 18043 | 21001 | } |
| 18044 | 21002 | |
| 18045 | 21003 | =begin original |
| 18046 | 21004 | |
| 18047 | 21005 | and then there's |
| 18048 | 21006 | |
| 18049 | 21007 | =end original |
| 18050 | 21008 | |
| 18051 | 21009 | これもそうです。 |
| 18052 | 21010 | |
| 18053 | 21011 | sub ordinal { unpack("W",$_[0]); } # same as ord() |
| 18054 | 21012 | |
| 18055 | 21013 | =begin original |
| 18056 | 21014 | |
| 18057 | In addition to fields allowed in pack | |
| 21015 | In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may | |
| 18058 | a %<number> to indicate that | |
| 21016 | prefix a field with a %<number> to indicate that | |
| 18059 | 21017 | you want a <number>-bit checksum of the items instead of the items |
| 18060 | themselves. Default is a 16-bit checksum. | |
| 21018 | themselves. Default is a 16-bit checksum. The checksum is calculated by | |
| 18061 | 21019 | summing numeric values of expanded values (for string fields the sum of |
| 18062 | 21020 | C<ord($char)> is taken; for bit fields the sum of zeroes and ones). |
| 18063 | 21021 | |
| 18064 | 21022 | =end original |
| 18065 | 21023 | |
| 18066 | pack | |
| 21024 | L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、 | |
| 18067 | 21025 | フィールドの前に %<数値> というものを付けて、 |
| 18068 | 21026 | 項目自身の代わりに、その項目の <数値>-ビットのチェックサムを |
| 18069 | 21027 | 計算させることができます。 |
| 18070 | 21028 | デフォルトは、16-ビットチェックサムです。 |
| 18071 | 21029 | チェックサムは展開された値の数値としての値の合計 |
| 18072 | 21030 | (文字列フィールドの場合は C<ord($char)> の合計; |
| 18073 | 21031 | ビットフィールドの場合は 0 と 1 の合計) が用いられます。 |
| 18074 | 21032 | |
| 18075 | 21033 | =begin original |
| 18076 | 21034 | |
| 18077 | 21035 | For example, the following |
| 18078 | 21036 | computes the same number as the System V sum program: |
| 18079 | 21037 | |
| 18080 | 21038 | =end original |
| 18081 | 21039 | |
| 18082 | 21040 | たとえば、以下のコードは |
| 18083 | 21041 | System V の sum プログラムと同じ値を計算します。 |
| 18084 | 21042 | |
| 18085 | $checksum = do { | |
| 21043 | my $checksum = do { | |
| 18086 | 21044 | local $/; # slurp! |
| 18087 | unpack("%32W*", | |
| 21045 | unpack("%32W*", readline) % 65535; | |
| 18088 | 21046 | }; |
| 18089 | 21047 | |
| 18090 | 21048 | =begin original |
| 18091 | 21049 | |
| 18092 | 21050 | The following efficiently counts the number of set bits in a bit vector: |
| 18093 | 21051 | |
| 18094 | 21052 | =end original |
| 18095 | 21053 | |
| 18096 | 21054 | 以下は、効率的にビットベクターの設定されているビットを |
| 18097 | 21055 | 数えるものです。 |
| 18098 | 21056 | |
| 18099 | $setbits = unpack("%32b*", $selectmask); | |
| 21057 | my $setbits = unpack("%32b*", $selectmask); | |
| 18100 | 21058 | |
| 18101 | 21059 | =begin original |
| 18102 | 21060 | |
| 18103 | 21061 | The C<p> and C<P> formats should be used with care. Since Perl |
| 18104 | has no way of checking whether the value passed to | |
| 21062 | has no way of checking whether the value passed to | |
| 21063 | L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 18105 | 21064 | corresponds to a valid memory location, passing a pointer value that's |
| 18106 | 21065 | not known to be valid is likely to have disastrous consequences. |
| 18107 | 21066 | |
| 18108 | 21067 | =end original |
| 18109 | 21068 | |
| 18110 | 21069 | C<p> と C<P> は注意深く使うべきです。 |
| 18111 | Perl は C<unpack | |
| 21070 | Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を | |
| 18112 | 確認する方法がないので、有効かどうかわからない | |
| 21071 | 指しているかどうかを確認する方法がないので、有効かどうかわからない | |
| 18113 | 悲惨な結果を引き起こすかもしれません。 | |
| 21072 | ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。 | |
| 18114 | 21073 | |
| 18115 | 21074 | =begin original |
| 18116 | 21075 | |
| 18117 | 21076 | If there are more pack codes or if the repeat count of a field or a group |
| 18118 | 21077 | is larger than what the remainder of the input string allows, the result |
| 18119 | 21078 | is not well defined: the repeat count may be decreased, or |
| 18120 | C<unpack | |
| 21079 | L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros, | |
| 21080 | or it may raise an exception. | |
| 18121 | 21081 | If the input string is longer than one described by the TEMPLATE, |
| 18122 | 21082 | the remainder of that input string is ignored. |
| 18123 | 21083 | |
| 18124 | 21084 | =end original |
| 18125 | 21085 | |
| 18126 | 21086 | 多くの pack コードがある場合や、フィールドやグループの繰り返し回数が |
| 18127 | 21087 | 入力文字列の残りより大きい場合、結果は未定義です: |
| 18128 | 繰り返し回数が減らされる場合もありますし、 | |
| 21088 | 繰り返し回数が減らされる場合もありますし、 | |
| 21089 | L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を | |
| 18129 | 21090 | 返すこともありますし、例外が発生します。 |
| 18130 | 21091 | もし入力文字列が TEMPLATE で表現されているものより大きい場合、 |
| 18131 | 21092 | 入力文字列の残りは無視されます。 |
| 18132 | 21093 | |
| 18133 | 21094 | =begin original |
| 18134 | 21095 | |
| 18135 | See L</pack> for more examples and notes. | |
| 21096 | See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes. | |
| 18136 | 21097 | |
| 18137 | 21098 | =end original |
| 18138 | 21099 | |
| 18139 | さらなる例と注意に関しては L</pack> を参照してください。 | |
| 21100 | さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 | |
| 18140 | 21101 | |
| 18141 | 21102 | =item unshift ARRAY,LIST |
| 18142 | 21103 | X<unshift> |
| 18143 | 21104 | |
| 18144 | =item unshift EXPR,LIST | |
| 18145 | ||
| 18146 | 21105 | =for Pod::Functions prepend more elements to the beginning of a list |
| 18147 | 21106 | |
| 18148 | 21107 | =begin original |
| 18149 | 21108 | |
| 18150 | ||
| 21109 | Add one or more elements to the B<beginning> of an array. This is the | |
| 18151 | ||
| 21110 | opposite of a L<C<shift>|/shift ARRAY>. | |
| 18152 | array and returns the new number of elements in the array. | |
| 18153 | 21111 | |
| 18154 | 21112 | =end original |
| 18155 | 21113 | |
| 18156 | ||
| 21114 | 一つまたは複数の要素を配列の B<先頭> に追加します。 | |
| 18157 | ||
| 21115 | これは L<C<shift>|/shift ARRAY> の逆操作です。 | |
| 18158 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 | |
| 18159 | 21116 | |
| 18160 | | |
| 21117 | my @animals = ("cat"); | |
| 21118 | unshift(@animals, "mouse"); # ("mouse", "cat") | |
| 18161 | 21119 | |
| 21120 | my @colors = ("red"); | |
| 21121 | unshift(@colors, ("blue", "green")); # ("blue", "green", "red") | |
| 21122 | ||
| 18162 | 21123 | =begin original |
| 18163 | 21124 | |
| 18164 | ||
| 21125 | Returns the new number of elements in the updated array. | |
| 18165 | prepended elements stay in the same order. Use C<reverse> to do the | |
| 18166 | reverse. | |
| 18167 | 21126 | |
| 18168 | 21127 | =end original |
| 18169 | 21128 | |
| 18170 | ||
| 21129 | 更新された配列の要素の数を返します。 | |
| 18171 | 逆順に登録するには、C<reverse> を使ってください。 | |
| 18172 | 21130 | |
| 21131 | # Return value is the number of items in the updated array | |
| 21132 | my $color_count = unshift(@colors, ("yellow", "purple")); | |
| 21133 | ||
| 21134 | say "There are $color_count colors in the updated array"; | |
| 21135 | ||
| 18173 | 21136 | =begin original |
| 18174 | 21137 | |
| 18175 | ||
| 21138 | Note the LIST is prepended whole, not one element at a time, so the | |
| 18176 | ||
| 21139 | prepended elements stay in the same order. Use | |
| 18177 | ||
| 21140 | L<C<reverse>|/reverse LIST> to do the reverse. | |
| 18178 | experimental. The exact behaviour may change in a future version of Perl. | |
| 18179 | 21141 | |
| 18180 | 21142 | =end original |
| 18181 | 21143 | |
| 18182 | ||
| 21144 | LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。 | |
| 18183 | ||
| 21145 | 逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。 | |
| 18184 | 引数は自動的にデリファレンスされます。 | |
| 18185 | C<unshift> のこの動作は高度に実験的であると考えられています。 | |
| 18186 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 18187 | 21146 | |
| 18188 | 21147 | =begin original |
| 18189 | 21148 | |
| 18190 | ||
| 21149 | Starting with Perl 5.14, an experimental feature allowed | |
| 18191 | ||
| 21150 | L<C<unshift>|/unshift ARRAY,LIST> to take | |
| 18192 | ||
| 21151 | a scalar expression. This experiment has been deemed unsuccessful, and was | |
| 18193 | ||
| 21152 | removed as of Perl 5.24. | |
| 18194 | 21153 | |
| 18195 | 21154 | =end original |
| 18196 | 21155 | |
| 18197 | ||
| 21156 | Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を | |
| 18198 | ||
| 21157 | 取ることが出来るという実験的機能がありました。 | |
| 18199 | ||
| 21158 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 18200 | 書いてください: | |
| 18201 | 21159 | |
| 18202 | use 5.014; # so push/pop/etc work on scalars (experimental) | |
| 18203 | ||
| 18204 | 21160 | =item untie VARIABLE |
| 18205 | 21161 | X<untie> |
| 18206 | 21162 | |
| 18207 | 21163 | =for Pod::Functions break a tie binding to a variable |
| 18208 | 21164 | |
| 18209 | 21165 | =begin original |
| 18210 | 21166 | |
| 18211 | 21167 | Breaks the binding between a variable and a package. |
| 18212 | 21168 | (See L<tie|/tie VARIABLE,CLASSNAME,LIST>.) |
| 18213 | 21169 | Has no effect if the variable is not tied. |
| 18214 | 21170 | |
| 18215 | 21171 | =end original |
| 18216 | 21172 | |
| 18217 | 21173 | 変数とパッケージの間の結合を解きます。 |
| 18218 | 21174 | (L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。) |
| 18219 | 21175 | 結合されていない場合は何も起きません。 |
| 18220 | 21176 | |
| 18221 | 21177 | =item use Module VERSION LIST |
| 18222 | 21178 | X<use> X<module> X<import> |
| 18223 | 21179 | |
| 18224 | 21180 | =item use Module VERSION |
| 18225 | 21181 | |
| 18226 | 21182 | =item use Module LIST |
| 18227 | 21183 | |
| 18228 | 21184 | =item use Module |
| 18229 | 21185 | |
| 18230 | =item use VERSION | |
| 18231 | ||
| 18232 | 21186 | =for Pod::Functions load in a module at compile time and import its namespace |
| 18233 | 21187 | |
| 18234 | 21188 | =begin original |
| 18235 | 21189 | |
| 18236 | 21190 | Imports some semantics into the current package from the named module, |
| 18237 | 21191 | generally by aliasing certain subroutine or variable names into your |
| 18238 | 21192 | package. It is exactly equivalent to |
| 18239 | 21193 | |
| 18240 | 21194 | =end original |
| 18241 | 21195 | |
| 18242 | 21196 | 指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; |
| 18243 | 21197 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 |
| 18244 | 21198 | 実現されています。 |
| 18245 | 21199 | これは、以下は等価ですが: |
| 18246 | 21200 | |
| 18247 | 21201 | BEGIN { require Module; Module->import( LIST ); } |
| 18248 | 21202 | |
| 18249 | 21203 | =begin original |
| 18250 | 21204 | |
| 18251 | 21205 | except that Module I<must> be a bareword. |
| 18252 | 21206 | The importation can be made conditional by using the L<if> module. |
| 18253 | 21207 | |
| 18254 | 21208 | =end original |
| 18255 | 21209 | |
| 18256 | 21210 | Module が I<裸の単語でなければならない> ことを除けば、です。 |
| 18257 | 21211 | インポートは、L<if> を使って条件付きで行うことができます。 |
| 18258 | 21212 | |
| 18259 | 21213 | =begin original |
| 18260 | 21214 | |
| 18261 | I | |
| 21215 | The C<BEGIN> forces the L<C<require>|/require VERSION> and | |
| 18262 | ||
| 21216 | L<C<import>|/import LIST> to happen at compile time. The | |
| 18263 | ||
| 21217 | L<C<require>|/require VERSION> makes sure the module is loaded into | |
| 18264 | e | |
| 21218 | memory if it hasn't been yet. The L<C<import>|/import LIST> is not a | |
| 18265 | ||
| 21219 | builtin; it's just an ordinary static method | |
| 18266 | ||
| 21220 | call into the C<Module> package to tell the module to import the list of | |
| 18267 | ||
| 21221 | features back into the current package. The module can implement its | |
| 18268 | o | |
| 21222 | L<C<import>|/import LIST> method any way it likes, though most modules | |
| 21223 | just choose to derive their L<C<import>|/import LIST> method via | |
| 21224 | inheritance from the C<Exporter> class that is defined in the | |
| 21225 | L<C<Exporter>|Exporter> module. See L<Exporter>. If no | |
| 21226 | L<C<import>|/import LIST> method can be found, then the call is skipped, | |
| 21227 | even if there is an AUTOLOAD method. | |
| 18269 | 21228 | |
| 18270 | 21229 | =end original |
| 18271 | 21230 | |
| 18272 | ||
| 21231 | C<BEGIN> によって、L<C<require>|/require VERSION> や | |
| 18273 | ||
| 21232 | L<C<import>|/import LIST> は、コンパイル時に | |
| 18274 | ||
| 21233 | 実行されることになります。 | |
| 18275 | VERSION | |
| 21234 | L<C<require>|/require VERSION> は、モジュールがまだメモリに | |
| 18276 | ||
| 21235 | ロードされていなければ、ロードします。 | |
| 18277 | L< | |
| 21236 | L<C<import>|/import LIST> は、組込みの関数ではありません; さまざまな機能を | |
| 18278 | ||
| 21237 | 現在のパッケージにインポートするように C<Module> パッケージに伝えるために | |
| 18279 | ||
| 21238 | 呼ばれる、通常の静的メソッドです。 | |
| 21239 | モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも | |
| 21240 | 実装することができますが、多くのモジュールでは、 | |
| 21241 | L<C<Exporter>|Exporter> モジュールで定義された、 | |
| 21242 | C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを | |
| 21243 | 行なうようにしています。 | |
| 21244 | L<Exporter>モジュールを参照してください。 | |
| 21245 | L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが | |
| 21246 | あったとしても呼び出しはスキップされます。 | |
| 18280 | 21247 | |
| 18281 | 21248 | =begin original |
| 18282 | 21249 | |
| 18283 | ||
| 21250 | If you do not want to call the package's L<C<import>|/import LIST> | |
| 18284 | ||
| 21251 | method (for instance, | |
| 18285 | ||
| 21252 | to stop your namespace from being altered), explicitly supply the empty list: | |
| 18286 | syntax. The equivalent numeric version should be used instead. | |
| 18287 | 21253 | |
| 18288 | 21254 | =end original |
| 18289 | 21255 | |
| 18290 | ||
| 21256 | パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、 | |
| 18291 | な | |
| 21257 | 名前空間を変更したくない場合など)は、明示的に空リストを指定してください: | |
| 18292 | (つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。 | |
| 18293 | 代わりに等価な数値表現を使うべきです。 | |
| 18294 | 21258 | |
| 18295 | use | |
| 21259 | use Module (); | |
| 18296 | use 5.6.1; # ditto | |
| 18297 | use 5.006_001; # ditto; preferred for backwards compatibility | |
| 18298 | 21260 | |
| 18299 | 21261 | =begin original |
| 18300 | 21262 | |
| 18301 | Th | |
| 21263 | That is exactly equivalent to | |
| 18302 | C<use>ing library modules that won't work with older versions of Perl. | |
| 18303 | (We try not to do this more than we have to.) | |
| 18304 | 21264 | |
| 18305 | 21265 | =end original |
| 18306 | 21266 | |
| 18307 | これは | |
| 21267 | これは以下と完全に等価です: | |
| 18308 | C<use> する前に、現在の Perl のバージョンを調べたい場合に有用です。 | |
| 18309 | (我々は必要な場合以外にそのようなことがないように努力していますが。) | |
| 18310 | 21268 | |
| 18311 | ||
| 21269 | BEGIN { require Module } | |
| 18312 | 21270 | |
| 18313 | C<use VERSION> also enables all features available in the requested | |
| 18314 | version as defined by the C<feature> pragma, disabling any features | |
| 18315 | not in the requested version's feature bundle. See L<feature>. | |
| 18316 | Similarly, if the specified Perl version is greater than or equal to | |
| 18317 | 5.12.0, strictures are enabled lexically as | |
| 18318 | with C<use strict>. Any explicit use of | |
| 18319 | C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes | |
| 18320 | before it. In both cases, the F<feature.pm> and F<strict.pm> files are | |
| 18321 | not actually loaded. | |
| 18322 | ||
| 18323 | =end original | |
| 18324 | ||
| 18325 | C<use VERSION> は、C<feature> プラグマで定義されたように、指定された | |
| 18326 | バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の | |
| 18327 | 束にない機能を無効にします。 | |
| 18328 | L<feature> を参照してください。 | |
| 18329 | 同様に、指定された Perl のバージョンが 5.12.0 以上の場合、 | |
| 18330 | 制限は C<use strict> と同様にレキシカルに有効になります。 | |
| 18331 | 明示的に C<use strict> や C<no strict> を使うと、例え先に | |
| 18332 | 指定されていたとしても、C<use VERSION> を上書きします。 | |
| 18333 | どちらの場合も、F<feature.pm> と F<strict.pm> ファイルは実際には | |
| 18334 | 読み込まれません。 | |
| 18335 | ||
| 18336 | 21271 | =begin original |
| 18337 | 21272 | |
| 18338 | ||
| 21273 | If the VERSION argument is present between Module and LIST, then the | |
| 18339 | C< | |
| 21274 | L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in | |
| 18340 | ||
| 21275 | class Module with the given version as an argument: | |
| 18341 | call into the C<Module> package to tell the module to import the list of | |
| 18342 | features back into the current package. The module can implement its | |
| 18343 | C<import> method any way it likes, though most modules just choose to | |
| 18344 | derive their C<import> method via inheritance from the C<Exporter> class that | |
| 18345 | is defined in the C<Exporter> module. See L<Exporter>. If no C<import> | |
| 18346 | method can be found then the call is skipped, even if there is an AUTOLOAD | |
| 18347 | method. | |
| 18348 | 21276 | |
| 18349 | 21277 | =end original |
| 18350 | 21278 | |
| 18351 | ||
| 21279 | Module と LIST の間に VERSION 引数がある場合、 | |
| 18352 | ||
| 21280 | L<C<use>|/use Module VERSION LIST> は Module クラスの | |
| 18353 | C< | |
| 21281 | C<VERSION> メソッドを、与えられたバージョンを引数として呼び出します: | |
| 18354 | C<import> は、組込みの関数ではありません; さまざまな機能を現在のパッケージに | |
| 18355 | インポートするように C<Module> パッケージに伝えるために呼ばれる、 | |
| 18356 | 通常の静的メソッドです。 | |
| 18357 | モジュール側では、C<import> メソッドをどのようにでも実装することが | |
| 18358 | できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、 | |
| 18359 | C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように | |
| 18360 | しています。 | |
| 18361 | L<Exporter>モジュールを参照してください。 | |
| 18362 | C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても | |
| 18363 | 呼び出しはスキップされます。 | |
| 18364 | 21282 | |
| 21283 | use Module 12.34; | |
| 21284 | ||
| 18365 | 21285 | =begin original |
| 18366 | 21286 | |
| 18367 | ||
| 21287 | is equivalent to: | |
| 18368 | to stop your namespace from being altered), explicitly supply the empty list: | |
| 18369 | 21288 | |
| 18370 | 21289 | =end original |
| 18371 | 21290 | |
| 18372 | ||
| 21291 | は以下と等価です: | |
| 18373 | 変更したくない場合など)は、明示的に空リストを指定してください: | |
| 18374 | 21292 | |
| 18375 | u | |
| 21293 | BEGIN { require Module; Module->VERSION(12.34) } | |
| 18376 | 21294 | |
| 18377 | 21295 | =begin original |
| 18378 | 21296 | |
| 18379 | Th | |
| 21297 | The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>, | |
| 21298 | inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given | |
| 21299 | version is larger than the value of the variable C<$Module::VERSION>. | |
| 18380 | 21300 | |
| 18381 | 21301 | =end original |
| 18382 | 21302 | |
| 18383 | ||
| 21303 | デフォルトの | |
| 21304 | L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、 | |
| 21305 | L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、 | |
| 21306 | 与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に | |
| 21307 | 警告を出します。 | |
| 18384 | 21308 | |
| 18385 | BEGIN { require Module } | |
| 18386 | ||
| 18387 | 21309 | =begin original |
| 18388 | 21310 | |
| 18389 | ||
| 21311 | The VERSION argument cannot be an arbitrary expression. It only counts | |
| 18390 | ||
| 21312 | as a VERSION argument if it is a version number literal, starting with | |
| 18391 | ||
| 21313 | either a digit or C<v> followed by a digit. Anything that doesn't | |
| 18392 | ||
| 21314 | look like a version literal will be parsed as the start of the LIST. | |
| 18393 | v | |
| 21315 | Nevertheless, many attempts to use an arbitrary expression as a VERSION | |
| 21316 | argument will appear to work, because L<Exporter>'s C<import> method | |
| 21317 | handles numeric arguments specially, performing version checks rather | |
| 21318 | than treating them as things to export. | |
| 18394 | 21319 | |
| 18395 | 21320 | =end original |
| 18396 | 21321 | |
| 18397 | ||
| 21322 | VERSION 引数は任意の式ではありません。 | |
| 18398 | VERSION | |
| 21323 | VERSION 引数が数値または C<v> に引き続いて数値であるバージョン番号リテラルの | |
| 18399 | ||
| 21324 | 場合にのみ扱われます。 | |
| 18400 | ||
| 21325 | バージョンリテラルのように見えないものは LIST の開始としてパースされます。 | |
| 18401 | ||
| 21326 | それにも関わらず、VERSION 引数として任意の式を使おうとする | |
| 21327 | 多くの試みは動作しているように見えます; なぜなら | |
| 21328 | L<Exporter> の C<import> メソッドは数値引数を特別に扱い、 | |
| 21329 | それらをエクスポートするべきものと扱わずにバージョンチェックを | |
| 21330 | 実行するからです。 | |
| 18402 | 21331 | |
| 18403 | 21332 | =begin original |
| 18404 | 21333 | |
| 18405 | Again, there is a distinction between omitting LIST (C<import> | |
| 21334 | Again, there is a distinction between omitting LIST (L<C<import>|/import | |
| 18406 | with no arguments) and an explicit empty LIST C<()> | |
| 21335 | LIST> called with no arguments) and an explicit empty LIST C<()> | |
| 18407 | called). Note that there is no comma | |
| 21336 | (L<C<import>|/import LIST> not called). Note that there is no comma | |
| 21337 | after VERSION! | |
| 18408 | 21338 | |
| 18409 | 21339 | =end original |
| 18410 | 21340 | |
| 18411 | 繰り返すと、LIST を省略する(C<import> が引数なしで | |
| 21341 | 繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで | |
| 18412 | 明示的に空の LIST C<()> を指定する | |
| 21342 | 呼び出される)ことと明示的に空の LIST C<()> を指定する | |
| 18413 | 違います。 | |
| 21343 | (L<C<import>|/import LIST> は呼び出されない)ことは違います。 | |
| 18414 | 21344 | VERSION の後ろにカンマが不要なことに注意してください! |
| 18415 | 21345 | |
| 18416 | 21346 | =begin original |
| 18417 | 21347 | |
| 18418 | 21348 | Because this is a wide-open interface, pragmas (compiler directives) |
| 18419 | are also implemented this way. | |
| 21349 | are also implemented this way. Some of the currently implemented | |
| 21350 | pragmas are: | |
| 18420 | 21351 | |
| 18421 | 21352 | =end original |
| 18422 | 21353 | |
| 18423 | 21354 | これは、広く公開されているインタフェースですので、 |
| 18424 | 21355 | プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 |
| 18425 | 現在実装されているプラグマには、以下のものがあります: | |
| 21356 | 現在実装されているプラグマには、以下のようなものがあります: | |
| 18426 | 21357 | |
| 18427 | 21358 | use constant; |
| 18428 | 21359 | use diagnostics; |
| 18429 | 21360 | use integer; |
| 18430 | 21361 | use sigtrap qw(SEGV BUS); |
| 18431 | 21362 | use strict qw(subs vars refs); |
| 18432 | 21363 | use subs qw(afunc blurfl); |
| 18433 | 21364 | use warnings qw(all); |
| 18434 | use sort qw(stable | |
| 21365 | use sort qw(stable); | |
| 18435 | 21366 | |
| 18436 | 21367 | =begin original |
| 18437 | 21368 | |
| 18438 | 21369 | Some of these pseudo-modules import semantics into the current |
| 18439 | block scope (like C<strict> or C<integer>, unlike | |
| 21370 | block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike | |
| 18440 | which import symbols into the current package (which | |
| 21371 | ordinary modules, which import symbols into the current package (which | |
| 18441 | through the end of the file). | |
| 21372 | are effective through the end of the file). | |
| 18442 | 21373 | |
| 18443 | 21374 | =end original |
| 18444 | 21375 | |
| 18445 | 21376 | 通常のモジュールが、現在のパッケージにシンボルをインポートする |
| 18446 | (これは、ファイルの終わりまで有効です) のに対して、 | |
| 21377 | (これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの | |
| 18447 | ||
| 21378 | 一部(L<C<strict>|strict> や L<C<integer>|integer> など)は、現在の | |
| 18448 | ||
| 21379 | ブロックスコープにインポートを行ないます。 | |
| 18449 | 21380 | |
| 18450 | 21381 | =begin original |
| 18451 | 21382 | |
| 18452 | Because C<use> takes effect at compile time, | |
| 21383 | Because L<C<use>|/use Module VERSION LIST> takes effect at compile time, | |
| 18453 | ordinary flow control of the code being compiled. | |
| 21384 | it doesn't respect the ordinary flow control of the code being compiled. | |
| 18454 | a C<use> | |
| 21385 | In particular, putting a L<C<use>|/use Module VERSION LIST> inside the | |
| 18455 | f | |
| 21386 | false branch of a conditional doesn't prevent it | |
| 21387 | from being processed. If a module or pragma only needs to be loaded | |
| 18456 | 21388 | conditionally, this can be done using the L<if> pragma: |
| 18457 | 21389 | |
| 18458 | 21390 | =end original |
| 18459 | 21391 | |
| 18460 | C<use> はコンパイル時に有効なので、コードが | |
| 21392 | L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが | |
| 18461 | 流れ制御には従いません。 | |
| 21393 | コンパイルされる際の通常の流れ制御には従いません。 | |
| 18462 | 特に、条件文のうち成立しない側の中に C<use> を | |
| 21394 | 特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST> を | |
| 18463 | 処理を妨げられません。 | |
| 21395 | 書いても、処理を妨げられません。 | |
| 18464 | 21396 | モジュールやプラグマを条件付きでのみ読み込みたい場合、 |
| 18465 | 21397 | L<if> プラグマを使って実現できます: |
| 18466 | 21398 | |
| 18467 | 21399 | use if $] < 5.008, "utf8"; |
| 18468 | 21400 | use if WANT_WARNINGS, warnings => qw(all); |
| 18469 | 21401 | |
| 18470 | 21402 | =begin original |
| 18471 | 21403 | |
| 18472 | There's a corresponding C<no> declaration | |
| 21404 | There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration | |
| 18473 | ||
| 21405 | that unimports meanings imported by L<C<use>|/use Module VERSION LIST>, | |
| 18474 | ||
| 21406 | i.e., it calls C<< Module->unimport(LIST) >> instead of | |
| 21407 | L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST> | |
| 21408 | does with VERSION, an omitted or empty LIST, | |
| 18475 | 21409 | or no unimport method being found. |
| 18476 | 21410 | |
| 18477 | 21411 | =end original |
| 18478 | 21412 | |
| 18479 | これに対して、C<no> 宣言という | |
| 21413 | これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、 | |
| 18480 | インポートされ | |
| 21414 | L<C<use>|/use Module VERSION LIST> によってインポートされたものを、 | |
| 18481 | ||
| 21415 | インポートされていないことにするものがあります; つまり、 | |
| 21416 | L<C<import>|/import LIST> の代わりに | |
| 21417 | C<< Module->unimport(LIST) >> を呼び出します。 | |
| 18482 | 21418 | これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない |
| 18483 | 場合などの観点では、C<import> と同様に振る舞います。 | |
| 21419 | 場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。 | |
| 18484 | 21420 | |
| 18485 | 21421 | no integer; |
| 18486 | 21422 | no strict 'refs'; |
| 18487 | 21423 | no warnings; |
| 18488 | 21424 | |
| 18489 | 21425 | =begin original |
| 18490 | 21426 | |
| 18491 | ||
| 21427 | See L<perlmodlib> for a list of standard modules and pragmas. See | |
| 18492 | ||
| 21428 | L<perlrun|perlrun/-m[-]module> for the C<-M> and C<-m> command-line | |
| 18493 | ||
| 21429 | options to Perl that give L<C<use>|/use Module VERSION LIST> | |
| 18494 | of | |
| 21430 | functionality from the command-line. | |
| 18495 | 21431 | |
| 18496 | 21432 | =end original |
| 18497 | 21433 | |
| 18498 | ||
| 21434 | 標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。 | |
| 18499 | ||
| 21435 | コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を | |
| 18500 | ||
| 21436 | 指定するための C<-M> と C<-m> の | |
| 18501 | ||
| 21437 | コマンドラインオプションについては | |
| 21438 | L<perlrun|perlrun/-m[-]module> を参照してください。 | |
| 18502 | 21439 | |
| 21440 | =item use VERSION | |
| 21441 | ||
| 21442 | =for Pod::Functions enable Perl language features and declare required version | |
| 21443 | ||
| 18503 | 21444 | =begin original |
| 18504 | 21445 | |
| 18505 | ||
| 21446 | Lexically enables all features available in the requested version as | |
| 18506 | f | |
| 21447 | defined by the L<feature> pragma, disabling any features not in the | |
| 18507 | ||
| 21448 | requested version's feature bundle. See L<feature>. | |
| 18508 | 21449 | |
| 18509 | 21450 | =end original |
| 18510 | 21451 | |
| 18511 | ||
| 21452 | L<feature> プラグマで定義された、指定されたバージョンで利用可能な | |
| 18512 | ||
| 21453 | 全ての機能を有効にし、指定されたバージョンの機能の束で要求されていない | |
| 18513 | ||
| 21454 | 全ての機能を無効にします。 | |
| 21455 | L<feature> を参照してください。 | |
| 18514 | 21456 | |
| 21457 | =begin original | |
| 21458 | ||
| 21459 | VERSION may be either a v-string such as v5.24.1, which will be compared | |
| 21460 | to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION), or a numeric argument of the | |
| 21461 | form 5.024001, which will be compared to L<C<$]>|perlvar/$]>. An | |
| 21462 | exception is raised if VERSION is greater than the version of the current | |
| 21463 | Perl interpreter; Perl will not attempt to parse the rest of the file. | |
| 21464 | Compare with L<C<require>|/require VERSION>, which can do a similar check | |
| 21465 | at run time. | |
| 21466 | ||
| 21467 | =end original | |
| 21468 | ||
| 21469 | VERSION は v5.24.1 のような v-文字列 | |
| 21470 | (L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます) | |
| 21471 | か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で | |
| 21472 | 指定します。 | |
| 21473 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します; | |
| 21474 | Perl はファイルの残りを読み込みません。 | |
| 21475 | L<C<require>|/require VERSION> と似ていますが、これは実行時に | |
| 21476 | チェックされます。 | |
| 21477 | ||
| 21478 | =begin original | |
| 21479 | ||
| 21480 | If the specified Perl version is 5.12 or higher, strictures are enabled | |
| 21481 | lexically as with L<C<use strict>|strict>. Similarly, if the specified | |
| 21482 | Perl version is 5.35.0 or higher, L<warnings> are enabled. Later use of | |
| 21483 | C<use VERSION> will override all behavior of a previous C<use VERSION>, | |
| 21484 | possibly removing the C<strict>, C<warnings>, and C<feature> added by it. | |
| 21485 | C<use VERSION> does not load the F<feature.pm>, F<strict.pm>, or | |
| 21486 | F<warnings.pm> files. | |
| 21487 | ||
| 21488 | =end original | |
| 21489 | ||
| 21490 | 指定された Perl のバージョンが 5.12 以上の場合、 | |
| 21491 | L<C<use strict>|strict> と同様に、strict 機能がレキシカルに有効になります。 | |
| 21492 | 同様に、指定された Perl のバージョンが 5.35.0 以上の場合、 | |
| 21493 | L<warnings> が有効になります。 | |
| 21494 | 後から使った C<use VERSION> は先の | |
| 21495 | C<use VERSION> の全ての振る舞いを上書きするので、 | |
| 21496 | それによって追加された C<strict>, C<feature>, C<feature> を | |
| 21497 | 削除することがあります。 | |
| 21498 | C<use VERSION> は F<feature.pm>, F<strict.pm>, F<warnings.pm> ファイルは | |
| 21499 | 読み込みません。 | |
| 21500 | ||
| 21501 | =begin original | |
| 21502 | ||
| 21503 | In the current implementation, any explicit use of C<use strict> or | |
| 21504 | C<no strict> overrides C<use VERSION>, even if it comes before it. | |
| 21505 | However, this may be subject to change in a future release of Perl, so new | |
| 21506 | code should not rely on this fact. It is recommended that a | |
| 21507 | C<use VERSION> declaration be the first significant statement within a | |
| 21508 | file (possibly after a C<package> statement or any amount of whitespace or | |
| 21509 | comment), so that its effects happen first, and other pragmata are applied | |
| 21510 | after it. | |
| 21511 | ||
| 21512 | =end original | |
| 21513 | ||
| 21514 | 現在の実装では、明示的に C<use strict> や C<no strict> を使うと、例え先に | |
| 21515 | 指定されていたとしても、C<use VERSION> を上書きします。 | |
| 21516 | しかし、これは将来のリリースの Perl で変更されるかもしれないので、 | |
| 21517 | 新しいコードはこの事実に依存するべきではありません。 | |
| 21518 | (場合によっては C<package> 文や任意の量の空白やコメントの後の)ファイルの | |
| 21519 | 最初の有効な文として C<use VERSION> 宣言することを勧めます; | |
| 21520 | この機能が最初に怒り、その他のプラグマはその後に適用されるからです。 | |
| 21521 | ||
| 21522 | =begin original | |
| 21523 | ||
| 21524 | Specifying VERSION as a numeric argument of the form 5.024001 should | |
| 21525 | generally be avoided as older less readable syntax compared to | |
| 21526 | v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric | |
| 21527 | form was the only supported syntax, which is why you might see it in | |
| 21528 | older code. | |
| 21529 | ||
| 21530 | =end original | |
| 21531 | ||
| 21532 | VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; | |
| 21533 | v5.24.1 に比べてより古く読みにくい文法だからです。 | |
| 21534 | (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な | |
| 21535 | 数値形式が唯一対応している文法でした; これが古いコードでこれを | |
| 21536 | 見るかも知れない理由です。 | |
| 21537 | ||
| 21538 | =begin original | |
| 21539 | ||
| 21540 | use v5.24.1; # compile time version check | |
| 21541 | use 5.24.1; # ditto | |
| 21542 | use 5.024_001; # ditto; older syntax compatible with perl 5.6 | |
| 21543 | ||
| 21544 | =end original | |
| 21545 | ||
| 21546 | use v5.24.1; # 実行時バージョンチェック | |
| 21547 | use 5.24.1; # 同様 | |
| 21548 | use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法 | |
| 21549 | ||
| 21550 | =begin original | |
| 21551 | ||
| 21552 | This is often useful if you need to check the current Perl version before | |
| 21553 | L<C<use>|/use Module VERSION LIST>ing library modules that won't work | |
| 21554 | with older versions of Perl. | |
| 21555 | (We try not to do this more than we have to.) | |
| 21556 | ||
| 21557 | =end original | |
| 21558 | ||
| 21559 | これは古いバージョンの Perl で動かなくなったライブラリモジュールを | |
| 21560 | L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを | |
| 21561 | 調べたい場合に有用です。 | |
| 21562 | (我々は必要な場合以外にそのようなことがないように努力していますが。) | |
| 21563 | ||
| 21564 | =begin original | |
| 21565 | ||
| 21566 | Symmetrically, C<no VERSION> allows you to specify that you want a version | |
| 21567 | of Perl older than the specified one. Historically this was added during | |
| 21568 | early designs of the Raku language (formerly "Perl 6"), so that a Perl 5 | |
| 21569 | program could begin | |
| 21570 | ||
| 21571 | =end original | |
| 21572 | ||
| 21573 | 対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で | |
| 21574 | 動作させたいことを意味します。 | |
| 21575 | 歴史的には、これは Raku 言語 (以前は "Perl 6") の初期仕様で加えられたので、 | |
| 21576 | Perl 5 のプログラムは次のもので始めて: | |
| 21577 | ||
| 21578 | no 6; | |
| 21579 | ||
| 21580 | =begin original | |
| 21581 | ||
| 21582 | to declare that it is not a Perl 6 program. As the two languages have | |
| 21583 | different implementations, file naming conventions, and other | |
| 21584 | infrastructure, this feature is now little used in practice and should be | |
| 21585 | avoided in newly-written code. | |
| 21586 | ||
| 21587 | =end original | |
| 21588 | ||
| 21589 | Perl 6 プログラムでないことを宣言できました。 | |
| 21590 | 二つの言語は異なる実装、命名規則、およびその他のインフラを持つので、 | |
| 21591 | 今ではこの機能は実際にはほとんど使われておらず、新しいコードでは | |
| 21592 | 避けるべきです。 | |
| 21593 | ||
| 21594 | =begin original | |
| 21595 | ||
| 21596 | Care should be taken when using the C<no VERSION> form, as it is I<only> | |
| 21597 | meant to be used to assert that the running Perl is of a earlier version | |
| 21598 | than its argument and I<not> to undo the feature-enabling side effects | |
| 21599 | of C<use VERSION>. | |
| 21600 | ||
| 21601 | =end original | |
| 21602 | ||
| 21603 | C<no VERSION> 形式を使うときには注意を払うべきです; | |
| 21604 | これは引数で指定されたバージョンよりも前の Perl で実行されたときに | |
| 21605 | アサートされることを意味する I<だけ> で、C<use VERSION> によって | |
| 21606 | 有効にされた副作用をなかったことにするもの I<ではありません>。 | |
| 21607 | ||
| 18515 | 21608 | =item utime LIST |
| 18516 | 21609 | X<utime> |
| 18517 | 21610 | |
| 18518 | 21611 | =for Pod::Functions set a file's last access and modify times |
| 18519 | 21612 | |
| 18520 | 21613 | =begin original |
| 18521 | 21614 | |
| 18522 | 21615 | Changes the access and modification times on each file of a list of |
| 18523 | 21616 | files. The first two elements of the list must be the NUMERIC access |
| 18524 | 21617 | and modification times, in that order. Returns the number of files |
| 18525 | 21618 | successfully changed. The inode change time of each file is set |
| 18526 | 21619 | to the current time. For example, this code has the same effect as the |
| 18527 | Unix touch(1) command when the files I<already exist> and belong to | |
| 21620 | Unix L<touch(1)> command when the files I<already exist> and belong to | |
| 18528 | 21621 | the user running the program: |
| 18529 | 21622 | |
| 18530 | 21623 | =end original |
| 18531 | 21624 | |
| 18532 | 21625 | ファイルのアクセス時刻と修正(modification) 時刻を変更します。 |
| 18533 | 21626 | LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を |
| 18534 | 21627 | 順に指定します。 |
| 18535 | 21628 | 変更に成功したファイルの数を返します。 |
| 18536 | 21629 | 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 |
| 18537 | 21630 | 例えば、このコードはファイルが I<既に存在して> いて、ユーザーが |
| 18538 | 21631 | 実行しているプログラムに従っているなら、 |
| 18539 | Unix の touch(1) コマンドと同じ効果があります。 | |
| 21632 | Unix の L<touch(1)> コマンドと同じ効果があります。 | |
| 18540 | 21633 | |
| 18541 | 21634 | #!/usr/bin/perl |
| 18542 | $atime = $mtime = time; | |
| 21635 | my $atime = my $mtime = time; | |
| 18543 | 21636 | utime $atime, $mtime, @ARGV; |
| 18544 | 21637 | |
| 18545 | 21638 | =begin original |
| 18546 | 21639 | |
| 18547 | Since Perl 5.8.0, if the first two elements of the list are | |
| 21640 | Since Perl 5.8.0, if the first two elements of the list are | |
| 18548 | ||
| 21641 | L<C<undef>|/undef EXPR>, | |
| 21642 | the L<utime(2)> syscall from your C library is called with a null second | |
| 18549 | 21643 | argument. On most systems, this will set the file's access and |
| 18550 | 21644 | modification times to the current time (i.e., equivalent to the example |
| 18551 | 21645 | above) and will work even on files you don't own provided you have write |
| 18552 | 21646 | permission: |
| 18553 | 21647 | |
| 18554 | 21648 | =end original |
| 18555 | 21649 | |
| 18556 | Perl 5.8.0 から、リストの最初の二つの要素が C<undef> である | |
| 21650 | Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である | |
| 18557 | C ライブラリの utime(2) システムコールを、秒の引数を null として | |
| 21651 | 場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として | |
| 18558 | 21652 | 呼び出します。 |
| 18559 | 21653 | ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を |
| 18560 | 21654 | 現在の時刻にセットし(つまり、上記の例と等価です)、 |
| 18561 | 21655 | 書き込み権限があれば他のユーザーのファイルに対しても動作します。 |
| 18562 | 21656 | |
| 18563 | for $file (@ARGV) { | |
| 21657 | for my $file (@ARGV) { | |
| 18564 | utime(undef, undef, $file) | |
| 21658 | utime(undef, undef, $file) | |
| 18565 | || warn " | |
| 21659 | || warn "Couldn't touch $file: $!"; | |
| 18566 | } | |
| 21660 | } | |
| 18567 | 21661 | |
| 18568 | 21662 | =begin original |
| 18569 | 21663 | |
| 18570 | 21664 | Under NFS this will use the time of the NFS server, not the time of |
| 18571 | 21665 | the local machine. If there is a time synchronization problem, the |
| 18572 | 21666 | NFS server and local machine will have different times. The Unix |
| 18573 | touch(1) command will in fact normally use this form instead of the | |
| 21667 | L<touch(1)> command will in fact normally use this form instead of the | |
| 18574 | 21668 | one shown in the first example. |
| 18575 | 21669 | |
| 18576 | 21670 | =end original |
| 18577 | 21671 | |
| 18578 | 21672 | NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が |
| 18579 | 21673 | 使われます。 |
| 18580 | 21674 | 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に |
| 18581 | 21675 | なっている場合があります。 |
| 18582 | 実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、 | |
| 21676 | 実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、 | |
| 18583 | 21677 | この形を使います。 |
| 18584 | 21678 | |
| 18585 | 21679 | =begin original |
| 18586 | 21680 | |
| 18587 | Passing only one of the first two elements as C<undef> is | |
| 21681 | Passing only one of the first two elements as L<C<undef>|/undef EXPR> is | |
| 18588 | equivalent to passing a 0 and will not have the effect | |
| 21682 | equivalent to passing a 0 and will not have the effect described when | |
| 18589 | ||
| 21683 | both are L<C<undef>|/undef EXPR>. This also triggers an | |
| 18590 | 21684 | uninitialized warning. |
| 18591 | 21685 | |
| 18592 | 21686 | =end original |
| 18593 | 21687 | |
| 18594 | 最初の二つの要素のうち、一つだけに C<undef> を渡すと、その | |
| 21688 | 最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その | |
| 18595 | 渡すのと等価となり、上述の、両方に C<undef> を | |
| 21689 | 要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を | |
| 18596 | 効果ではありません。 | |
| 21690 | 渡した時と同じ効果ではありません。 | |
| 18597 | 21691 | この場合は、未初期化の警告が出ます。 |
| 18598 | 21692 | |
| 18599 | 21693 | =begin original |
| 18600 | 21694 | |
| 18601 | On systems that support futimes(2), you may pass filehandles among the | |
| 21695 | On systems that support L<futimes(2)>, you may pass filehandles among the | |
| 18602 | files. On systems that don't support futimes(2), passing filehandles raises | |
| 21696 | files. On systems that don't support L<futimes(2)>, passing filehandles raises | |
| 18603 | 21697 | an exception. Filehandles must be passed as globs or glob references to be |
| 18604 | 21698 | recognized; barewords are considered filenames. |
| 18605 | 21699 | |
| 18606 | 21700 | =end original |
| 18607 | 21701 | |
| 18608 | futimes(2) に対応しているシステムでは、ファイルハンドルを引数として | |
| 21702 | L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として | |
| 18609 | 21703 | 渡せます。 |
| 18610 | futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと | |
| 21704 | L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 18611 | 21705 | 例外が発生します。 |
| 18612 | 21706 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして |
| 18613 | 21707 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 |
| 18614 | 21708 | |
| 18615 | 21709 | =begin original |
| 18616 | 21710 | |
| 18617 | 21711 | Portability issues: L<perlport/utime>. |
| 18618 | 21712 | |
| 18619 | 21713 | =end original |
| 18620 | 21714 | |
| 18621 | 21715 | 移植性の問題: L<perlport/utime>。 |
| 18622 | 21716 | |
| 18623 | 21717 | =item values HASH |
| 18624 | 21718 | X<values> |
| 18625 | 21719 | |
| 18626 | 21720 | =item values ARRAY |
| 18627 | 21721 | |
| 18628 | =item values EXPR | |
| 18629 | ||
| 18630 | 21722 | =for Pod::Functions return a list of the values in a hash |
| 18631 | 21723 | |
| 18632 | 21724 | =begin original |
| 18633 | 21725 | |
| 18634 | 21726 | In list context, returns a list consisting of all the values of the named |
| 18635 | 21727 | hash. In Perl 5.12 or later only, will also return a list of the values of |
| 18636 | 21728 | an array; prior to that release, attempting to use an array argument will |
| 18637 | 21729 | produce a syntax error. In scalar context, returns the number of values. |
| 18638 | 21730 | |
| 18639 | 21731 | =end original |
| 18640 | 21732 | |
| 18641 | 21733 | リストコンテキストでは、指定したハッシュのすべての値を返します。 |
| 18642 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも | |
| 21734 | Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します; | |
| 18643 | ||
| 21735 | このリリースの前では、配列要素に使おうとすると文法エラーが発生します。 | |
| 18644 | 発生します。 | |
| 18645 | 21736 | スカラコンテキストでは、値の数を返します。 |
| 18646 | 21737 | |
| 18647 | 21738 | =begin original |
| 18648 | 21739 | |
| 18649 | 21740 | Hash entries are returned in an apparently random order. The actual random |
| 18650 | 21741 | order is specific to a given hash; the exact same series of operations |
| 18651 | on two hashes may result in a different order for each hash. Any insertion | |
| 21742 | on two hashes may result in a different order for each hash. Any insertion | |
| 18652 | 21743 | into the hash may change the order, as will any deletion, with the exception |
| 18653 | that the most recent key returned by C<each> | |
| 21744 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 18654 | without changing the order. So | |
| 21745 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 18655 | ||
| 21746 | long as a given hash is unmodified you may rely on | |
| 18656 | ||
| 21747 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
| 18657 | ||
| 21748 | L<C<each>|/each HASH> to repeatedly return the same order | |
| 21749 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 21750 | details on why hash order is randomized. Aside from the guarantees | |
| 18658 | 21751 | provided here the exact details of Perl's hash algorithm and the hash |
| 18659 | traversal order are subject to change in any release of Perl. | |
| 21752 | traversal order are subject to change in any release of Perl. Tied hashes | |
| 21753 | may behave differently to Perl's hashes with respect to changes in order on | |
| 21754 | insertion and deletion of items. | |
| 18660 | 21755 | |
| 18661 | 21756 | =end original |
| 18662 | 21757 | |
| 18663 | 21758 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 |
| 18664 | 21759 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の |
| 18665 | 21760 | 操作を行っても、ハッシュによって異なった順序になります。 |
| 18666 | 21761 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 |
| 18667 | C<each> または C<keys> によって返されたもっとも | |
| 21762 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 18668 | 変えることなく削除できます。 | |
| 21763 | 最近のキーは順序を変えることなく削除できます。 | |
| 18669 | ハッシュが変更されない限り、C<keys>, C<values> | |
| 21764 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 18670 | 返すことに依存してもかまいません。 | |
| 21765 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 | |
| 18671 | 21766 | なぜハッシュの順序がランダム化されているかの詳細については |
| 18672 | 21767 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 |
| 18673 | 21768 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の |
| 18674 | 21769 | 正確な詳細は Perl のリリースによって変更される可能性があります。 |
| 21770 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
| 21771 | 異なった振る舞いをします。 | |
| 18675 | 21772 | |
| 18676 | 21773 | =begin original |
| 18677 | 21774 | |
| 18678 | As a side effect, calling values | |
| 21775 | As a side effect, calling L<C<values>|/values HASH> resets the HASH or | |
| 18679 | iterator | |
| 21776 | ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the | |
| 18680 | ||
| 21777 | values. In particular, | |
| 18681 | ||
| 21778 | calling L<C<values>|/values HASH> in void context resets the iterator | |
| 21779 | with no other overhead. | |
| 21780 | ||
| 21781 | =end original | |
| 21782 | ||
| 21783 | 副作用として、L<C<values>|/values HASH> を呼び出すと、 | |
| 21784 | 値を取り出す前に HASH や ARRAY の | |
| 21785 | 内部反復子(L<C<each>|/each HASH> 参照)をリセットします。 | |
| 21786 | 特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の | |
| 21787 | オーバーヘッドなしで反復子をリセットします。 | |
| 21788 | ||
| 21789 | =begin original | |
| 21790 | ||
| 21791 | Apart from resetting the iterator, | |
| 21792 | C<values @array> in list context is the same as plain C<@array>. | |
| 18682 | 21793 | (We recommend that you use void context C<keys @array> for this, but |
| 18683 | 21794 | reasoned that taking C<values @array> out would require more |
| 18684 | 21795 | documentation than leaving it in.) |
| 18685 | 21796 | |
| 18686 | 21797 | =end original |
| 18687 | 21798 | |
| 18688 | 副作用として、values() を呼び出すと HASH や ARRAY の内部反復子を | |
| 18689 | リセットします; C</each> を参照してください。 | |
| 18690 | (特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで | |
| 18691 | 反復子をリセットします。 | |
| 18692 | 21799 | 反復子をリセットするということを除けば、 |
| 18693 | 21800 | リストコンテキストでの C<values @array> は単なる C<@array> と同じです。 |
| 18694 | 21801 | この目的のためには無効コンテキストで C<keys @array> を使うことを |
| 18695 | 21802 | お勧めしますが、C<values @array> を取り出すにはそのままにするよりも |
| 18696 | 21803 | より多くの文書が必要だと判断しました。) |
| 18697 | 21804 | |
| 18698 | 21805 | =begin original |
| 18699 | 21806 | |
| 18700 | 21807 | Note that the values are not copied, which means modifying them will |
| 18701 | 21808 | modify the contents of the hash: |
| 18702 | 21809 | |
| 18703 | 21810 | =end original |
| 18704 | 21811 | |
| 18705 | 21812 | 値はコピーされないので、返されたリストを変更すると |
| 18706 | 21813 | ハッシュの中身が変更されることに注意してください。 |
| 18707 | 21814 | |
| 18708 | 21815 | for (values %hash) { s/foo/bar/g } # modifies %hash values |
| 18709 | 21816 | for (@hash{keys %hash}) { s/foo/bar/g } # same |
| 18710 | 21817 | |
| 18711 | 21818 | =begin original |
| 18712 | 21819 | |
| 18713 | Starting with Perl 5.14, | |
| 21820 | Starting with Perl 5.14, an experimental feature allowed | |
| 18714 | a | |
| 21821 | L<C<values>|/values HASH> to take a | |
| 18715 | ||
| 21822 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 18716 | ||
| 21823 | removed as of Perl 5.24. | |
| 18717 | 21824 | |
| 18718 | 21825 | =end original |
| 18719 | 21826 | |
| 18720 | Perl 5.14 から、C<values> | |
| 21827 | Perl 5.14 から、L<C<values>|/values HASH> がスカラ式を取ることが出来るという | |
| 18721 | ||
| 21828 | 実験的機能がありました。 | |
| 18722 | ||
| 21829 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 18723 | C<values> のこの動作は高度に実験的であると考えられています。 | |
| 18724 | 正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。 | |
| 18725 | 21830 | |
| 18726 | for (values $hashref) { ... } | |
| 18727 | for (values $obj->get_arrayref) { ... } | |
| 18728 | ||
| 18729 | 21831 | =begin original |
| 18730 | 21832 | |
| 18731 | 21833 | To avoid confusing would-be users of your code who are running earlier |
| 18732 | 21834 | versions of Perl with mysterious syntax errors, put this sort of thing at |
| 18733 | 21835 | the top of your file to signal that your code will work I<only> on Perls of |
| 18734 | 21836 | a recent vintage: |
| 18735 | 21837 | |
| 18736 | 21838 | =end original |
| 18737 | 21839 | |
| 18738 | 21840 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な |
| 18739 | 21841 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で |
| 18740 | 21842 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを |
| 18741 | 21843 | 書いてください: |
| 18742 | 21844 | |
| 18743 | use 5. | |
| 21845 | use v5.12; # so keys/values/each work on arrays | |
| 18744 | use 5.014; # so keys/values/each work on scalars (experimental) | |
| 18745 | 21846 | |
| 18746 | 21847 | =begin original |
| 18747 | 21848 | |
| 18748 | See also C<keys>, C<each>, and | |
| 21849 | See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and | |
| 21850 | L<C<sort>|/sort SUBNAME LIST>. | |
| 18749 | 21851 | |
| 18750 | 21852 | =end original |
| 18751 | 21853 | |
| 18752 | C<keys>, C<each>, C<sort> も | |
| 21854 | L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も | |
| 21855 | 参照してください。 | |
| 18753 | 21856 | |
| 18754 | 21857 | =item vec EXPR,OFFSET,BITS |
| 18755 | 21858 | X<vec> X<bit> X<bit vector> |
| 18756 | 21859 | |
| 18757 | 21860 | =for Pod::Functions test or set particular bits in a string |
| 18758 | 21861 | |
| 18759 | 21862 | =begin original |
| 18760 | 21863 | |
| 18761 | 21864 | Treats the string in EXPR as a bit vector made up of elements of |
| 18762 | 21865 | width BITS and returns the value of the element specified by OFFSET |
| 18763 | 21866 | as an unsigned integer. BITS therefore specifies the number of bits |
| 18764 | 21867 | that are reserved for each element in the bit vector. This must |
| 18765 | 21868 | be a power of two from 1 to 32 (or 64, if your platform supports |
| 18766 | 21869 | that). |
| 18767 | 21870 | |
| 18768 | 21871 | =end original |
| 18769 | 21872 | |
| 18770 | 21873 | 文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、 |
| 18771 | 21874 | OFFSET で指定された要素を符号なし整数として返します。 |
| 18772 | 21875 | 従って、 BITS はビットベクターの中の各要素について予約されるビット数です。 |
| 18773 | 21876 | BIT は、1 から 32 まで(プラットホームが |
| 18774 | 21877 | 対応していれば 64 まで) の 2 のべき乗でなければなりません。 |
| 18775 | 21878 | |
| 18776 | 21879 | =begin original |
| 18777 | 21880 | |
| 18778 | 21881 | If BITS is 8, "elements" coincide with bytes of the input string. |
| 18779 | 21882 | |
| 18780 | 21883 | =end original |
| 18781 | 21884 | |
| 18782 | 21885 | BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。 |
| 18783 | 21886 | |
| 18784 | 21887 | =begin original |
| 18785 | 21888 | |
| 18786 | 21889 | If BITS is 16 or more, bytes of the input string are grouped into chunks |
| 18787 | 21890 | of size BITS/8, and each group is converted to a number as with |
| 18788 | pack | |
| 21891 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with | |
| 18789 | for BITS==64). See | |
| 21892 | big-endian formats C<n>/C<N> (and analogously for BITS==64). See | |
| 21893 | L<C<pack>|/pack TEMPLATE,LIST> for details. | |
| 18790 | 21894 | |
| 18791 | 21895 | =end original |
| 18792 | 21896 | |
| 18793 | 21897 | BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに |
| 18794 | グループ化され、各グループは pack | |
| 21898 | グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/ | |
| 21899 | L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン | |
| 18795 | 21900 | フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。 |
| 18796 | 詳細は L< | |
| 21901 | 詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。 | |
| 18797 | 21902 | |
| 18798 | 21903 | =begin original |
| 18799 | 21904 | |
| 18800 | 21905 | If bits is 4 or less, the string is broken into bytes, then the bits |
| 18801 | 21906 | of each byte are broken into 8/BITS groups. Bits of a byte are |
| 18802 | 21907 | numbered in a little-endian-ish way, as in C<0x01>, C<0x02>, |
| 18803 | 21908 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example, |
| 18804 | 21909 | breaking the single input byte C<chr(0x36)> into two groups gives a list |
| 18805 | 21910 | C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>. |
| 18806 | 21911 | |
| 18807 | 21912 | =end original |
| 18808 | 21913 | |
| 18809 | 21914 | BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは |
| 18810 | 21915 | 8/BITS 個のグループに分割されます。 |
| 18811 | 21916 | ビットはリトルエンディアン風に、C<0x01>, C<0x02>, |
| 18812 | 21917 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。 |
| 18813 | 21918 | 例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、 |
| 18814 | 21919 | C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に |
| 18815 | 21920 | なります。 |
| 18816 | 21921 | |
| 18817 | 21922 | =begin original |
| 18818 | 21923 | |
| 18819 | C<vec> may also be assigned to, in which case | |
| 21924 | L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case | |
| 21925 | parentheses are needed | |
| 18820 | 21926 | to give the expression the correct precedence as in |
| 18821 | 21927 | |
| 18822 | 21928 | =end original |
| 18823 | 21929 | |
| 18824 | 左辺値として、代入の | |
| 21930 | L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の | |
| 21931 | 対象にすることもできます; この場合、式を正しく | |
| 18825 | 21932 | 先行させるために以下のように括弧が必要です: |
| 18826 | 21933 | |
| 18827 | 21934 | vec($image, $max_x * $x + $y, 8) = 3; |
| 18828 | 21935 | |
| 18829 | 21936 | =begin original |
| 18830 | 21937 | |
| 18831 | 21938 | If the selected element is outside the string, the value 0 is returned. |
| 18832 | 21939 | If an element off the end of the string is written to, Perl will first |
| 18833 | 21940 | extend the string with sufficiently many zero bytes. It is an error |
| 18834 | 21941 | to try to write off the beginning of the string (i.e., negative OFFSET). |
| 18835 | 21942 | |
| 18836 | 21943 | =end original |
| 18837 | 21944 | |
| 18838 | 21945 | 選択された要素が文字列の外側だった場合、値 0 が返されます。 |
| 18839 | 21946 | 文字列の最後よりも後ろの要素に書き込もうとした場合、 |
| 18840 | 21947 | Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。 |
| 18841 | 21948 | 文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった) |
| 18842 | 21949 | 場合はエラーとなります。 |
| 18843 | 21950 | |
| 18844 | 21951 | =begin original |
| 18845 | 21952 | |
| 18846 | 21953 | If the string happens to be encoded as UTF-8 internally (and thus has |
| 18847 | the UTF8 flag set), | |
| 21954 | the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it | |
| 18848 | ||
| 21955 | to use a one-byte-per-character internal representation. However, if the | |
| 18849 | ||
| 21956 | string contains characters with values of 256 or higher, a fatal error | |
| 21957 | will occur. | |
| 18850 | 21958 | |
| 18851 | 21959 | =end original |
| 18852 | 21960 | |
| 18853 | 文字列が | |
| 21961 | 文字列がたまたま内部で UTF-8 でエンコードされている場合(したがって | |
| 18854 | セットされている場合)、 | |
| 21962 | UTF8 フラグがセットされている場合)、 | |
| 18855 | 文字 | |
| 21963 | L<C<vec>|/vec EXPR,OFFSET,BITS> はこれを単一バイト文字内部表現に | |
| 18856 | ||
| 21964 | 変換しようとします。 | |
| 21965 | しかし、この文字列に値が 256 以上の文字が含まれている場合、 | |
| 21966 | 致命的エラーが発生します。 | |
| 18857 | 21967 | |
| 18858 | 21968 | =begin original |
| 18859 | 21969 | |
| 18860 | Strings created with C<vec> can also be | |
| 21970 | Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be | |
| 21971 | manipulated with the logical | |
| 18861 | 21972 | operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit |
| 18862 | 21973 | vector operation is desired when both operands are strings. |
| 18863 | 21974 | See L<perlop/"Bitwise String Operators">. |
| 18864 | 21975 | |
| 18865 | 21976 | =end original |
| 18866 | 21977 | |
| 18867 | C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、 | |
| 21978 | L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、 | |
| 18868 | 扱うこともできます。 | |
| 21979 | C<^>, C<~> で扱うこともできます。 | |
| 18869 | 21980 | これらの演算子は、両方の被演算子に文字列を使うと、 |
| 18870 | 21981 | ビットベクター演算を行ないます。 |
| 18871 | 21982 | L<perlop/"Bitwise String Operators"> を参照してください。 |
| 18872 | 21983 | |
| 18873 | 21984 | =begin original |
| 18874 | 21985 | |
| 18875 | 21986 | The following code will build up an ASCII string saying C<'PerlPerlPerl'>. |
| 18876 | 21987 | The comments show the string after each step. Note that this code works |
| 18877 | 21988 | in the same way on big-endian or little-endian machines. |
| 18878 | 21989 | |
| 18879 | 21990 | =end original |
| 18880 | 21991 | |
| 18881 | 21992 | 次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。 |
| 18882 | 21993 | コメントは各行の実行後の文字列を示します。 |
| 18883 | 21994 | このコードはビッグエンディアンでもリトルエンディアンでも同じように |
| 18884 | 21995 | 動作することに注意してください。 |
| 18885 | 21996 | |
| 18886 | 21997 | my $foo = ''; |
| 18887 | 21998 | vec($foo, 0, 32) = 0x5065726C; # 'Perl' |
| 18888 | 21999 | |
| 18889 | 22000 | # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits |
| 18890 | 22001 | print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P') |
| 18891 | 22002 | |
| 18892 | 22003 | vec($foo, 2, 16) = 0x5065; # 'PerlPe' |
| 18893 | 22004 | vec($foo, 3, 16) = 0x726C; # 'PerlPerl' |
| 18894 | 22005 | vec($foo, 8, 8) = 0x50; # 'PerlPerlP' |
| 18895 | 22006 | vec($foo, 9, 8) = 0x65; # 'PerlPerlPe' |
| 18896 | 22007 | vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02" |
| 18897 | 22008 | vec($foo, 21, 4) = 7; # 'PerlPerlPer' |
| 18898 | 22009 | # 'r' is "\x72" |
| 18899 | 22010 | vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c" |
| 18900 | 22011 | vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c" |
| 18901 | 22012 | vec($foo, 94, 1) = 1; # 'PerlPerlPerl' |
| 18902 | 22013 | # 'l' is "\x6c" |
| 18903 | 22014 | |
| 18904 | 22015 | =begin original |
| 18905 | 22016 | |
| 18906 | 22017 | To transform a bit vector into a string or list of 0's and 1's, use these: |
| 18907 | 22018 | |
| 18908 | 22019 | =end original |
| 18909 | 22020 | |
| 18910 | 22021 | ビットベクターを、0 と 1 の文字列や配列に変換するには、 |
| 18911 | 22022 | 以下のようにします。 |
| 18912 | 22023 | |
| 18913 | $bits = unpack("b*", $vector); | |
| 22024 | my $bits = unpack("b*", $vector); | |
| 18914 | @bits = split(//, unpack("b*", $vector)); | |
| 22025 | my @bits = split(//, unpack("b*", $vector)); | |
| 18915 | 22026 | |
| 18916 | 22027 | =begin original |
| 18917 | 22028 | |
| 18918 | 22029 | If you know the exact length in bits, it can be used in place of the C<*>. |
| 18919 | 22030 | |
| 18920 | 22031 | =end original |
| 18921 | 22032 | |
| 18922 | 22033 | ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。 |
| 18923 | 22034 | |
| 18924 | 22035 | =begin original |
| 18925 | 22036 | |
| 18926 | 22037 | Here is an example to illustrate how the bits actually fall in place: |
| 18927 | 22038 | |
| 18928 | 22039 | =end original |
| 18929 | 22040 | |
| 18930 | 22041 | これはビットが実際にどのような位置に入るかを図示する例です。 |
| 18931 | 22042 | |
| 18932 | 22043 | #!/usr/bin/perl -wl |
| 18933 | 22044 | |
| 18934 | 22045 | print <<'EOT'; |
| 18935 | 22046 | 0 1 2 3 |
| 18936 | 22047 | unpack("V",$_) 01234567890123456789012345678901 |
| 18937 | 22048 | ------------------------------------------------------------------ |
| 18938 | 22049 | EOT |
| 18939 | 22050 | |
| 18940 | 22051 | for $w (0..3) { |
| 18941 | 22052 | $width = 2**$w; |
| 18942 | 22053 | for ($shift=0; $shift < $width; ++$shift) { |
| 18943 | 22054 | for ($off=0; $off < 32/$width; ++$off) { |
| 18944 | 22055 | $str = pack("B*", "0"x32); |
| 18945 | 22056 | $bits = (1<<$shift); |
| 18946 | 22057 | vec($str, $off, $width) = $bits; |
| 18947 | 22058 | $res = unpack("b*",$str); |
| 18948 | 22059 | $val = unpack("V", $str); |
| 18949 | 22060 | write; |
| 18950 | 22061 | } |
| 18951 | 22062 | } |
| 18952 | 22063 | } |
| 18953 | 22064 | |
| 18954 | 22065 | format STDOUT = |
| 18955 | 22066 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 18956 | 22067 | $off, $width, $bits, $val, $res |
| 18957 | 22068 | . |
| 18958 | 22069 | __END__ |
| 18959 | 22070 | |
| 18960 | 22071 | =begin original |
| 18961 | 22072 | |
| 18962 | Regardless of the machine architecture on which it runs, the | |
| 22073 | Regardless of the machine architecture on which it runs, the | |
| 18963 | 22074 | example above should print the following table: |
| 18964 | 22075 | |
| 18965 | 22076 | =end original |
| 18966 | 22077 | |
| 18967 | 22078 | 実行するマシンのアーキテクチャに関わらず、 |
| 18968 | 22079 | 上記の例は以下の表を出力します。 |
| 18969 | 22080 | |
| 18970 | 22081 | 0 1 2 3 |
| 18971 | 22082 | unpack("V",$_) 01234567890123456789012345678901 |
| 18972 | 22083 | ------------------------------------------------------------------ |
| 18973 | 22084 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 |
| 18974 | 22085 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 |
| 18975 | 22086 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 |
| 18976 | 22087 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 |
| 18977 | 22088 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 |
| 18978 | 22089 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 |
| 18979 | 22090 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 |
| 18980 | 22091 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 |
| 18981 | 22092 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 |
| 18982 | 22093 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 |
| 18983 | 22094 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 |
| 18984 | 22095 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 |
| 18985 | 22096 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 |
| 18986 | 22097 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 |
| 18987 | 22098 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 |
| 18988 | 22099 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 |
| 18989 | 22100 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 |
| 18990 | 22101 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 |
| 18991 | 22102 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 |
| 18992 | 22103 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 |
| 18993 | 22104 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 |
| 18994 | 22105 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 |
| 18995 | 22106 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 |
| 18996 | 22107 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 |
| 18997 | 22108 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 |
| 18998 | 22109 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 |
| 18999 | 22110 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 |
| 19000 | 22111 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 |
| 19001 | 22112 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 |
| 19002 | 22113 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 |
| 19003 | 22114 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 |
| 19004 | 22115 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 |
| 19005 | 22116 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 |
| 19006 | 22117 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 |
| 19007 | 22118 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 |
| 19008 | 22119 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 |
| 19009 | 22120 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 |
| 19010 | 22121 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 |
| 19011 | 22122 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 |
| 19012 | 22123 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 |
| 19013 | 22124 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 |
| 19014 | 22125 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 |
| 19015 | 22126 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 |
| 19016 | 22127 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 |
| 19017 | 22128 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 |
| 19018 | 22129 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 |
| 19019 | 22130 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 |
| 19020 | 22131 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 |
| 19021 | 22132 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 |
| 19022 | 22133 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 |
| 19023 | 22134 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 |
| 19024 | 22135 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 |
| 19025 | 22136 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 |
| 19026 | 22137 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 |
| 19027 | 22138 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 |
| 19028 | 22139 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 |
| 19029 | 22140 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 |
| 19030 | 22141 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 |
| 19031 | 22142 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 |
| 19032 | 22143 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 |
| 19033 | 22144 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 |
| 19034 | 22145 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 |
| 19035 | 22146 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 |
| 19036 | 22147 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 |
| 19037 | 22148 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 |
| 19038 | 22149 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 |
| 19039 | 22150 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 |
| 19040 | 22151 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 |
| 19041 | 22152 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 |
| 19042 | 22153 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 |
| 19043 | 22154 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 |
| 19044 | 22155 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 |
| 19045 | 22156 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 |
| 19046 | 22157 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 |
| 19047 | 22158 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 |
| 19048 | 22159 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 |
| 19049 | 22160 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 |
| 19050 | 22161 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 |
| 19051 | 22162 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 |
| 19052 | 22163 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 |
| 19053 | 22164 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 |
| 19054 | 22165 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 |
| 19055 | 22166 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 |
| 19056 | 22167 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 |
| 19057 | 22168 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 |
| 19058 | 22169 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 |
| 19059 | 22170 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 |
| 19060 | 22171 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 |
| 19061 | 22172 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 |
| 19062 | 22173 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 |
| 19063 | 22174 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 |
| 19064 | 22175 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 |
| 19065 | 22176 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 |
| 19066 | 22177 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 |
| 19067 | 22178 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 |
| 19068 | 22179 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 |
| 19069 | 22180 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 |
| 19070 | 22181 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 |
| 19071 | 22182 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 |
| 19072 | 22183 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 |
| 19073 | 22184 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 |
| 19074 | 22185 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 |
| 19075 | 22186 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 |
| 19076 | 22187 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 |
| 19077 | 22188 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 |
| 19078 | 22189 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 |
| 19079 | 22190 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 |
| 19080 | 22191 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 |
| 19081 | 22192 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 |
| 19082 | 22193 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 |
| 19083 | 22194 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 |
| 19084 | 22195 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 |
| 19085 | 22196 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 |
| 19086 | 22197 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 |
| 19087 | 22198 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 |
| 19088 | 22199 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 |
| 19089 | 22200 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 |
| 19090 | 22201 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 |
| 19091 | 22202 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 |
| 19092 | 22203 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 |
| 19093 | 22204 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 |
| 19094 | 22205 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 |
| 19095 | 22206 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 |
| 19096 | 22207 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 |
| 19097 | 22208 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 |
| 19098 | 22209 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 |
| 19099 | 22210 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 |
| 19100 | 22211 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 |
| 19101 | 22212 | |
| 19102 | 22213 | =item wait |
| 19103 | 22214 | X<wait> |
| 19104 | 22215 | |
| 19105 | 22216 | =for Pod::Functions wait for any child process to die |
| 19106 | 22217 | |
| 19107 | 22218 | =begin original |
| 19108 | 22219 | |
| 19109 | Behaves like wait(2) on your system: it waits for a child | |
| 22220 | Behaves like L<wait(2)> on your system: it waits for a child | |
| 19110 | 22221 | process to terminate and returns the pid of the deceased process, or |
| 19111 | C<-1> if there are no child processes. The status is returned in | |
| 22222 | C<-1> if there are no child processes. The status is returned in | |
| 19112 | ||
| 22223 | L<C<$?>|perlvar/$?> and | |
| 22224 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 19113 | 22225 | Note that a return value of C<-1> could mean that child processes are |
| 19114 | 22226 | being automatically reaped, as described in L<perlipc>. |
| 19115 | 22227 | |
| 19116 | 22228 | =end original |
| 19117 | 22229 | |
| 19118 | wait(2) と同様に振る舞います: チャイルドプロセスが終了するのを待ち、 | |
| 22230 | L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、 | |
| 19119 | プロセスの pid を返します; チャイルドプロセスが存在しないときには、 | |
| 22231 | 消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、 | |
| 19120 | 返します。 | |
| 22232 | C<-1> を返します。 | |
| 19121 | ステータスは C<$?> | |
| 22233 | ステータスは L<C<$?>|perlvar/$?> と | |
| 22234 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
| 19122 | 22235 | L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが |
| 19123 | 22236 | 自動的に刈り取られたことを意味するかもしれないことに注意してください。 |
| 19124 | 22237 | |
| 19125 | 22238 | =begin original |
| 19126 | 22239 | |
| 19127 | If you use wait in your handler for | |
| 22240 | If you use L<C<wait>|/wait> in your handler for | |
| 19128 | ||
| 22241 | L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child | |
| 22242 | created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>. | |
| 22243 | See L<perlipc> for details. | |
| 19129 | 22244 | |
| 19130 | 22245 | =end original |
| 19131 | 22246 | |
| 19132 | wait を $SIG{CHLD} のハンドラで使うと、誤って | |
| 22247 | L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って | |
| 19133 | ||
| 22248 | L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって | |
| 22249 | 作られた子を待つことになるかも知れません。 | |
| 19134 | 22250 | 詳しくは L<perlipc> を参照してください。 |
| 19135 | 22251 | |
| 19136 | 22252 | =begin original |
| 19137 | 22253 | |
| 19138 | 22254 | Portability issues: L<perlport/wait>. |
| 19139 | 22255 | |
| 19140 | 22256 | =end original |
| 19141 | 22257 | |
| 19142 | 22258 | 移植性の問題: L<perlport/wait>。 |
| 19143 | 22259 | |
| 19144 | 22260 | =item waitpid PID,FLAGS |
| 19145 | 22261 | X<waitpid> |
| 19146 | 22262 | |
| 19147 | 22263 | =for Pod::Functions wait for a particular child process to die |
| 19148 | 22264 | |
| 19149 | 22265 | =begin original |
| 19150 | 22266 | |
| 19151 | 22267 | Waits for a particular child process to terminate and returns the pid of |
| 19152 | the deceased process, or C<-1> if there is no such child process. | |
| 22268 | the deceased process, or C<-1> if there is no such child process. A | |
| 19153 | ||
| 22269 | non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if | |
| 19154 | ||
| 22270 | there are child processes matching PID but none have terminated yet. | |
| 22271 | The status is returned in L<C<$?>|perlvar/$?> and | |
| 22272 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 19155 | 22273 | |
| 19156 | 22274 | =end original |
| 19157 | 22275 | |
| 19158 | 特定の | |
| 22276 | 特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を | |
| 19159 | 返します; 指定した | |
| 22277 | 返します; 指定した子プロセスが存在しないときには、C<-1> を返します。 | |
| 19160 | ||
| 22278 | (FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブロッキング wait は、 | |
| 19161 | ||
| 22279 | PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を | |
| 19162 | ||
| 22280 | 返すことがあります。 | |
| 22281 | ステータスは L<C<$?>|perlvar/$?> と | |
| 22282 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
| 19163 | 22283 | |
| 22284 | =begin original | |
| 22285 | ||
| 22286 | A PID of C<0> indicates to wait for any child process whose process group ID is | |
| 22287 | equal to that of the current process. A PID of less than C<-1> indicates to | |
| 22288 | wait for any child process whose process group ID is equal to -PID. A PID of | |
| 22289 | C<-1> indicates to wait for any child process. | |
| 22290 | ||
| 22291 | =end original | |
| 22292 | ||
| 22293 | PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである | |
| 22294 | 任意の子プロセスを wait します。 | |
| 22295 | PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい | |
| 22296 | 任意の子プロセスを wait します。 | |
| 22297 | PID に C<-1> を指定すると任意の子プロセスを wait します。 | |
| 22298 | ||
| 22299 | =begin original | |
| 22300 | ||
| 22301 | If you say | |
| 22302 | ||
| 22303 | =end original | |
| 22304 | ||
| 22305 | 以下のようにするか | |
| 22306 | ||
| 19164 | 22307 | use POSIX ":sys_wait_h"; |
| 19165 | ||
| 22309 | my $kid; | |
| 19166 | 22310 | do { |
| 19167 | 22311 | $kid = waitpid(-1, WNOHANG); |
| 19168 | 22312 | } while $kid > 0; |
| 19169 | 22313 | |
| 19170 | 22314 | =begin original |
| 19171 | 22315 | |
| 19172 | ||
| 22316 | or | |
| 22317 | ||
| 22318 | =end original | |
| 22319 | ||
| 22320 | または | |
| 22321 | ||
| 22322 | 1 while waitpid(-1, WNOHANG) > 0; | |
| 22323 | ||
| 22324 | =begin original | |
| 22325 | ||
| 22326 | then you can do a non-blocking wait for all pending zombie processes (see | |
| 22327 | L<POSIX/WAIT>). | |
| 19173 | 22328 | Non-blocking wait is available on machines supporting either the |
| 19174 | waitpid(2) or wait4(2) syscalls. However, waiting for a particular | |
| 22329 | L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular | |
| 19175 | 22330 | pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the |
| 19176 | 22331 | system call by remembering the status values of processes that have |
| 19177 | 22332 | exited but have not been harvested by the Perl script yet.) |
| 19178 | 22333 | |
| 19179 | 22334 | =end original |
| 19180 | 22335 | |
| 19181 | ブロックが起こらないようにして、全ての待機中ゾンビプロセスを | |
| 22336 | とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを | |
| 19182 | ||
| 22337 | wait します (L<POSIX/WAIT> を参照してください)。 | |
| 19183 | システムコール wait | |
| 22338 | ブロックなしの wait は、システムコール L<wait_pid(2)> か、 | |
| 22339 | システムコール L<wait4(2)> をサポートしているマシンで利用可能です。 | |
| 19184 | 22340 | しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも |
| 19185 | 22341 | 実装されています。 |
| 19186 | 22342 | (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを |
| 19187 | 22343 | エミュレートしますが、Perl スクリプトには取り入れられていません。) |
| 19188 | 22344 | |
| 19189 | 22345 | =begin original |
| 19190 | 22346 | |
| 19191 | 22347 | Note that on some systems, a return value of C<-1> could mean that child |
| 19192 | 22348 | processes are being automatically reaped. See L<perlipc> for details, |
| 19193 | 22349 | and for other examples. |
| 19194 | 22350 | |
| 19195 | 22351 | =end original |
| 19196 | 22352 | |
| 19197 | 22353 | システムによっては、返り値が C<-1> の場合は子プロセスが自動的に |
| 19198 | 22354 | 刈り取られたことを意味するかもしれないことに注意してください。 |
| 19199 | 22355 | 詳細やその他の例については L<perlipc> を参照してください。 |
| 19200 | 22356 | |
| 19201 | 22357 | =begin original |
| 19202 | 22358 | |
| 19203 | 22359 | Portability issues: L<perlport/waitpid>. |
| 19204 | 22360 | |
| 19205 | 22361 | =end original |
| 19206 | 22362 | |
| 19207 | 22363 | 移植性の問題: L<perlport/waitpid>。 |
| 19208 | 22364 | |
| 19209 | 22365 | =item wantarray |
| 19210 | 22366 | X<wantarray> X<context> |
| 19211 | 22367 | |
| 19212 | 22368 | =for Pod::Functions get void vs scalar vs list context of current subroutine call |
| 19213 | 22369 | |
| 19214 | 22370 | =begin original |
| 19215 | 22371 | |
| 19216 | 22372 | Returns true if the context of the currently executing subroutine or |
| 19217 | C<eval> is looking for a list value. Returns false if the | |
| 22373 | L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the | |
| 22374 | context is | |
| 19218 | 22375 | looking for a scalar. Returns the undefined value if the context is |
| 19219 | 22376 | looking for no value (void context). |
| 19220 | 22377 | |
| 19221 | 22378 | =end original |
| 19222 | 22379 | |
| 19223 | 現在実行中のサブルーチンか eval | |
| 22380 | 現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、 | |
| 19224 | 要求するものであれば、真を返します。 | |
| 22381 | リスト値を要求するものであれば、真を返します。 | |
| 19225 | 22382 | スカラを要求するコンテキストであれば、偽を返します。 |
| 19226 | 22383 | 何も値を要求しない(無効コンテキスト)場合は未定義値を返します。 |
| 19227 | 22384 | |
| 19228 | 22385 | return unless defined wantarray; # don't bother doing more |
| 19229 | 22386 | my @a = complex_calculation(); |
| 19230 | 22387 | return wantarray ? @a : "@a"; |
| 19231 | 22388 | |
| 19232 | 22389 | =begin original |
| 19233 | 22390 | |
| 19234 | C<wantarray | |
| 22391 | L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file, | |
| 19235 | 22392 | in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or |
| 19236 | 22393 | in a C<DESTROY> method. |
| 19237 | 22394 | |
| 19238 | 22395 | =end original |
| 19239 | 22396 | |
| 19240 | 22397 | ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END> |
| 19241 | ブロック内、C<DESTROY> メソッド内では C<wantarray | |
| 22398 | ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は | |
| 22399 | 未定義です。 | |
| 19242 | 22400 | |
| 19243 | 22401 | =begin original |
| 19244 | 22402 | |
| 19245 | 22403 | This function should have been named wantlist() instead. |
| 19246 | 22404 | |
| 19247 | 22405 | =end original |
| 19248 | 22406 | |
| 19249 | 22407 | この関数は wantlist() という名前にするべきでした。 |
| 19250 | 22408 | |
| 19251 | 22409 | =item warn LIST |
| 19252 | 22410 | X<warn> X<warning> X<STDERR> |
| 19253 | 22411 | |
| 19254 | 22412 | =for Pod::Functions print debugging info |
| 19255 | 22413 | |
| 19256 | 22414 | =begin original |
| 19257 | 22415 | |
| 19258 | ||
| 22416 | Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets | |
| 19259 | ||
| 22417 | its operand LIST in the same way as C<die>, but is slightly different | |
| 19260 | does. | |
| 22418 | in what it defaults to when LIST is empty or makes an empty string. | |
| 22419 | If it is empty and L<C<$@>|perlvar/$@> already contains an exception | |
| 22420 | value then that value is used after appending C<"\t...caught">. If it | |
| 22421 | is empty and C<$@> is also empty then the string C<"Warning: Something's | |
| 22422 | wrong"> is used. | |
| 19261 | 22423 | |
| 19262 | 22424 | =end original |
| 19263 | 22425 | |
| 19264 | ||
| 22426 | (通常は C<STDERR> に表示することで) 警告を出力します。 | |
| 19265 | LIST | |
| 22427 | C<warn> はそのオペランド LIST を C<die> と同様に解釈しますが、 | |
| 19266 | フ | |
| 22428 | LIST が空や空文字列を作る時に何をデフォルトとするかが少し異なります。 | |
| 22429 | それが空かつ、L<C<$@>|perlvar/$@> に既に | |
| 22430 | 例外値が入っている場合、C<"\t...caught"> を追加した値が | |
| 22431 | 用いられます。 | |
| 22432 | もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という | |
| 22433 | 文字列が使われます。 | |
| 19267 | 22434 | |
| 19268 | 22435 | =begin original |
| 19269 | 22436 | |
| 19270 | ||
| 22437 | By default, the exception derived from the operand LIST is stringified | |
| 19271 | pr | |
| 22438 | and printed to C<STDERR>. This behaviour can be altered by installing | |
| 19272 | ||
| 22439 | a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a | |
| 19273 | ||
| 22440 | handler then no message is automatically printed; it is the handler's | |
| 22441 | responsibility to deal with the exception | |
| 19275 | ||
| 22442 | as it sees fit (like, for instance, converting it into a | |
| 22443 | L<C<die>|/die LIST>). Most | |
| 19277 | 出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている | |
| 19278 | 場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。 | |
| 19279 | これはほとんどそのままにするときに便利ですが、 | |
| 19280 | C<die> と全体的に似ているわけではありません。 | |
| 19281 | ||
| 19282 | =begin original | |
| 19283 | ||
| 19284 | If C<$@> is empty then the string C<"Warning: Something's wrong"> is used. | |
| 19285 | ||
| 19286 | =end original | |
| 19287 | ||
| 19288 | C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が | |
| 19289 | 使われます。 | |
| 19290 | ||
| 19291 | =begin original | |
| 19292 | ||
| 19293 | No message is printed if there is a C<$SIG{__WARN__}> handler | |
| 19294 | installed. It is the handler's responsibility to deal with the message | |
| 19295 | as it sees fit (like, for instance, converting it into a C<die>). Most | |
| 19296 | 22444 | handlers must therefore arrange to actually display the |
| 19297 | warnings that they are not prepared to deal with, by calling | |
| 22445 | warnings that they are not prepared to deal with, by calling | |
| 22446 | L<C<warn>|/warn LIST> | |
| 19298 | 22447 | again in the handler. Note that this is quite safe and will not |
| 19299 | 22448 | produce an endless loop, since C<__WARN__> hooks are not called from |
| 19300 | 22449 | inside one. |
| 19301 | 22450 | |
| 19302 | 22451 | =end original |
| 19303 | 22452 | |
| 19304 | ||
| 22453 | デフォルトでは、LIST オペランドから生成された例外は | |
| 19305 | 表示されま | |
| 22454 | 文字列化されて C<STDERR> に表示されます。 | |
| 19306 | ||
| 22455 | この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで | |
| 22456 | 置き換えられます。 | |
| 22457 | このようなハンドラが設定されている場合は何の | |
| 22458 | メッセージも自動的には表示されません; | |
| 22459 | 例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの | |
| 19307 | 22460 | 責任ということです。 |
| 19308 | 22461 | 従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、 |
| 19309 | ハンドラの中で C<warn> を再び呼び出します。 | |
| 22462 | ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。 | |
| 19310 | 22463 | C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、 |
| 19311 | 22464 | 無限ループを引き起こすことはないということに注意してください。 |
| 19312 | 22465 | |
| 19313 | 22466 | =begin original |
| 19314 | 22467 | |
| 19315 | 22468 | You will find this behavior is slightly different from that of |
| 19316 | C<$SIG{__DIE__}> handlers (which don't suppress the | |
| 22469 | L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the | |
| 19317 | instead call C<die> again to change | |
| 22470 | error text, but can instead call L<C<die>|/die LIST> again to change | |
| 22471 | it). | |
| 19318 | 22472 | |
| 19319 | 22473 | =end original |
| 19320 | 22474 | |
| 19321 | この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは | |
| 22475 | この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは | |
| 19322 | 代わりに C<die> をもう一度呼び出すことで | |
| 22476 | 削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで | |
| 19323 | 少し違うことに気付くことでしょう。 | |
| 22477 | 変更できます)とは少し違うことに気付くことでしょう。 | |
| 19324 | 22478 | |
| 19325 | 22479 | =begin original |
| 19326 | 22480 | |
| 19327 | 22481 | Using a C<__WARN__> handler provides a powerful way to silence all |
| 19328 | 22482 | warnings (even the so-called mandatory ones). An example: |
| 19329 | 22483 | |
| 19330 | 22484 | =end original |
| 19331 | 22485 | |
| 19332 | 22486 | C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての |
| 19333 | 22487 | 警告を黙らせる強力な手段となります。 |
| 19334 | 22488 | 例: |
| 19335 | 22489 | |
| 19336 | 22490 | # wipe out *all* compile-time warnings |
| 19337 | 22491 | BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } |
| 19338 | 22492 | my $foo = 10; |
| 19339 | 22493 | my $foo = 20; # no warning about duplicate my $foo, |
| 19340 | 22494 | # but hey, you asked for it! |
| 19341 | 22495 | # no compile-time or run-time warnings before here |
| 19342 | 22496 | $DOWARN = 1; |
| 19343 | 22497 | |
| 19344 | 22498 | # run-time warnings enabled after here |
| 19345 | 22499 | warn "\$foo is alive and $foo!"; # does show up |
| 19346 | 22500 | |
| 19347 | 22501 | =begin original |
| 19348 | 22502 | |
| 19349 | See L<perlvar> for details on setting C<%SIG> entries | |
| 22503 | See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries | |
| 19350 | ||
| 22504 | and for more | |
| 19351 | ||
| 22505 | examples. See the L<Carp> module for other kinds of warnings using its | |
| 22506 | C<carp> and C<cluck> functions. | |
| 19352 | 22507 | |
| 19353 | 22508 | =end original |
| 19354 | 22509 | |
| 19355 | C<%SIG> エントリのセットに関する詳細とさらなる例に関しては | |
| 22510 | L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては | |
| 19356 | 22511 | L<perlvar> を参照してください。 |
| 19357 | carp | |
| 22512 | C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては | |
| 19358 | Carp モジュールを参照してください。 | |
| 22513 | L<Carp> モジュールを参照してください。 | |
| 19359 | 22514 | |
| 19360 | 22515 | =item write FILEHANDLE |
| 19361 | 22516 | X<write> |
| 19362 | 22517 | |
| 19363 | 22518 | =item write EXPR |
| 19364 | 22519 | |
| 19365 | 22520 | =item write |
| 19366 | 22521 | |
| 19367 | 22522 | =for Pod::Functions print a picture record |
| 19368 | 22523 | |
| 19369 | 22524 | =begin original |
| 19370 | 22525 | |
| 19371 | 22526 | Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, |
| 19372 | 22527 | using the format associated with that file. By default the format for |
| 19373 | 22528 | a file is the one having the same name as the filehandle, but the |
| 19374 | format for the current output channel (see the | |
| 22529 | format for the current output channel (see the | |
| 19375 | e | |
| 22530 | L<C<select>|/select FILEHANDLE> function) may be set explicitly by | |
| 22531 | assigning the name of the format to the L<C<$~>|perlvar/$~> variable. | |
| 19376 | 22532 | |
| 19377 | 22533 | =end original |
| 19378 | 22534 | |
| 19379 | 22535 | 指定された FILEHANDLE に対して、そのファイルに対応させた |
| 19380 | 22536 | フォーマットを使って、(複数行の場合もある) 整形された |
| 19381 | 22537 | レコードを書き出します。 |
| 19382 | 22538 | デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと |
| 19383 | 同じ名前のものですが、その時点の出力チャネル | |
| 22539 | 同じ名前のものですが、その時点の出力チャネル | |
| 19384 | ||
| 22540 | (L<C<select>|/select FILEHANDLE> 関数の項を | |
| 19385 | ||
| 22541 | 参照してください) のフォーマットは、その名前を明示的に変数 | |
| 22542 | L<C<$~>|perlvar/$~> に代入することで、変更が可能です。 | |
| 19386 | 22543 | |
| 19387 | 22544 | =begin original |
| 19388 | 22545 | |
| 19389 | 22546 | Top of form processing is handled automatically: if there is insufficient |
| 19390 | 22547 | room on the current page for the formatted record, the page is advanced by |
| 19391 | writing a form feed | |
| 22548 | writing a form feed and a special top-of-page | |
| 22549 | format is used to format the new | |
| 19392 | 22550 | page header before the record is written. By default, the top-of-page |
| 19393 | format is the name of the filehandle with | |
| 22551 | format is the name of the filehandle with C<_TOP> appended, or C<top> | |
| 22552 | in the current package if the former does not exist. This would be a | |
| 19394 | 22553 | problem with autovivified filehandles, but it may be dynamically set to the |
| 19395 | format of your choice by assigning the name to the C<$^> | |
| 22554 | format of your choice by assigning the name to the L<C<$^>|perlvar/$^> | |
| 19396 | that filehandle is selected. The number of lines | |
| 22555 | variable while that filehandle is selected. The number of lines | |
| 19397 | page is in variable C<$->, which | |
| 22556 | remaining on the current page is in variable L<C<$->|perlvar/$->, which | |
| 22557 | can be set to C<0> to force a new page. | |
| 19398 | 22558 | |
| 19399 | 22559 | =end original |
| 19400 | 22560 | |
| 19401 | 22561 | ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された |
| 19402 | 22562 | レコードを出力するだけのスペースがない場合には、改ページを行なってページを |
| 19403 | 22563 | 進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、 |
| 19404 | 22564 | その後でレコードが書かれます。 |
| 19405 | 22565 | デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に |
| 19406 | ||
| 22566 | C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの | |
| 22567 | C<top> です。 | |
| 19407 | 22568 | これは自動有効化されたファイルハンドルで問題になる可能性がありますが、 |
| 19408 | 22569 | ファイルハンドルが選択されている間に、 |
| 19409 | 変数 C<$^> に名前を設定すれば、動的にフォーマットを | |
| 22570 | 変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを | |
| 19410 | 22571 | 変更することができます。 |
| 19411 | そのページの残り行数は、変数 C<$-> に入っており、この変数を | |
| 22572 | そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を | |
| 19412 | 設定することで、強制的に改ページを行なうことができます。 | |
| 22573 | C<0> に設定することで、強制的に改ページを行なうことができます。 | |
| 19413 | 22574 | |
| 19414 | 22575 | =begin original |
| 19415 | 22576 | |
| 19416 | 22577 | If FILEHANDLE is unspecified, output goes to the current default output |
| 19417 | 22578 | channel, which starts out as STDOUT but may be changed by the |
| 19418 | C<select> operator. If the FILEHANDLE is an EXPR, | |
| 22579 | L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR, | |
| 22580 | then the expression | |
| 19419 | 22581 | is evaluated and the resulting string is used to look up the name of |
| 19420 | 22582 | the FILEHANDLE at run time. For more on formats, see L<perlform>. |
| 19421 | 22583 | |
| 19422 | 22584 | =end original |
| 19423 | 22585 | |
| 19424 | 22586 | FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して |
| 19425 | 22587 | 行なわれます; これは、スクリプトの開始時点では STDOUT ですが、 |
| 19426 | select | |
| 22588 | L<C<select>|/select FILEHANDLE> 演算子で変更することができます。 | |
| 19427 | 22589 | FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が |
| 19428 | 22590 | 実行時に FILEHANDLE の名前として見られます。 |
| 19429 | 22591 | フォーマットについて、さらには、L<perlform> を参照してください。 |
| 19430 | 22592 | |
| 19431 | 22593 | =begin original |
| 19432 | 22594 | |
| 19433 | Note that write is I<not> the opposite of | |
| 22595 | Note that write is I<not> the opposite of | |
| 22596 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately. | |
| 19434 | 22597 | |
| 19435 | 22598 | =end original |
| 19436 | 22599 | |
| 19437 | write は C<read> | |
| 22600 | write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の | |
| 22601 | 反対のことをするもの I<ではありません>。 | |
| 19438 | 22602 | 残念ながら。 |
| 19439 | 22603 | |
| 19440 | 22604 | =item y/// |
| 19441 | 22605 | |
| 19442 | 22606 | =for Pod::Functions transliterate a string |
| 19443 | 22607 | |
| 19444 | 22608 | =begin original |
| 19445 | 22609 | |
| 19446 | The transliteration operator. Same as | |
| 22610 | The transliteration operator. Same as | |
| 19447 | L< | |
| 22611 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See | |
| 22612 | L<perlop/"Quote-Like Operators">. | |
| 19448 | 22613 | |
| 19449 | 22614 | =end original |
| 19450 | 22615 | |
| 19451 | 22616 | 文字変換演算子です。 |
| 19452 | C<tr/ | |
| 22617 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。 | |
| 19453 | L<perlop/"Quote | |
| 22618 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
| 19454 | 22619 | |
| 19455 | 22620 | =back |
| 19456 | 22621 | |
| 19457 | 22622 | =head2 Non-function Keywords by Cross-reference |
| 19458 | 22623 | |
| 19459 | 22624 | =head3 perldata |
| 19460 | 22625 | |
| 19461 | 22626 | =over |
| 19462 | 22627 | |
| 19463 | 22628 | =item __DATA__ |
| 19464 | 22629 | |
| 19465 | 22630 | =item __END__ |
| 19466 | 22631 | |
| 19467 | 22632 | =begin original |
| 19468 | 22633 | |
| 19469 | 22634 | These keywords are documented in L<perldata/"Special Literals">. |
| 19470 | 22635 | |
| 19471 | 22636 | =end original |
| 19472 | 22637 | |
| 19473 | 22638 | これらのキーワードは L<perldata/"Special Literals"> で文書化されています。 |
| 19474 | 22639 | |
| 19475 | 22640 | =back |
| 19476 | 22641 | |
| 19477 | 22642 | =head3 perlmod |
| 19478 | 22643 | |
| 19479 | 22644 | =over |
| 19480 | 22645 | |
| 19481 | 22646 | =item BEGIN |
| 19482 | 22647 | |
| 19483 | 22648 | =item CHECK |
| 19484 | 22649 | |
| 19485 | 22650 | =item END |
| 19486 | 22651 | |
| 19487 | 22652 | =item INIT |
| 19488 | 22653 | |
| 19489 | 22654 | =item UNITCHECK |
| 19490 | 22655 | |
| 19491 | 22656 | =begin original |
| 19492 | 22657 | |
| 19493 | 22658 | These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">. |
| 19494 | 22659 | |
| 19495 | 22660 | =end original |
| 19496 | 22661 | |
| 19497 | 22662 | これらのコンパイルフェーズキーワードは |
| 19498 | 22663 | L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。 |
| 19499 | 22664 | |
| 19500 | 22665 | =back |
| 19501 | 22666 | |
| 19502 | 22667 | =head3 perlobj |
| 19503 | 22668 | |
| 19504 | 22669 | =over |
| 19505 | 22670 | |
| 19506 | 22671 | =item DESTROY |
| 19507 | 22672 | |
| 19508 | 22673 | =begin original |
| 19509 | 22674 | |
| 19510 | 22675 | This method keyword is documented in L<perlobj/"Destructors">. |
| 19511 | 22676 | |
| 19512 | 22677 | =end original |
| 19513 | 22678 | |
| 19514 | 22679 | このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。 |
| 19515 | 22680 | |
| 19516 | 22681 | =back |
| 19517 | 22682 | |
| 19518 | 22683 | =head3 perlop |
| 19519 | 22684 | |
| 19520 | 22685 | =over |
| 19521 | 22686 | |
| 19522 | 22687 | =item and |
| 19523 | 22688 | |
| 19524 | 22689 | =item cmp |
| 19525 | 22690 | |
| 19526 | 22691 | =item eq |
| 19527 | 22692 | |
| 19528 | 22693 | =item ge |
| 19529 | 22694 | |
| 19530 | 22695 | =item gt |
| 19531 | 22696 | |
| 19532 | =item i | |
| 22697 | =item isa | |
| 19533 | 22698 | |
| 19534 | 22699 | =item le |
| 19535 | 22700 | |
| 19536 | 22701 | =item lt |
| 19537 | 22702 | |
| 19538 | 22703 | =item ne |
| 19539 | 22704 | |
| 19540 | 22705 | =item not |
| 19541 | 22706 | |
| 19542 | 22707 | =item or |
| 19543 | 22708 | |
| 19544 | 22709 | =item x |
| 19545 | 22710 | |
| 19546 | 22711 | =item xor |
| 19547 | 22712 | |
| 19548 | 22713 | =begin original |
| 19549 | 22714 | |
| 19550 | 22715 | These operators are documented in L<perlop>. |
| 19551 | 22716 | |
| 19552 | 22717 | =end original |
| 19553 | 22718 | |
| 19554 | 22719 | これらの演算子は L<perlop> で文書化されています。 |
| 19555 | 22720 | |
| 19556 | 22721 | =back |
| 19557 | 22722 | |
| 19558 | 22723 | =head3 perlsub |
| 19559 | 22724 | |
| 19560 | 22725 | =over |
| 19561 | 22726 | |
| 19562 | 22727 | =item AUTOLOAD |
| 19563 | 22728 | |
| 19564 | 22729 | =begin original |
| 19565 | 22730 | |
| 19566 | 22731 | This keyword is documented in L<perlsub/"Autoloading">. |
| 19567 | 22732 | |
| 19568 | 22733 | =end original |
| 19569 | 22734 | |
| 19570 | 22735 | このキーワードは L<perlsub/"Autoloading"> で文書化されています。 |
| 19571 | 22736 | |
| 19572 | 22737 | =back |
| 19573 | 22738 | |
| 19574 | 22739 | =head3 perlsyn |
| 19575 | 22740 | |
| 19576 | 22741 | =over |
| 19577 | 22742 | |
| 19578 | 22743 | =item else |
| 19579 | 22744 | |
| 19580 | =item elseif | |
| 19581 | ||
| 19582 | 22745 | =item elsif |
| 19583 | 22746 | |
| 19584 | 22747 | =item for |
| 19585 | 22748 | |
| 19586 | 22749 | =item foreach |
| 19587 | 22750 | |
| 22751 | =item if | |
| 22752 | ||
| 19588 | 22753 | =item unless |
| 19589 | 22754 | |
| 19590 | 22755 | =item until |
| 19591 | 22756 | |
| 19592 | 22757 | =item while |
| 19593 | 22758 | |
| 19594 | 22759 | =begin original |
| 19595 | 22760 | |
| 19596 | 22761 | These flow-control keywords are documented in L<perlsyn/"Compound Statements">. |
| 19597 | 22762 | |
| 19598 | 22763 | =end original |
| 19599 | 22764 | |
| 19600 | 22765 | これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で |
| 19601 | 22766 | 文書化されています。 |
| 19602 | 22767 | |
| 22768 | =item elseif | |
| 22769 | ||
| 22770 | =begin original | |
| 22771 | ||
| 22772 | The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif> | |
| 22773 | or C<else if> either. It does parse C<elseif>, but only to warn you | |
| 22774 | about not using it. | |
| 22775 | ||
| 22776 | =end original | |
| 22777 | ||
| 22778 | "else if" キーワードは Perl では C<elsif> と綴ります。 | |
| 22779 | C<elif> や C<else if> はありません。 | |
| 22780 | C<elseif> はパースされますが、使わないように警告するためだけです。 | |
| 22781 | ||
| 22782 | =begin original | |
| 22783 | ||
| 22784 | See the documentation for flow-control keywords in L<perlsyn/"Compound | |
| 22785 | Statements">. | |
| 22786 | ||
| 22787 | =end original | |
| 22788 | ||
| 22789 | L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を | |
| 22790 | 参照してください。 | |
| 22791 | ||
| 19603 | 22792 | =back |
| 19604 | 22793 | |
| 19605 | 22794 | =over |
| 19606 | 22795 | |
| 19607 | 22796 | =item default |
| 19608 | 22797 | |
| 19609 | 22798 | =item given |
| 19610 | 22799 | |
| 19611 | 22800 | =item when |
| 19612 | 22801 | |
| 19613 | 22802 | =begin original |
| 19614 | 22803 | |
| 19615 | 22804 | These flow-control keywords related to the experimental switch feature are |
| 19616 | documented in L<perlsyn/"Switch Statements"> | |
| 22805 | documented in L<perlsyn/"Switch Statements">. | |
| 19617 | 22806 | |
| 19618 | 22807 | =end original |
| 19619 | 22808 | |
| 19620 | 22809 | これらの実験的な switch 機能に関連するフロー制御キーワードは |
| 19621 | 22810 | L<perlsyn/"Switch Statements"> で文書化されています。 |
| 19622 | 22811 | |
| 19623 | 22812 | =back |
| 19624 | 22813 | |
| 22814 | =over | |
| 22815 | ||
| 22816 | =item try | |
| 22817 | ||
| 22818 | =item catch | |
| 22819 | ||
| 22820 | =item finally | |
| 22821 | ||
| 22822 | =begin original | |
| 22823 | ||
| 22824 | These flow-control keywords related to the experimental C<try> feature are | |
| 22825 | documented in L<perlsyn/"Try Catch Exception Handling">. | |
| 22826 | ||
| 22827 | =end original | |
| 22828 | ||
| 22829 | 実験的な C<try> 機能に関係するこれらのフロー制御キーワードは | |
| 22830 | L<perlsyn/"Try Catch Exception Handling"> に文書化されています。 | |
| 22831 | ||
| 22832 | =back | |
| 22833 | ||
| 22834 | =over | |
| 22835 | ||
| 22836 | =item defer | |
| 22837 | ||
| 22838 | =begin original | |
| 22839 | ||
| 22840 | This flow-control keyword related to the experimental C<defer> feature is | |
| 22841 | documented in L<perlsyn/"defer blocks">. | |
| 22842 | ||
| 22843 | =end original | |
| 22844 | ||
| 22845 | 実験的な C<defer> 機能に関係するこれらのフロー制御キーワードは | |
| 22846 | L<perlsyn/"defer blocks"> に文書化されています。 | |
| 22847 | ||
| 22848 | =back | |
| 22849 | ||
| 22850 | =over | |
| 22851 | ||
| 22852 | =item ADJUST | |
| 22853 | ||
| 22854 | =begin original | |
| 22855 | ||
| 22856 | This class-related phaser block is documented in L<perlclass>. | |
| 22857 | ||
| 22858 | =end original | |
| 22859 | ||
| 22860 | This class-related phaser block is documented in L<perlclass>. | |
| 22861 | (TBT) | |
| 22862 | ||
| 22863 | =back | |
| 22864 | ||
| 22865 | =cut | |
| 22866 | ||
| 19625 | 22867 | =begin meta |
| 19626 | 22868 | |
| 19627 | 22869 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
| 19628 | 22870 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) |
| 19629 | 22871 | Status: in progress |
| 19630 | 22872 | |
| 19631 | 22873 | =end meta |
| 19632 | ||
| 19633 | =cut |