perlfunc >
5.30.0
との差分
perlfunc 5.30.0 と 5.6.1 の差分
| 1 | 1 | |
| 2 | 2 | =encoding euc-jp |
| 3 | 3 | |
| 4 | 4 | =head1 NAME |
| 5 | X<function> | |
| 6 | 5 | |
| 7 | 6 | =begin original |
| 8 | 7 | |
| 9 | 8 | perlfunc - Perl builtin functions |
| 10 | 9 | |
| 11 | 10 | =end original |
| 12 | 11 | |
| 13 | 12 | perlfunc - Perl 組み込み関数 |
| 14 | 13 | |
| 15 | 14 | =head1 DESCRIPTION |
| 16 | 15 | |
| 17 | 16 | =begin original |
| 18 | 17 | |
| 19 | 18 | The functions in this section can serve as terms in an expression. |
| 20 | 19 | They fall into two major categories: list operators and named unary |
| 21 | 20 | operators. These differ in their precedence relationship with a |
| 22 | 21 | following comma. (See the precedence table in L<perlop>.) List |
| 23 | 22 | operators take more than one argument, while unary operators can never |
| 24 | 23 | take more than one argument. Thus, a comma terminates the argument of |
| 25 | 24 | a unary operator, but merely separates the arguments of a list |
| 26 | operator. A unary operator generally provides scalar context to its | |
| 25 | operator. A unary operator generally provides a scalar context to its | |
| 27 | 26 | argument, while a list operator may provide either scalar or list |
| 28 | contexts for its arguments. If it does both, scalar arguments | |
| 27 | contexts for its arguments. If it does both, the scalar arguments will | |
| 29 | ||
| 28 | be first, and the list argument will follow. (Note that there can ever | |
| 30 | be one such list argument. For instance, | |
| 29 | be only one such list argument.) For instance, splice() has three scalar | |
| 31 | ||
| 30 | arguments followed by a list, whereas gethostbyname() has four scalar | |
| 32 | ||
| 31 | arguments. | |
| 33 | four scalar arguments. | |
| 34 | 32 | |
| 35 | 33 | =end original |
| 36 | 34 | |
| 37 | 35 | この節の関数は、式の中で項として使うことができます。 |
| 38 | これらは、大きく | |
| 36 | これらは、大きく 2 つに分けられます: | |
| 39 | 37 | リスト演算子と名前付き単項演算子です。 |
| 40 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 | |
| 38 | これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 | |
| 41 | 39 | (L<perlop> の優先順位の表を参照してください。) |
| 42 | リスト演算子は 2 個以上の引数をとるのに対して、 | |
| 40 | リスト演算子は 2 個以上の引数をとるのに対して、 | |
| 43 | とることはありません。 | |
| 41 | 単項演算子が複数の引数をとることはありません。 | |
| 44 | つまり、コンマは単項演算子の引数の終わりとなりますが、 | |
| 42 | つまり、コンマは単項演算子の引数の終わりとなりますが、 | |
| 45 | 場合には、引数の区切りでしかありません。 | |
| 43 | リスト演算子の場合には、引数の区切りでしかありません。 | |
| 46 | 単項演算子は一般に、 | |
| 44 | 単項演算子は一般に、 | |
| 45 | 引数に対してスカラコンテキストを与えるのに対して、 | |
| 47 | 46 | スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、 |
| 48 | 47 | リストコンテキストを与える場合もあります。 |
| 49 | ||
| 48 | 1 つのリスト演算子が | |
| 50 | いくつか並び、 | |
| 49 | 両方のコンテキストを与える場合には、スカラ引数がいくつか並び、 | |
| 51 | ||
| 50 | 最後にリスト引数が 1 つ続きます。 | |
| 52 | ||
| 51 | (リスト引数は 1 つだけです。) | |
| 53 | ||
| 52 | たとえば、splice() は 3 つのスカラ引数に 1 つのリスト引数が続きます。 | |
| 54 | 一方 | |
| 53 | 一方 gethostbyname() は 4 つのスカラ引数を持ちます。 | |
| 55 | 54 | |
| 56 | 55 | =begin original |
| 57 | 56 | |
| 58 | 57 | In the syntax descriptions that follow, list operators that expect a |
| 59 | list (and provide list context for elements of the list) are shown | |
| 58 | list (and provide list context for the elements of the list) are shown | |
| 60 | 59 | with LIST as an argument. Such a list may consist of any combination |
| 61 | 60 | of scalar arguments or list values; the list values will be included |
| 62 | 61 | in the list as if each individual element were interpolated at that |
| 63 | 62 | point in the list, forming a longer single-dimensional list value. |
| 64 | ||
| 63 | Elements of the LIST should be separated by commas. | |
| 65 | 64 | |
| 66 | 65 | =end original |
| 67 | 66 | |
| 68 | 後に載せる構文記述では、リストをとり | |
| 67 | 後に載せる構文記述では、リストをとり | |
| 69 | ||
| 68 | (そのリストの要素にリストコンテキストを与える) | |
| 69 | リスト演算子は、引数として LIST をとるように書いています。 | |
| 70 | 70 | そのようなリストには、任意のスカラ引数の組み合わせやリスト値を |
| 71 | 含めることができ、リスト値はリストの中に、 | |
| 71 | 含めることができ、リスト値はリストの中に、 | |
| 72 | 埋め込まれます。 | |
| 72 | 個々の要素が展開されたように埋め込まれます。 | |
| 73 | 73 | 1 次元の長いリスト値が形成されることになります。 |
| 74 | LIST の | |
| 74 | LIST の要素は、コンマで区切られている必要があります。 | |
| 75 | 75 | |
| 76 | 76 | =begin original |
| 77 | 77 | |
| 78 | 78 | Any function in the list below may be used either with or without |
| 79 | 79 | parentheses around its arguments. (The syntax descriptions omit the |
| 80 | parentheses.) If you use parentheses, the simple but occasionally | |
| 80 | parentheses.) If you use the parentheses, the simple (but occasionally | |
| 81 | surprising rule is this: It I<looks> like a function, therefore it I<is> a | |
| 81 | surprising) rule is this: It I<looks> like a function, therefore it I<is> a | |
| 82 | 82 | function, and precedence doesn't matter. Otherwise it's a list |
| 83 | operator or unary operator, and precedence does matter. | |
| 83 | operator or unary operator, and precedence does matter. And whitespace | |
| 84 | between the function and left parenthesis doesn't count | |
| 84 | between the function and left parenthesis doesn't count--so you need to | |
| 85 | ||
| 85 | be careful sometimes: | |
| 86 | 86 | |
| 87 | 87 | =end original |
| 88 | 88 | |
| 89 | 以下のリストの関数はすべて、引数の前後の括弧は省略可能と | |
| 89 | 以下のリストの関数はすべて、引数の前後の括弧は省略可能と | |
| 90 | なっています。 | |
| 90 | 91 | (構文記述では省略しています。) |
| 91 | 括弧を使うときには、 | |
| 92 | 括弧を使うときには、 | |
| 92 | 適用できます: | |
| 93 | 単純な (しかし、ときには驚く結果となる) 規則が適用できます: | |
| 93 | 94 | I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。 |
| 94 | そう見えなければ、それはリスト演算子か単項演算子で、優先順位が | |
| 95 | そう見えなければ、それはリスト演算子か単項演算子で、優先順位が | |
| 95 | 関 | |
| 96 | 関係します。 | |
| 96 | ||
| 97 | また、関数と開き括弧の間の空白は関係ありませんので、 | |
| 98 | ときに気を付けなければなりません: | |
| 97 | 99 | |
| 98 | print 1+2+4; | |
| 100 | print 1+2+4; # Prints 7. | |
| 99 | print(1+2) + 4; | |
| 101 | print(1+2) + 4; # Prints 3. | |
| 100 | print (1+2)+4; | |
| 102 | print (1+2)+4; # Also prints 3! | |
| 101 | print +(1+2)+4; | |
| 103 | print +(1+2)+4; # Prints 7. | |
| 102 | print ((1+2)+4); | |
| 104 | print ((1+2)+4); # Prints 7. | |
| 103 | 105 | |
| 104 | 106 | =begin original |
| 105 | 107 | |
| 106 | If you run Perl with the | |
| 108 | If you run Perl with the B<-w> switch it can warn you about this. For | |
| 107 | ||
| 109 | example, the third line above produces: | |
| 108 | 110 | |
| 111 | print (...) interpreted as function at - line 1. | |
| 112 | Useless use of integer addition in void context at - line 1. | |
| 113 | ||
| 109 | 114 | =end original |
| 110 | 115 | |
| 111 | Perl に | |
| 116 | Perl に B<-w> スイッチを付けて実行すれば、こういったものには | |
| 112 | ||
| 117 | 警告を出してくれます。 | |
| 113 | たとえば、上記の | |
| 118 | たとえば、上記の 3 つめは、以下のような警告が出ます: | |
| 114 | 119 | |
| 115 | print (...) interpreted as function at - line 1. | |
| 120 | print (...) interpreted as function at - line 1. | |
| 116 | Useless use of integer addition in void context at - line 1. | |
| 121 | Useless use of integer addition in void context at - line 1. | |
| 117 | 122 | |
| 118 | 123 | =begin original |
| 119 | 124 | |
| 120 | 125 | A few functions take no arguments at all, and therefore work as neither |
| 121 | unary nor list operators. These include such functions as | |
| 126 | unary nor list operators. These include such functions as C<time> | |
| 122 | ||
| 127 | and C<endpwent>. For example, C<time+86_400> always means | |
| 123 | C<time | |
| 128 | C<time() + 86_400>. | |
| 124 | 129 | |
| 125 | 130 | =end original |
| 126 | 131 | |
| 127 | 132 | いくつかの関数は引数を全くとらないので、単項演算子としても |
| 128 | 133 | リスト演算子としても動作しません。 |
| 129 | このような関数としては | |
| 134 | このような関数としては C<time> や C<endpwent> があります。 | |
| 130 | あります。 | |
| 131 | 135 | 例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。 |
| 132 | 136 | |
| 133 | 137 | =begin original |
| 134 | 138 | |
| 135 | 139 | For functions that can be used in either a scalar or list context, |
| 136 | nonabortive failure is generally indicated in scalar context by | |
| 140 | nonabortive failure is generally indicated in a scalar context by | |
| 137 | returning the undefined value, and in list context by returning the | |
| 141 | returning the undefined value, and in a list context by returning the | |
| 138 | ||
| 142 | null list. | |
| 139 | 143 | |
| 140 | 144 | =end original |
| 141 | 145 | |
| 142 | スカラコンテキストでも、リストコンテキストでも使える関数は、 | |
| 146 | スカラコンテキストでも、リストコンテキストでも使える関数は、 | |
| 143 | エラーを示すために、スカラコンテキストでは | |
| 147 | 致命的でないエラーを示すために、スカラコンテキストでは | |
| 144 | リストコンテキストでは空リストを返します。 | |
| 148 | 未定義値を返し、リストコンテキストでは空リストを返します。 | |
| 145 | 149 | |
| 146 | 150 | =begin original |
| 147 | 151 | |
| 148 | 152 | Remember the following important rule: There is B<no rule> that relates |
| 149 | 153 | the behavior of an expression in list context to its behavior in scalar |
| 150 | 154 | context, or vice versa. It might do two totally different things. |
| 151 | Each operator and function decides which sort of value would be most | |
| 155 | Each operator and function decides which sort of value it would be most | |
| 152 | 156 | appropriate to return in scalar context. Some operators return the |
| 153 | 157 | length of the list that would have been returned in list context. Some |
| 154 | 158 | operators return the first value in the list. Some operators return the |
| 155 | 159 | last value in the list. Some operators return a count of successful |
| 156 | 160 | operations. In general, they do what you want, unless you want |
| 157 | 161 | consistency. |
| 158 | X<context> | |
| 159 | 162 | |
| 160 | 163 | =end original |
| 161 | 164 | |
| 162 | 165 | 以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの |
| 163 | 166 | 振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に |
| 164 | 167 | B<ルールはありません>。 |
| 165 | 168 | 2 つの全く異なったことがあります。 |
| 166 | 169 | それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と |
| 167 | 170 | 思われる値を返します。 |
| 168 | 171 | リストコンテキストで返す時のリストの長さを返す演算子もあります。 |
| 169 | 172 | リストの最初の値を返す演算子もあります。 |
| 170 | 173 | リストの最後の値を返す演算子もあります。 |
| 171 | 174 | 成功した操作の数を返す演算子もあります。 |
| 172 | 175 | 一般的には、一貫性を求めない限り、こちらが求めることをします。 |
| 173 | X<context> | |
| 174 | 176 | |
| 175 | 177 | =begin original |
| 176 | 178 | |
| 177 | A named array in scalar context is quite different from what would at | |
| 179 | An named array in scalar context is quite different from what would at | |
| 178 | 180 | first glance appear to be a list in scalar context. You can't get a list |
| 179 | 181 | like C<(1,2,3)> into being in scalar context, because the compiler knows |
| 180 | 182 | the context at compile time. It would generate the scalar comma operator |
| 181 | there, not the list con | |
| 183 | there, not the list construction version of the comma. That means it | |
| 182 | 184 | was never a list to start with. |
| 183 | 185 | |
| 184 | 186 | =end original |
| 185 | 187 | |
| 186 | 188 | スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを |
| 187 | 189 | 一目見たものとは全く違います。 |
| 188 | 190 | コンパイラはコンパイル時にコンテキストを知っているので、 |
| 189 | 191 | C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。 |
| 190 | これはスカラコンマ演算子を生成し、コンマのリスト | |
| 192 | これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。 | |
| 191 | 193 | これは初めからリストであることはないことを意味します。 |
| 192 | 194 | |
| 193 | 195 | =begin original |
| 194 | 196 | |
| 195 | 197 | In general, functions in Perl that serve as wrappers for system calls |
| 196 | ||
| 198 | of the same name (like chown(2), fork(2), closedir(2), etc.) all return | |
| 197 | ||
| 199 | true when they succeed and C<undef> otherwise, as is usually mentioned | |
| 198 | ||
| 200 | in the descriptions below. This is different from the C interfaces, | |
| 199 | ||
| 201 | which return C<-1> on failure. Exceptions to this rule are C<wait>, | |
| 200 | ||
| 202 | C<waitpid>, and C<syscall>. System calls also set the special C<$!> | |
| 201 | ||
| 203 | variable on failure. Other functions do not, except accidentally. | |
| 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. | |
| 205 | 204 | |
| 206 | 205 | =end original |
| 207 | 206 | |
| 208 | 207 | 一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数 |
| 209 | ( | |
| 208 | (chown(2), fork(2), closedir(2) など)は、以下に述べるように、 | |
| 210 | 成功時に真を返し、そうでなければ | |
| 209 | 成功時に真を返し、そうでなければ C<undef> を返します。 | |
| 211 | 210 | これは失敗時に C<-1> を返す C のインターフェースとは違います。 |
| 212 | このルールの例外は | |
| 211 | このルールの例外は C<wait>, C<waitpid>, C<syscall> です。 | |
| 213 | ||
| 212 | システムコールは失敗時に特殊変数 C<$!> をセットします。 | |
| 214 | システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。 | |
| 215 | 213 | その他の関数は、事故を除いて、セットしません。 |
| 216 | 214 | |
| 217 | =begin original | |
| 218 | ||
| 219 | Extension modules can also hook into the Perl parser to define new | |
| 220 | kinds of keyword-headed expression. These may look like functions, but | |
| 221 | may also look completely different. The syntax following the keyword | |
| 222 | is defined entirely by the extension. If you are an implementor, see | |
| 223 | L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such | |
| 224 | a module, see the module's documentation for details of the syntax that | |
| 225 | it defines. | |
| 226 | ||
| 227 | =end original | |
| 228 | ||
| 229 | エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を | |
| 230 | 定義するために Perl パーサをフックできます。 | |
| 231 | これらは関数のように見えるかもしれませんが、全く別物かもしれません。 | |
| 232 | キーワード以降の文法は完全にエクステンションによって定義されます。 | |
| 233 | もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を | |
| 234 | 参照してください。 | |
| 235 | もしあなたがそのようなモジュールを使っているなら、 | |
| 236 | 定義されている文法の詳細についてはモジュールの文書を参照してください。 | |
| 237 | ||
| 238 | 215 | =head2 Perl Functions by Category |
| 239 | X<function> | |
| 240 | 216 | |
| 241 | 217 | (カテゴリ別の Perl 関数) |
| 242 | 218 | |
| 243 | 219 | =begin original |
| 244 | 220 | |
| 245 | 221 | Here are Perl's functions (including things that look like |
| 246 | 222 | functions, like some keywords and named operators) |
| 247 | 223 | arranged by category. Some functions appear in more |
| 248 | than one place. | |
| 224 | than one place. | |
| 249 | keywords, are described in L<perldiag> and L<warnings>. | |
| 250 | 225 | |
| 251 | 226 | =end original |
| 252 | 227 | |
| 253 | 228 | 以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、 |
| 254 | 229 | 関数のように見えるものも含みます)を示します。 |
| 255 | 230 | 複数の場所に現れる関数もあります。 |
| 256 | キーワードによって生成されるものを含む全ての警告は | |
| 257 | L<perldiag> と L<warnings> に記述されています。 | |
| 258 | 231 | |
| 259 | 232 | =over 4 |
| 260 | 233 | |
| 261 | 234 | =item Functions for SCALARs or strings |
| 262 | X<scalar> X<string> X<character> | |
| 263 | 235 | |
| 264 | 236 | (スカラや文字列のための関数) |
| 265 | 237 | |
| 266 | ||
| 238 | C<chomp>, C<chop>, C<chr>, C<crypt>, C<hex>, C<index>, C<lc>, C<lcfirst>, | |
| 239 | C<length>, C<oct>, C<ord>, C<pack>, C<q/STRING/>, C<qq/STRING/>, C<reverse>, | |
| 240 | C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///> | |
| 267 | 241 | |
| 268 | L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>, | |
| 269 | L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>, | |
| 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>> | |
| 283 | ||
| 284 | =begin original | |
| 285 | ||
| 286 | L<C<fc>|/fc EXPR> is available only if the | |
| 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 | |
| 290 | with a C<use v5.16> (or higher) declaration in the current scope. | |
| 291 | ||
| 292 | =end original | |
| 293 | ||
| 294 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か | |
| 295 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 296 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
| 297 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 298 | ||
| 299 | 242 | =item Regular expressions and pattern matching |
| 300 | X<regular expression> X<regex> X<regexp> | |
| 301 | 243 | |
| 302 | 244 | (正規表現とパターンマッチング) |
| 303 | 245 | |
| 304 | ||
| 246 | C<m//>, C<pos>, C<quotemeta>, C<s///>, C<split>, C<study>, C<qr//> | |
| 305 | 247 | |
| 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> | |
| 312 | ||
| 313 | 248 | =item Numeric functions |
| 314 | X<numeric> X<number> X<trigonometric> X<trigonometry> | |
| 315 | 249 | |
| 316 | 250 | (数値関数) |
| 317 | 251 | |
| 318 | ||
| 252 | C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>, | |
| 253 | C<sin>, C<sqrt>, C<srand> | |
| 319 | 254 | |
| 320 | L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>, | |
| 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> | |
| 324 | ||
| 325 | 255 | =item Functions for real @ARRAYs |
| 326 | X<array> | |
| 327 | 256 | |
| 328 | 257 | (実配列のための関数) |
| 329 | 258 | |
| 330 | ||
| 259 | C<pop>, C<push>, C<shift>, C<splice>, C<unshift> | |
| 331 | 260 | |
| 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> | |
| 336 | ||
| 337 | 261 | =item Functions for list data |
| 338 | X<list> | |
| 339 | 262 | |
| 340 | 263 | (リストデータのための関数) |
| 341 | 264 | |
| 342 | ||
| 265 | C<grep>, C<join>, C<map>, C<qw/STRING/>, C<reverse>, C<sort>, C<unpack> | |
| 343 | 266 | |
| 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> | |
| 348 | ||
| 349 | 267 | =item Functions for real %HASHes |
| 350 | X<hash> | |
| 351 | 268 | |
| 352 | 269 | (実ハッシュのための関数) |
| 353 | 270 | |
| 354 | ||
| 271 | C<delete>, C<each>, C<exists>, C<keys>, C<values> | |
| 355 | 272 | |
| 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> | |
| 359 | ||
| 360 | 273 | =item Input and output functions |
| 361 | X<I/O> X<input> X<output> X<dbm> | |
| 362 | 274 | |
| 363 | 275 | (入出力関数) |
| 364 | 276 | |
| 365 | ||
| 277 | C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>, | |
| 278 | C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>, | |
| 279 | C<readdir>, C<rewinddir>, C<seek>, C<seekdir>, C<select>, C<syscall>, | |
| 280 | C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>, | |
| 281 | C<warn>, C<write> | |
| 366 | 282 | |
| 367 | ||
| 283 | =item Functions for fixed length data or records | |
| 368 | L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>, | |
| 369 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>, | |
| 370 | L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>, | |
| 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> | |
| 387 | 284 | |
| 388 | =begin original | |
| 389 | ||
| 390 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
| 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 | |
| 394 | with a C<use v5.10> (or higher) declaration in the current scope. | |
| 395 | ||
| 396 | =end original | |
| 397 | ||
| 398 | L<C<say>|/say FILEHANDLE LIST> は | |
| 399 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
| 400 | 前置されたときにのみ利用可能です。 | |
| 401 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
| 402 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 403 | ||
| 404 | =item Functions for fixed-length data or records | |
| 405 | ||
| 406 | 285 | (固定長データやレコードのための関数) |
| 407 | 286 | |
| 408 | ||
| 287 | C<pack>, C<read>, C<syscall>, C<sysread>, C<syswrite>, C<unpack>, C<vec> | |
| 409 | 288 | |
| 410 | L<C<pack>|/pack TEMPLATE,LIST>, | |
| 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> | |
| 417 | ||
| 418 | 289 | =item Functions for filehandles, files, or directories |
| 419 | X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink> | |
| 420 | 290 | |
| 421 | 291 | (ファイルハンドル、ファイル、ディレクトリのための関数) |
| 422 | 292 | |
| 423 | ||
| 293 | C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>, | |
| 294 | C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>, | |
| 295 | C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<umask>, | |
| 296 | C<unlink>, C<utime> | |
| 424 | 297 | |
| 425 | ||
| 298 | =item Keywords related to the control flow of your perl program | |
| 426 | L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>, | |
| 427 | L<C<chroot>|/chroot FILENAME>, | |
| 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,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> | |
| 439 | 299 | |
| 440 | =item Keywords related to the control flow of your Perl program | |
| 441 | X<control flow> | |
| 442 | ||
| 443 | 300 | (プログラムの流れを制御することに関連するキーワード) |
| 444 | 301 | |
| 445 | ||
| 302 | C<caller>, C<continue>, C<die>, C<do>, C<dump>, C<eval>, C<exit>, | |
| 303 | C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray> | |
| 446 | 304 | |
| 447 | L<C<break>|/break>, L<C<caller>|/caller EXPR>, | |
| 448 | L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>, | |
| 449 | L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>, | |
| 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<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>, | |
| 454 | L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>, | |
| 455 | L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>, | |
| 456 | L<C<wantarray>|/wantarray> | |
| 457 | ||
| 458 | =begin original | |
| 459 | ||
| 460 | L<C<break>|/break> is available only if you enable the experimental | |
| 461 | L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::> | |
| 462 | prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also | |
| 463 | enables the C<default>, C<given> and C<when> statements, which are | |
| 464 | documented in L<perlsyn/"Switch Statements">. | |
| 465 | The L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
| 466 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 467 | scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK> | |
| 468 | required the L<C<"switch"> feature|feature/The 'switch' feature>, like | |
| 469 | the other keywords. | |
| 470 | ||
| 471 | =end original | |
| 472 | ||
| 473 | L<C<break>|/break> は、実験的な | |
| 474 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を | |
| 475 | 使ったときにのみ利用可能です。 | |
| 476 | L<C<"switch"> 機能|feature/The 'switch' feature> は、 | |
| 477 | L<perlsyn/"Switch Statements"> で文書化されている | |
| 478 | C<default>, C<given>, C<when> 文も有効にします。 | |
| 479 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
| 480 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
| 481 | Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に | |
| 482 | L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。 | |
| 483 | ||
| 484 | =begin original | |
| 485 | ||
| 486 | L<C<evalbytes>|/evalbytes EXPR> is only available with the | |
| 487 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 488 | (see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__> | |
| 489 | is only available with the | |
| 490 | L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if | |
| 491 | prefixed with C<CORE::>. Both the | |
| 492 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 493 | and L<C<"current_sub">|feature/The 'current_sub' feature> features are | |
| 494 | enabled automatically with a C<use v5.16> (or higher) declaration in the | |
| 495 | current scope. | |
| 496 | ||
| 497 | =end original | |
| 498 | ||
| 499 | L<C<evalbytes>|/evalbytes EXPR> は | |
| 500 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 501 | (L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。 | |
| 502 | L<C<__SUB__>|/__SUB__> は | |
| 503 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か | |
| 504 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 505 | L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と | |
| 506 | L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は | |
| 507 | 現在のスコープで | |
| 508 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 509 | ||
| 510 | 305 | =item Keywords related to scoping |
| 511 | 306 | |
| 512 | 307 | (スコープに関するキーワード) |
| 513 | 308 | |
| 514 | ||
| 309 | C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<use> | |
| 515 | 310 | |
| 516 | L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>, | |
| 517 | L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>, | |
| 518 | L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>, | |
| 519 | L<C<use>|/use Module VERSION LIST> | |
| 520 | ||
| 521 | =begin original | |
| 522 | ||
| 523 | L<C<state>|/state VARLIST> is available only if the | |
| 524 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
| 525 | prefixed with C<CORE::>. The | |
| 526 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
| 527 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 528 | scope. | |
| 529 | ||
| 530 | =end original | |
| 531 | ||
| 532 | L<C<state>|/state VARLIST> は | |
| 533 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
| 534 | 前置した場合にのみ利用可能です。 | |
| 535 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
| 536 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
| 537 | ||
| 538 | 311 | =item Miscellaneous functions |
| 539 | 312 | |
| 540 | 313 | (さまざまな関数) |
| 541 | 314 | |
| 542 | ||
| 315 | C<defined>, C<dump>, C<eval>, C<formline>, C<local>, C<my>, C<our>, C<reset>, | |
| 316 | C<scalar>, C<undef>, C<wantarray> | |
| 543 | 317 | |
| 544 | L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>, | |
| 545 | L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>, | |
| 546 | L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>, | |
| 547 | L<C<undef>|/undef EXPR> | |
| 548 | ||
| 549 | 318 | =item Functions for processes and process groups |
| 550 | X<process> X<pid> X<process id> | |
| 551 | 319 | |
| 552 | 320 | (プロセスとプロセスグループのための関数) |
| 553 | 321 | |
| 554 | ||
| 322 | C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>, | |
| 323 | C<pipe>, C<qx/STRING/>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>, | |
| 324 | C<times>, C<wait>, C<waitpid> | |
| 555 | 325 | |
| 556 | ||
| 326 | =item Keywords related to perl modules | |
| 557 | L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>, | |
| 558 | L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>, | |
| 559 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, | |
| 560 | L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, | |
| 561 | L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
| 562 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
| 563 | L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>, | |
| 564 | L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS> | |
| 565 | 327 | |
| 566 | ||
| 328 | (perl モジュールに関するキーワード) | |
| 567 | X<module> | |
| 568 | 329 | |
| 569 | ||
| 330 | C<do>, C<import>, C<no>, C<package>, C<require>, C<use> | |
| 570 | 331 | |
| 571 | = | |
| 332 | =item Keywords related to classes and object-orientedness | |
| 572 | 333 | |
| 573 | L<C<do>|/do EXPR>, L<C<import>|/import LIST>, | |
| 574 | L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>, | |
| 575 | L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST> | |
| 576 | ||
| 577 | =item Keywords related to classes and object-orientation | |
| 578 | X<object> X<class> X<package> | |
| 579 | ||
| 580 | 334 | (クラスとオブジェクト指向に関するキーワード) |
| 581 | 335 | |
| 582 | ||
| 336 | C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>, | |
| 337 | C<untie>, C<use> | |
| 583 | 338 | |
| 584 | L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>, | |
| 585 | L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, | |
| 586 | L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>, | |
| 587 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>, | |
| 588 | L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST> | |
| 589 | ||
| 590 | 339 | =item Low-level socket functions |
| 591 | X<socket> X<sock> | |
| 592 | 340 | |
| 593 | 341 | (低レベルソケット関数) |
| 594 | 342 | |
| 595 | ||
| 343 | C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>, | |
| 344 | C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>, | |
| 345 | C<socket>, C<socketpair> | |
| 596 | 346 | |
| 597 | L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>, | |
| 598 | L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>, | |
| 599 | L<C<getpeername>|/getpeername SOCKET>, | |
| 600 | L<C<getsockname>|/getsockname SOCKET>, | |
| 601 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
| 602 | L<C<listen>|/listen SOCKET,QUEUESIZE>, | |
| 603 | L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>, | |
| 604 | L<C<send>|/send SOCKET,MSG,FLAGS,TO>, | |
| 605 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
| 606 | L<C<shutdown>|/shutdown SOCKET,HOW>, | |
| 607 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
| 608 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> | |
| 609 | ||
| 610 | 347 | =item System V interprocess communication functions |
| 611 | X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message> | |
| 612 | 348 | |
| 613 | 349 | (System V プロセス間通信関数) |
| 614 | 350 | |
| 615 | ||
| 351 | C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>, | |
| 352 | C<shmctl>, C<shmget>, C<shmread>, C<shmwrite> | |
| 616 | 353 | |
| 617 | L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>, | |
| 618 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
| 619 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, | |
| 620 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
| 621 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
| 622 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
| 623 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
| 624 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE> | |
| 625 | ||
| 626 | 354 | =item Fetching user and group info |
| 627 | X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd> | |
| 628 | 355 | |
| 629 | 356 | (ユーザーとグループの情報取得) |
| 630 | 357 | |
| 631 | ||
| 358 | C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>, | |
| 359 | C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>, | |
| 360 | C<getpwuid>, C<setgrent>, C<setpwent> | |
| 632 | 361 | |
| 633 | L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>, | |
| 634 | L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>, | |
| 635 | L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>, | |
| 636 | L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>, | |
| 637 | L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>, | |
| 638 | L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>, | |
| 639 | L<C<setpwent>|/setpwent> | |
| 640 | ||
| 641 | 362 | =item Fetching network info |
| 642 | X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service> | |
| 643 | 363 | |
| 644 | 364 | (ネットワーク情報取得) |
| 645 | 365 | |
| 646 | ||
| 366 | C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>, | |
| 367 | C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>, | |
| 368 | C<getprotobyname>, C<getprotobynumber>, C<getprotoent>, | |
| 369 | C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>, | |
| 370 | C<setnetent>, C<setprotoent>, C<setservent> | |
| 647 | 371 | |
| 648 | L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>, | |
| 649 | L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>, | |
| 650 | L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>, | |
| 651 | L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>, | |
| 652 | L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>, | |
| 653 | L<C<getprotobyname>|/getprotobyname NAME>, | |
| 654 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
| 655 | L<C<getprotoent>|/getprotoent>, | |
| 656 | L<C<getservbyname>|/getservbyname NAME,PROTO>, | |
| 657 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
| 658 | L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
| 659 | L<C<setnetent>|/setnetent STAYOPEN>, | |
| 660 | L<C<setprotoent>|/setprotoent STAYOPEN>, | |
| 661 | L<C<setservent>|/setservent STAYOPEN> | |
| 662 | ||
| 663 | 372 | =item Time-related functions |
| 664 | X<time> X<date> | |
| 665 | 373 | |
| 666 | 374 | (時刻に関する関数) |
| 667 | 375 | |
| 668 | ||
| 376 | C<gmtime>, C<localtime>, C<time>, C<times> | |
| 669 | 377 | |
| 670 | ||
| 378 | =item Functions new in perl5 | |
| 671 | L<C<time>|/time>, L<C<times>|/times> | |
| 672 | 379 | |
| 673 | ||
| 380 | (perl5 で新設された関数) | |
| 674 | 381 | |
| 675 | ||
| 382 | C<abs>, C<bless>, C<chomp>, C<chr>, C<exists>, C<formline>, C<glob>, | |
| 383 | C<import>, C<lc>, C<lcfirst>, C<map>, C<my>, C<no>, C<our>, C<prototype>, | |
| 384 | C<qx>, C<qw>, C<readline>, C<readpipe>, C<ref>, C<sub*>, C<sysopen>, C<tie>, | |
| 385 | C<tied>, C<uc>, C<ucfirst>, C<untie>, C<use> | |
| 676 | 386 | |
| 677 | ||
| 387 | =begin original | |
| 678 | C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>, | |
| 679 | C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>, | |
| 680 | C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>, | |
| 681 | C<while>, C<x>, C<xor> | |
| 682 | 388 | |
| 389 | * - C<sub> was a keyword in perl4, but in perl5 it is an | |
| 390 | operator, which can be used in expressions. | |
| 391 | ||
| 392 | =end original | |
| 393 | ||
| 394 | * - C<sub> は perl4 ではキーワードですが、perl5 では演算子なので、 | |
| 395 | 式で使えます。 | |
| 396 | ||
| 397 | =item Functions obsoleted in perl5 | |
| 398 | ||
| 399 | (perl5 では古いものとなった関数) | |
| 400 | ||
| 401 | C<dbmclose>, C<dbmopen> | |
| 402 | ||
| 683 | 403 | =back |
| 684 | 404 | |
| 685 | 405 | =head2 Portability |
| 686 | X<portability> X<Unix> X<portable> | |
| 687 | 406 | |
| 688 | (移植性) | |
| 689 | ||
| 690 | 407 | =begin original |
| 691 | 408 | |
| 692 | 409 | Perl was born in Unix and can therefore access all common Unix |
| 693 | 410 | system calls. In non-Unix environments, the functionality of some |
| 694 | Unix system calls may not be available or details of the available | |
| 411 | Unix system calls may not be available, or details of the available | |
| 695 | 412 | functionality may differ slightly. The Perl functions affected |
| 696 | 413 | by this are: |
| 697 | 414 | |
| 698 | 415 | =end original |
| 699 | 416 | |
| 700 | 417 | Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに |
| 701 | アクセスします。 | |
| 418 | アクセスします。非 Unix 環境では、いくつかの Unix システムコールの | |
| 702 | ||
| 419 | 機能が使えなかったり、使える機能の詳細が多少異なったりします。 | |
| 703 | 使える機能の詳細が多少異なったりします。 | |
| 704 | 420 | これによる影響を受ける Perl 関数は以下のものです: |
| 705 | 421 | |
| 706 | ||
| 422 | C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>, | |
| 707 | ||
| 423 | C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>, | |
| 708 | ||
| 424 | C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>, | |
| 709 | ||
| 425 | C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostent>, | |
| 710 | ||
| 426 | C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>, | |
| 711 | ||
| 427 | C<getppid>, C<getprgp>, C<getpriority>, C<getprotobynumber>, | |
| 712 | ||
| 428 | C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>, | |
| 713 | ||
| 429 | C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>, | |
| 714 | ||
| 430 | C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>, | |
| 715 | ||
| 431 | C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>, | |
| 716 | ||
| 432 | C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>, | |
| 717 | ||
| 433 | C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>, | |
| 718 | ||
| 434 | C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>, | |
| 719 | ||
| 435 | C<shmwrite>, C<socket>, C<socketpair>, C<stat>, C<symlink>, C<syscall>, | |
| 720 | ||
| 436 | C<sysopen>, C<system>, C<times>, C<truncate>, C<umask>, C<unlink>, | |
| 721 | ||
| 437 | C<utime>, C<wait>, C<waitpid> | |
| 722 | L<C<getpriority>|/getpriority WHICH,WHO>, | |
| 723 | L<C<getprotobynumber>|/getprotobynumber NUMBER>, | |
| 724 | L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>, | |
| 725 | L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>, | |
| 726 | L<C<getservbyport>|/getservbyport PORT,PROTO>, | |
| 727 | L<C<getservent>|/getservent>, | |
| 728 | L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>, | |
| 729 | L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, | |
| 730 | L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>, | |
| 731 | L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>, | |
| 732 | L<C<msgget>|/msgget KEY,FLAGS>, | |
| 733 | L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>, | |
| 734 | L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>, | |
| 735 | L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>, | |
| 736 | L<C<rename>|/rename OLDNAME,NEWNAME>, | |
| 737 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, | |
| 738 | L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>, | |
| 739 | L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>, | |
| 740 | L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>, | |
| 741 | L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>, | |
| 742 | L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>, | |
| 743 | L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>, | |
| 744 | L<C<setservent>|/setservent STAYOPEN>, | |
| 745 | L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>, | |
| 746 | L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>, | |
| 747 | L<C<shmread>|/shmread ID,VAR,POS,SIZE>, | |
| 748 | L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>, | |
| 749 | L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>, | |
| 750 | L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, | |
| 751 | L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>, | |
| 752 | L<C<syscall>|/syscall NUMBER, LIST>, | |
| 753 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, | |
| 754 | L<C<system>|/system LIST>, L<C<times>|/times>, | |
| 755 | L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>, | |
| 756 | L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>, | |
| 757 | L<C<waitpid>|/waitpid PID,FLAGS> | |
| 758 | 438 | |
| 759 | 439 | =begin original |
| 760 | 440 | |
| 761 | 441 | For more information about the portability of these functions, see |
| 762 | 442 | L<perlport> and other available platform-specific documentation. |
| 763 | 443 | |
| 764 | 444 | =end original |
| 765 | 445 | |
| 766 | 446 | これらの関数の移植性に関するさらなる情報については、 |
| 767 | L<perlport> とその他のプラットホーム固有のドキュメントを参照して | |
| 447 | L<perlport> とその他のプラットホーム固有のドキュメントを参照して下さい。 | |
| 768 | 448 | |
| 769 | 449 | =head2 Alphabetical Listing of Perl Functions |
| 770 | 450 | |
| 771 | =over | |
| 451 | =over 8 | |
| 772 | 452 | |
| 773 | =item -X FILEHANDLE | |
| 453 | =item I<-X> FILEHANDLE | |
| 774 | X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p> | |
| 775 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> | |
| 776 | 454 | |
| 777 | =item -X EXPR | |
| 455 | =item I<-X> EXPR | |
| 778 | 456 | |
| 779 | =item -X | |
| 457 | =item I<-X> | |
| 780 | 458 | |
| 781 | =item -X | |
| 782 | ||
| 783 | =for Pod::Functions a file test (-r, -x, etc) | |
| 784 | ||
| 785 | 459 | =begin original |
| 786 | 460 | |
| 787 | 461 | A file test, where X is one of the letters listed below. This unary |
| 788 | operator takes one argument, either a filename | |
| 462 | operator takes one argument, either a filename or a filehandle, and | |
| 789 | ||
| 463 | tests the associated file to see if something is true about it. If the | |
| 790 | argument is omitted, tests | |
| 464 | argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN. | |
| 791 | ||
| 465 | Unless otherwise documented, it returns C<1> for true and C<''> for false, or | |
| 792 | ||
| 466 | the undefined value if the file doesn't exist. Despite the funny | |
| 793 | ||
| 467 | names, precedence is the same as any other named unary operator, and | |
| 794 | ||
| 468 | the argument may be parenthesized like any other unary operator. The | |
| 795 | ||
| 469 | operator may be any of: | |
| 796 | be examined and will therefore report failure). | |
| 797 | 470 | |
| 798 | 471 | =end original |
| 799 | 472 | |
| 800 | 473 | X は以下にあげる文字で、ファイルテストを行ないます。 |
| 801 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
| 474 | この単項演算子は、ファイル名かファイルハンドルを唯一の | |
| 802 | 「あること」について真であるか否かを | |
| 475 | 引数として動作し、「あること」について真であるか否かを | |
| 803 | ||
| 476 | 判定した結果を返します。 | |
| 804 | ||
| 477 | 引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。 | |
| 805 | 特に記述されていなければ、真として C<1> を返し、偽として | |
| 478 | 特に記述されていなければ、真として C<1> を返し、偽として | |
| 806 | ファイルが存在しな | |
| 479 | C<''> を返し、ファイルが存在しなければ、未定義値を返します。 | |
| 807 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 808 | C<-l> テストを例外として、これら全てはシンボリックリンクに従います; | |
| 809 | C<lstat()> ではなく C<stat()> を使っているからです | |
| 810 | (従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。 | |
| 811 | ||
| 812 | =begin original | |
| 813 | ||
| 814 | Despite the funny names, precedence is the same as any other named unary | |
| 815 | operator. The operator may be any of: | |
| 816 | ||
| 817 | =end original | |
| 818 | ||
| 819 | 480 | みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、 |
| 820 | 481 | 他の単項演算子と同じく、引数を括弧で括ることもできます。 |
| 821 | 482 | 演算子には以下のものがあります: |
| 822 | 483 | |
| 484 | 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> | |
| 485 | X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> | |
| 486 | ||
| 823 | 487 | =begin original |
| 824 | 488 | |
| 825 | -r | |
| 489 | -r File is readable by effective uid/gid. | |
| 826 | -w | |
| 490 | -w File is writable by effective uid/gid. | |
| 827 | -x | |
| 491 | -x File is executable by effective uid/gid. | |
| 828 | -o | |
| 492 | -o File is owned by effective uid. | |
| 829 | 493 | |
| 830 | 494 | =end original |
| 831 | 495 | |
| 832 | -r ファイルが実効 uid/gid で読み出し可 | |
| 496 | -r ファイルが実効 uid/gid で読み出し可 | |
| 833 | -w ファイルが実効 uid/gid で書き込み可 | |
| 497 | -w ファイルが実効 uid/gid で書き込み可 | |
| 834 | -x ファイルが実効 uid/gid で実行可 | |
| 498 | -x ファイルが実効 uid/gid で実行可 | |
| 835 | -o ファイルが実効 uid の所有物 | |
| 499 | -o ファイルが実効 uid の所有物 | |
| 836 | 500 | |
| 837 | 501 | =begin original |
| 838 | 502 | |
| 839 | -R | |
| 503 | -R File is readable by real uid/gid. | |
| 840 | -W | |
| 504 | -W File is writable by real uid/gid. | |
| 841 | -X | |
| 505 | -X File is executable by real uid/gid. | |
| 842 | -O | |
| 506 | -O File is owned by real uid. | |
| 843 | 507 | |
| 844 | 508 | =end original |
| 845 | 509 | |
| 846 | -R ファイルが実 uid/gid で読み出し可 | |
| 510 | -R ファイルが実 uid/gid で読み出し可 | |
| 847 | -W ファイルが実 uid/gid で書き込み可 | |
| 511 | -W ファイルが実 uid/gid で書き込み可 | |
| 848 | -X ファイルが実 uid/gid で実行可 | |
| 512 | -X ファイルが実 uid/gid で実行可 | |
| 849 | -O ファイルが実 uid の所有物 | |
| 513 | -O ファイルが実 uid の所有物 | |
| 850 | 514 | |
| 851 | 515 | =begin original |
| 852 | 516 | |
| 853 | -e | |
| 517 | -e File exists. | |
| 854 | -z | |
| 518 | -z File has zero size (is empty). | |
| 855 | -s | |
| 519 | -s File has nonzero size (returns size in bytes). | |
| 856 | 520 | |
| 857 | 521 | =end original |
| 858 | 522 | |
| 859 | -e ファイルが存在する | |
| 523 | -e ファイルが存在する | |
| 860 | -z ファイルの大きさがゼロ(空) | |
| 524 | -z ファイルの大きさがゼロ(空) | |
| 861 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す) | |
| 525 | -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す) | |
| 862 | 526 | |
| 863 | 527 | =begin original |
| 864 | 528 | |
| 865 | -f | |
| 529 | -f File is a plain file. | |
| 866 | -d | |
| 530 | -d File is a directory. | |
| 867 | -l | |
| 531 | -l File is a symbolic link. | |
| 868 | | |
| 532 | -p File is a named pipe (FIFO), or Filehandle is a pipe. | |
| 869 | - | |
| 533 | -S File is a socket. | |
| 870 | - | |
| 534 | -b File is a block special file. | |
| 871 | - | |
| 535 | -c File is a character special file. | |
| 872 | - | |
| 536 | -t Filehandle is opened to a tty. | |
| 873 | -t Filehandle is opened to a tty. | |
| 874 | 537 | |
| 875 | 538 | =end original |
| 876 | 539 | |
| 877 | -f ファイルは通常ファイル | |
| 540 | -f ファイルは通常ファイル | |
| 878 | -d ファイルはディレクトリ | |
| 541 | -d ファイルはディレクトリ | |
| 879 | -l ファイルはシンボリックリンク | |
| 542 | -l ファイルはシンボリックリンク | |
| 880 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ | |
| 543 | -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ | |
| 881 | -S ファイルはソケット | |
| 544 | -S ファイルはソケット | |
| 882 | -b ファイルはブロック特殊ファイル | |
| 545 | -b ファイルはブロック特殊ファイル | |
| 883 | -c ファイルはキャラクタ特殊ファイル | |
| 546 | -c ファイルはキャラクタ特殊ファイル | |
| 884 | -t ファイルハンドルは tty にオープンされている | |
| 547 | -t ファイルハンドルは tty にオープンされている | |
| 885 | 548 | |
| 886 | 549 | =begin original |
| 887 | 550 | |
| 888 | -u | |
| 551 | -u File has setuid bit set. | |
| 889 | -g | |
| 552 | -g File has setgid bit set. | |
| 890 | -k | |
| 553 | -k File has sticky bit set. | |
| 891 | 554 | |
| 892 | 555 | =end original |
| 893 | 556 | |
| 894 | -u ファイルの setuid ビットがセットされている | |
| 557 | -u ファイルの setuid ビットがセットされている | |
| 895 | -g ファイルの setgid ビットがセットされている | |
| 558 | -g ファイルの setgid ビットがセットされている | |
| 896 | -k ファイルの sticky ビットがセットされている | |
| 559 | -k ファイルの sticky ビットがセットされている | |
| 897 | 560 | |
| 898 | 561 | =begin original |
| 562 | -T File is an ASCII text file. | |
| 563 | -B File is a "binary" file (opposite of -T). | |
| 899 | 564 | |
| 900 | -T File is an ASCII or UTF-8 text file (heuristic guess). | |
| 901 | -B File is a "binary" file (opposite of -T). | |
| 902 | ||
| 903 | 565 | =end original |
| 904 | 566 | |
| 905 | -T ファイルは ASCII | |
| 567 | -T ファイルは ASCII テキストファイル | |
| 906 | -B ファイルは「バイナリ」ファイル (-T の反対) | |
| 568 | -B ファイルは「バイナリ」ファイル (-T の反対) | |
| 907 | 569 | |
| 908 | 570 | =begin original |
| 909 | 571 | |
| 910 | -M | |
| 572 | -M Age of file in days when script started. | |
| 911 | -A | |
| 573 | -A Same for access time. | |
| 912 | -C | |
| 574 | -C Same for inode change time. | |
| 913 | platforms) | |
| 914 | 575 | |
| 915 | 576 | =end original |
| 916 | 577 | |
| 917 | -M スクリプト実行開始時 | |
| 578 | -M スクリプト実行開始時のファイル修正からの日数 | |
| 918 | -A 同様にアクセスがあってからの日数 | |
| 579 | -A 同様にアクセスがあってからの日数 | |
| 919 | -C 同様に | |
| 580 | -C 同様に inode が変更されてからの日数 | |
| 920 | プラットフォームでは違うかもしれません)。 | |
| 921 | 581 | |
| 922 | 582 | =begin original |
| 923 | 583 | |
| 924 | 584 | Example: |
| 925 | 585 | |
| 926 | 586 | =end original |
| 927 | 587 | |
| 928 | 588 | 例: |
| 929 | 589 | |
| 930 | 590 | while (<>) { |
| 931 | ||
| 591 | chomp; | |
| 932 | ||
| 592 | next unless -f $_; # ignore specials | |
| 933 | ||
| 593 | #... | |
| 934 | 594 | } |
| 935 | 595 | |
| 936 | 596 | =begin original |
| 937 | 597 | |
| 938 | Note that C<-s/a/b/> does not do a negated substitution. Saying | |
| 939 | C<-exp($foo)> still works as expected, however: only single letters | |
| 940 | following a minus are interpreted as file tests. | |
| 941 | ||
| 942 | =end original | |
| 943 | ||
| 944 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 | |
| 945 | しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に | |
| 946 | 英字が 1 字続くときにのみ、ファイルテストと解釈されます。 | |
| 947 | ||
| 948 | =begin original | |
| 949 | ||
| 950 | These operators are exempt from the "looks like a function rule" described | |
| 951 | above. That is, an opening parenthesis after the operator does not affect | |
| 952 | how much of the following code constitutes the argument. Put the opening | |
| 953 | parentheses before the operator to separate it from code that follows (this | |
| 954 | applies only to operators with higher precedence than unary operators, of | |
| 955 | course): | |
| 956 | ||
| 957 | =end original | |
| 958 | ||
| 959 | これらの演算子は上述の「関数のように見えるルール」から免除されます。 | |
| 960 | つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を | |
| 961 | 構成するかに影響を与えません。 | |
| 962 | 演算子を引き続くコードから分離するには、演算子の前に開きかっこを | |
| 963 | 置いてください (これはもちろん、単項演算子より高い優先順位を持つ | |
| 964 | 演算子にのみ適用されます): | |
| 965 | ||
| 966 | -s($file) + 1024 # probably wrong; same as -s($file + 1024) | |
| 967 | (-s $file) + 1024 # correct | |
| 968 | ||
| 969 | =begin original | |
| 970 | ||
| 971 | 598 | The interpretation of the file permission operators C<-r>, C<-R>, |
| 972 | 599 | C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode |
| 973 | 600 | of the file and the uids and gids of the user. There may be other |
| 974 | reasons you can't actually read, write, or execute the file | |
| 601 | reasons you can't actually read, write, or execute the file. Such | |
| 975 | example network filesystem access controls, ACLs | |
| 602 | reasons may be for example network filesystem access controls, ACLs | |
| 976 | read-only filesystems, and unrecognized | |
| 603 | (access control lists), read-only filesystems, and unrecognized | |
| 977 | ||
| 604 | executable formats. | |
| 978 | is possible is usually a mistake, because it may be open to race | |
| 979 | conditions. | |
| 980 | 605 | |
| 981 | 606 | =end original |
| 982 | 607 | |
| 983 | 608 | ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>, |
| 984 | 609 | C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と |
| 985 | 610 | 実効/実 gid のみから判断されます。 |
| 986 | 611 | 実際にファイルが読めたり、書けたり、実行できたりするためには、 |
| 987 | 別の条件が必要かもしれません | |
| 612 | 別の条件が必要かもしれません。 | |
| 988 | ||
| 613 | 条件としてはネットワークファイルシステムアクセスコントロール、 | |
| 989 | 614 | ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、 |
| 990 | 認識できない実行ファイルフォーマット、など | |
| 615 | 認識できない実行ファイルフォーマット、などがあります。 | |
| 991 | これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは | |
| 992 | 通常は誤りであることに注意してください; なぜなら、これらは競合条件を | |
| 993 | 招きやすいからです。 | |
| 994 | 616 | |
| 995 | 617 | =begin original |
| 996 | 618 | |
| 997 | 619 | Also note that, for the superuser on the local filesystems, the C<-r>, |
| 998 | 620 | C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1 |
| 999 | 621 | if any execute bit is set in the mode. Scripts run by the superuser |
| 1000 | may thus need to do a | |
| 622 | may thus need to do a stat() to determine the actual mode of the file, | |
| 1001 | ||
| 623 | or temporarily set their effective uid to something else. | |
| 1002 | something else. | |
| 1003 | 624 | |
| 1004 | 625 | =end original |
| 1005 | 626 | |
| 1006 | 627 | ローカルファイルシステムのスーパーユーザには、 |
| 1007 | 628 | C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の |
| 1008 | 629 | いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が |
| 1009 | 630 | 返ることにも注意してください。 |
| 1010 | 631 | スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、 |
| 1011 | ||
| 632 | stat() を行なうか、実効 uid を一時的に別のものにする | |
| 1012 | 633 | 必要があるでしょう。 |
| 1013 | 634 | |
| 1014 | 635 | =begin original |
| 1015 | 636 | |
| 1016 | If you are using ACLs, there is a pragma called | |
| 637 | If you are using ACLs, there is a pragma called C<filetest> that may | |
| 1017 | ||
| 638 | produce more accurate results than the bare stat() mode bits. | |
| 1018 | ||
| 639 | When under the C<use filetest 'access'> the above-mentioned filetests | |
| 1019 | ||
| 640 | will test whether the permission can (not) be granted using the | |
| 1020 | ||
| 641 | access() family of system calls. Also note that the C<-x> and C<-X> may | |
| 1021 | family of system calls. Also note that the C<-x> and C<-X> tests may | |
| 1022 | 642 | under this pragma return true even if there are no execute permission |
| 1023 | 643 | bits set (nor any extra execute permission ACLs). This strangeness is |
| 1024 | due to the underlying system calls' definitions. | |
| 644 | due to the underlying system calls' definitions. Read the | |
| 1025 | ||
| 645 | documentation for the C<filetest> pragma for more information. | |
| 1026 | filehandle won't cache the results of the file tests when this pragma is | |
| 1027 | in effect. Read the documentation for the L<C<filetest>|filetest> | |
| 1028 | pragma for more information. | |
| 1029 | 646 | |
| 1030 | 647 | =end original |
| 1031 | 648 | |
| 1032 | ACL を使っている場合は、生の | |
| 649 | ACL を使っている場合は、生の stat() モードビットより | |
| 1033 | 精度の高い結果を作成する | |
| 650 | 精度の高い結果を作成する C<filetest> プラグマがあります。 | |
| 1034 | 651 | C<use filetest 'access'> とした場合、上述したファイルテストは |
| 1035 | システムコールの | |
| 652 | システムコールの access() ファミリーを使って権限が与えられているか | |
| 1036 | 653 | どうかをテストします。 |
| 1037 | また、このプラグマが指定されている場合、C<-x> と C<-X> | |
| 654 | また、このプラグマが指定されている場合、C<-x> と C<-X> は | |
| 1038 | 655 | たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない |
| 1039 | 656 | 場合でも真を返すことに注意してください。 |
| 1040 | 657 | この挙動は使用するシステムコールの定義によるものです。 |
| 1041 | C< | |
| 658 | さらなる情報については C<filetest> プラグマのドキュメントを | |
| 1042 | C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに | |
| 1043 | 注意してください。 | |
| 1044 | さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを | |
| 1045 | 659 | 参照してください。 |
| 1046 | 660 | |
| 1047 | 661 | =begin original |
| 1048 | 662 | |
| 1049 | ||
| 663 | Note that C<-s/a/b/> does not do a negated substitution. Saying | |
| 1050 | ||
| 664 | C<-exp($foo)> still works as expected, however--only single letters | |
| 1051 | ||
| 665 | following a minus are interpreted as file tests. | |
| 1052 | ||
| 1053 | ||
| 667 | =end original | |
| 1054 | ||
| 1055 | ||
| 669 | C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。 | |
| 1056 | ||
| 670 | しかし、C<-exp($foo)> は期待どおりに動作します。 | |
| 1057 | ||
| 671 | マイナス記号の後に英字が 1 字続くときにのみ、ファイルテストと | |
| 1058 | ||
| 672 | 解釈されます。 | |
| 1059 | ||
| 1060 | e | |
| 674 | =begin original | |
| 1061 | ||
| 676 | The C<-T> and C<-B> switches work as follows. The first block or so of the | |
| 677 | file is examined for odd characters such as strange control codes or | |
| 678 | characters with the high bit set. If too many strange characters (>30%) | |
| 679 | are found, it's a C<-B> file, otherwise it's a C<-T> file. Also, any file | |
| 680 | containing null in the first block is considered a binary file. If C<-T> | |
| 681 | or C<-B> is used on a filehandle, the current stdio buffer is examined | |
| 682 | rather than the first block. Both C<-T> and C<-B> return true on a null | |
| 1062 | 683 | file, or a file at EOF when testing a filehandle. Because you have to |
| 1063 | 684 | read a file to do the C<-T> test, on most occasions you want to use a C<-f> |
| 1064 | 685 | against the file first, as in C<next unless -f $file && -T $file>. |
| 1065 | 686 | |
| 1066 | 687 | =end original |
| 1067 | 688 | |
| 1068 | 689 | ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。 |
| 1069 | ファイルの最初の数ブロックを調べて、 | |
| 690 | ファイルの最初の数ブロックを調べて、変わった制御コードや | |
| 1070 | 調べます。 | |
| 1071 | もしそうなら、それは C<-T> ファイルです。 | |
| 1072 | さもなければ、ファイルの同じ位置から、変わった制御コードや | |
| 1073 | 691 | 上位ビットがセットされているような、通常のテキストには現れない文字を探します。 |
| 1074 | ||
| 692 | そのような文字が、たくさん (>30%) 見つかるようであれば、 | |
| 1075 | ||
| 693 | そのファイルは C<-B> ファイルであると判断され、 | |
| 1076 | ||
| 694 | それほど見つからなければ、C<-T> ファイルとなります。 | |
| 1077 | ||
| 695 | 最初のブロックにヌル文字が含まれるファイルも、 | |
| 1078 | ||
| 696 | バイナリファイルとみなされます。 | |
| 1079 | おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。) | |
| 1080 | 697 | C<-T> や C<-B> をファイルハンドルに対して用いると、 |
| 1081 | 最初のブロックを調べる代わりに、 | |
| 698 | 最初のブロックを調べる代わりに、標準入出力バッファを調べます。 | |
| 1082 | 699 | 調べたファイルの中身が何もないときや、 |
| 1083 | 700 | ファイルハンドルを調べたときに EOF に達して |
| 1084 | 701 | いたときには、C<-T> も C<-B> も「真」を返します。 |
| 1085 | 702 | C<-T> テストをするためにはファイルを読み込まないといけないので、 |
| 1086 | 703 | たいていは C<next unless -f $file && -T $file> というような形で |
| 1087 | 704 | まず調べたいファイルに対して C<-f> を使いたいはずです。 |
| 1088 | 705 | |
| 1089 | 706 | =begin original |
| 1090 | 707 | |
| 1091 | If any of the file tests (or either the | |
| 708 | If any of the file tests (or either the C<stat> or C<lstat> operators) are given | |
| 1092 | ||
| 709 | the special filehandle consisting of a solitary underline, then the stat | |
| 1093 | ||
| 710 | structure of the previous file test (or stat operator) is used, saving | |
| 1094 | ||
| 711 | a system call. (This doesn't work with C<-t>, and you need to remember | |
| 1095 | ||
| 712 | that lstat() and C<-l> will leave values in the stat structure for the | |
| 1096 | ||
| 713 | symbolic link, not the real file.) Example: | |
| 1097 | the stat structure for the symbolic link, not the real file.) (Also, if | |
| 1098 | the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call, | |
| 1099 | C<-T> and C<-B> will reset it with the results of C<stat _>). | |
| 1100 | Example: | |
| 1101 | 714 | |
| 1102 | 715 | =end original |
| 1103 | 716 | |
| 1104 | どのファイルテスト (あるいは、 | |
| 717 | どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、 | |
| 1105 | L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、 | |
| 1106 | 718 | 下線だけから成る特別なファイルハンドルを与えると、 |
| 1107 | 前回のファイルテスト (や | |
| 719 | 前回のファイルテスト (や stat) の stat 構造体が使われ、 | |
| 1108 | ||
| 720 | システムコールを省きます。 | |
| 1109 | (C<-t> には使えませんし、 | |
| 721 | (C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、 | |
| 1110 | ||
| 722 | シンボリックリンクの情報を stat 構造体に残すことを | |
| 1111 | 覚えておく必要があります。) | |
| 723 | 覚えておく必要があります。)例: | |
| 1112 | (また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、 | |
| 1113 | C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。 | |
| 1114 | 例: | |
| 1115 | 724 | |
| 1116 | 725 | print "Can do.\n" if -r $a || -w _ || -x _; |
| 1117 | 726 | |
| 1118 | 727 | stat($filename); |
| 1119 | 728 | print "Readable\n" if -r _; |
| 1120 | 729 | print "Writable\n" if -w _; |
| 1121 | 730 | print "Executable\n" if -x _; |
| 1122 | 731 | print "Setuid\n" if -u _; |
| 1123 | 732 | print "Setgid\n" if -g _; |
| 1124 | 733 | print "Sticky\n" if -k _; |
| 1125 | 734 | print "Text\n" if -T _; |
| 1126 | 735 | print "Binary\n" if -B _; |
| 1127 | 736 | |
| 1128 | =begin original | |
| 1129 | ||
| 1130 | As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file | |
| 1131 | test operators, in a way that C<-f -w -x $file> is equivalent to | |
| 1132 | C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use | |
| 1133 | the return value of C<-f $file> as an argument to another filetest | |
| 1134 | operator, no special magic will happen.) | |
| 1135 | ||
| 1136 | =end original | |
| 1137 | ||
| 1138 | Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を | |
| 1139 | スタックさせることができるので、C<-f -w -x $file> は | |
| 1140 | C<-x $file && -w _ && -f _> と等価です。 | |
| 1141 | (これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト | |
| 1142 | 演算子の引数として使う場合は、何の特別なことも起きません。) | |
| 1143 | ||
| 1144 | =begin original | |
| 1145 | ||
| 1146 | Portability issues: L<perlport/-X>. | |
| 1147 | ||
| 1148 | =end original | |
| 1149 | ||
| 1150 | 移植性の問題: L<perlport/-X>。 | |
| 1151 | ||
| 1152 | =begin original | |
| 1153 | ||
| 1154 | To avoid confusing would-be users of your code with mysterious | |
| 1155 | syntax errors, put something like this at the top of your script: | |
| 1156 | ||
| 1157 | =end original | |
| 1158 | ||
| 1159 | あなたのコードのユーザーが不思議な文法エラーで混乱することを | |
| 1160 | 避けるために、スクリプトの先頭に以下のようなことを書いてください: | |
| 1161 | ||
| 1162 | use 5.010; # so filetest ops can stack | |
| 1163 | ||
| 1164 | 737 | =item abs VALUE |
| 1165 | X<abs> X<absolute> | |
| 1166 | 738 | |
| 1167 | 739 | =item abs |
| 1168 | 740 | |
| 1169 | =for Pod::Functions absolute value function | |
| 1170 | ||
| 1171 | 741 | =begin original |
| 1172 | 742 | |
| 1173 | 743 | Returns the absolute value of its argument. |
| 1174 | If VALUE is omitted, uses | |
| 744 | If VALUE is omitted, uses C<$_>. | |
| 1175 | 745 | |
| 1176 | 746 | =end original |
| 1177 | 747 | |
| 1178 | 748 | 引数の絶対値を返します。 |
| 1179 | VALUE が省略された場合は、 | |
| 749 | VALUE が省略された場合は、C<$_> を使います。 | |
| 1180 | 750 | |
| 1181 | 751 | =item accept NEWSOCKET,GENERICSOCKET |
| 1182 | X<accept> | |
| 1183 | 752 | |
| 1184 | =for Pod::Functions accept an incoming socket connect | |
| 1185 | ||
| 1186 | 753 | =begin original |
| 1187 | 754 | |
| 1188 | Accepts an incoming socket connect, just as | |
| 755 | Accepts an incoming socket connect, just as the accept(2) system call | |
| 1189 | 756 | does. Returns the packed address if it succeeded, false otherwise. |
| 1190 | 757 | See the example in L<perlipc/"Sockets: Client/Server Communication">. |
| 1191 | 758 | |
| 1192 | 759 | =end original |
| 1193 | 760 | |
| 1194 | ||
| 761 | accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。 | |
| 1195 | 762 | 成功時にはパックされたアドレスを返し、失敗すれば偽を返します。 |
| 1196 | L<perlipc/"Sockets: Client/Server Communication"> の | |
| 763 | L<perlipc/"Sockets: Client/Server Communication"> の | |
| 764 | 例を参照してください。 | |
| 1197 | 765 | |
| 1198 | 766 | =begin original |
| 1199 | 767 | |
| 1200 | 768 | On systems that support a close-on-exec flag on files, the flag will |
| 1201 | 769 | be set for the newly opened file descriptor, as determined by the |
| 1202 | value of | |
| 770 | value of $^F. See L<perlvar/$^F>. | |
| 1203 | 771 | |
| 1204 | 772 | =end original |
| 1205 | 773 | |
| 1206 | 774 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 1207 | フラグは | |
| 775 | フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して | |
| 1208 | ||
| 776 | セットされます。L<perlvar/$^F> を参照してください。 | |
| 1209 | L<perlvar/$^F> を参照してください。 | |
| 1210 | 777 | |
| 1211 | 778 | =item alarm SECONDS |
| 1212 | X<alarm> | |
| 1213 | X<SIGALRM> | |
| 1214 | X<timer> | |
| 1215 | 779 | |
| 1216 | 780 | =item alarm |
| 1217 | 781 | |
| 1218 | =for Pod::Functions schedule a SIGALRM | |
| 1219 | ||
| 1220 | 782 | =begin original |
| 1221 | 783 | |
| 1222 | 784 | Arranges to have a SIGALRM delivered to this process after the |
| 1223 | specified number of | |
| 785 | specified number of seconds have elapsed. If SECONDS is not specified, | |
| 1224 | ||
| 786 | the value stored in C<$_> is used. (On some machines, | |
| 1225 | ||
| 787 | unfortunately, the elapsed time may be up to one second less than you | |
| 1226 | ||
| 788 | specified because of how seconds are counted.) Only one timer may be | |
| 1227 | ||
| 789 | counting at once. Each call disables the previous timer, and an | |
| 790 | argument of C<0> may be supplied to cancel the previous timer without | |
| 791 | starting a new one. The returned value is the amount of time remaining | |
| 792 | on the previous timer. | |
| 1228 | 793 | |
| 1229 | 794 | =end original |
| 1230 | 795 | |
| 1231 | 指定した | |
| 796 | 指定した秒数が経過した後に、自プロセスに SIGALRM が | |
| 1232 | 送られてくるようにします。 | |
| 797 | 送られてくるようにします。SECONDS が指定されていない場合は、 | |
| 1233 | ||
| 798 | C<$_>に格納されている値を使います。 | |
| 1234 | ||
| 799 | (マシンによっては、秒の | |
| 1235 | ||
| 800 | 数え方が異なるため、指定した秒数よりも最大で 1 秒少ない経過時間となります。) | |
| 1236 | 1 | |
| 801 | 一度には 1 つのタイマだけが設定可能です。 | |
| 1237 | ||
| 1238 | =begin original | |
| 1239 | ||
| 1240 | Only one timer may be counting at once. Each call disables the | |
| 1241 | previous timer, and an argument of C<0> may be supplied to cancel the | |
| 1242 | previous timer without starting a new one. The returned value is the | |
| 1243 | amount of time remaining on the previous timer. | |
| 1244 | ||
| 1245 | =end original | |
| 1246 | ||
| 1247 | 一度には一つのタイマだけが設定可能です。 | |
| 1248 | 802 | 呼び出しを行なう度に、以前のタイマを無効にしますし、 |
| 1249 | 803 | 新しくタイマを起動しないで以前のタイマをキャンセルするために |
| 1250 | 804 | 引数に C<0> を指定して呼び出すことができます。 |
| 1251 | 805 | 以前のタイマの残り時間が、返り値となります。 |
| 1252 | 806 | |
| 1253 | 807 | =begin original |
| 1254 | 808 | |
| 1255 | For delays of finer granularity than one second, | |
| 809 | For delays of finer granularity than one second, you may use Perl's | |
| 1256 | ||
| 810 | four-argument version of select() leaving the first three arguments | |
| 1257 | di | |
| 811 | undefined, or you might be able to use the C<syscall> interface to | |
| 1258 | ||
| 812 | access setitimer(2) if your system supports it. The Time::HiRes module | |
| 1259 | ||
| 813 | from CPAN may also prove useful. | |
| 1260 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three | |
| 1261 | arguments undefined, or you might be able to use the | |
| 1262 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
| 1263 | if your system supports it. See L<perlfaq8> for details. | |
| 1264 | 814 | |
| 1265 | 815 | =end original |
| 1266 | 816 | |
| 1267 | 1 秒より精度の高いスリープを行なうには、 | |
| 817 | 1 秒より精度の高いスリープを行なうには、 | |
| 1268 | ||
| 818 | Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、 | |
| 1269 | ||
| 819 | setitimer(2) をサポートしているシステムでは、Perl の | |
| 1270 | ||
| 820 | C<syscall> インタフェースを使ってアクセスすることができます。 | |
| 1271 | ||
| 821 | CPAN の Time::HiRes モジュールも有用でしょう。 | |
| 1272 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
| 1273 | アクセスすることもできます。 | |
| 1274 | 詳しくは L<perlfaq8> を参照してください。 | |
| 1275 | 822 | |
| 1276 | 823 | =begin original |
| 1277 | 824 | |
| 1278 | It is usually a mistake to intermix | |
| 825 | It is usually a mistake to intermix C<alarm> and C<sleep> calls. | |
| 1279 | ||
| 826 | (C<sleep> may be internally implemented in your system with C<alarm>) | |
| 1280 | internally implemented on your system with L<C<alarm>|/alarm SECONDS>. | |
| 1281 | 827 | |
| 1282 | 828 | =end original |
| 1283 | 829 | |
| 1284 | ||
| 830 | C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです。 | |
| 1285 | ||
| 831 | (C<sleep> は内部的に C<alarm> を使って内部的に実装されているかもしれません) | |
| 1286 | L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも | |
| 1287 | しれないからです。 | |
| 1288 | 832 | |
| 1289 | 833 | =begin original |
| 1290 | 834 | |
| 1291 | If you want to use | |
| 835 | If you want to use C<alarm> to time out a system call you need to use an | |
| 1292 | ||
| 836 | C<eval>/C<die> pair. You can't rely on the alarm causing the system call to | |
| 1293 | ||
| 837 | fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to | |
| 1294 | ||
| 838 | restart system calls on some systems. Using C<eval>/C<die> always works, | |
| 1295 | ||
| 839 | modulo the caveats given in L<perlipc/"Signals">. | |
| 1296 | L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the | |
| 1297 | caveats given in L<perlipc/"Signals">. | |
| 1298 | 840 | |
| 1299 | 841 | =end original |
| 1300 | 842 | |
| 1301 | ||
| 843 | C<alarm> をシステムコールの時間切れのために使いたいなら、 | |
| 1302 | ||
| 844 | C<eval>/C<die> のペアで使う必要があります。 | |
| 1303 | システムコールが失敗したときに | |
| 845 | システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに | |
| 1304 | ||
| 846 | 頼ってはいけません。なぜならシステムによっては Perl は | |
| 1305 | 847 | システムコールを再開するためにシグナルハンドラを設定するからです。 |
| 1306 | ||
| 848 | C<eval>/C<die> は常にうまく動きます。 | |
| 1307 | 注意点については L<perlipc/"Signals"> を参照して | |
| 849 | 注意点については L<perlipc/"Signals"> を参照して下さい。 | |
| 1308 | 850 | |
| 1309 | 851 | eval { |
| 1310 | ||
| 852 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required | |
| 1311 | ||
| 853 | alarm $timeout; | |
| 1312 | ||
| 854 | $nread = sysread SOCKET, $buffer, $size; | |
| 1313 | ||
| 855 | alarm 0; | |
| 1314 | 856 | }; |
| 1315 | 857 | if ($@) { |
| 1316 | ||
| 858 | die unless $@ eq "alarm\n"; # propagate unexpected errors | |
| 1317 | | |
| 859 | # timed out | |
| 1318 | 860 | } |
| 1319 | 861 | else { |
| 1320 | | |
| 862 | # didn't | |
| 1321 | 863 | } |
| 1322 | 864 | |
| 1323 | =begin original | |
| 1324 | ||
| 1325 | For more information see L<perlipc>. | |
| 1326 | ||
| 1327 | =end original | |
| 1328 | ||
| 1329 | さらなる情報については L<perlipc> を参照してください。 | |
| 1330 | ||
| 1331 | =begin original | |
| 1332 | ||
| 1333 | Portability issues: L<perlport/alarm>. | |
| 1334 | ||
| 1335 | =end original | |
| 1336 | ||
| 1337 | 移植性の問題: L<perlport/alarm>。 | |
| 1338 | ||
| 1339 | 865 | =item atan2 Y,X |
| 1340 | X<atan2> X<arctangent> X<tan> X<tangent> | |
| 1341 | 866 | |
| 1342 | =for Pod::Functions arctangent of Y/X in the range -PI to PI | |
| 1343 | ||
| 1344 | 867 | =begin original |
| 1345 | 868 | |
| 1346 | 869 | Returns the arctangent of Y/X in the range -PI to PI. |
| 1347 | 870 | |
| 1348 | 871 | =end original |
| 1349 | 872 | |
| 1350 | 873 | -πからπの範囲で Y/X の逆正接を返します。 |
| 1351 | 874 | |
| 1352 | 875 | =begin original |
| 1353 | 876 | |
| 1354 | For the tangent operation, you may use the | |
| 877 | For the tangent operation, you may use the C<Math::Trig::tan> | |
| 1355 | ||
| 878 | function, or use the familiar relation: | |
| 1356 | relation: | |
| 1357 | 879 | |
| 1358 | 880 | =end original |
| 1359 | 881 | |
| 1360 | 正接を求めたいときは、 | |
| 882 | 正接を求めたいときは、C<Math::Trig::tan> を使うか、 | |
| 1361 | 883 | 以下のよく知られた関係を使ってください。 |
| 1362 | 884 | |
| 1363 | 885 | sub tan { sin($_[0]) / cos($_[0]) } |
| 1364 | 886 | |
| 1365 | =begin original | |
| 1366 | ||
| 1367 | The return value for C<atan2(0,0)> is implementation-defined; consult | |
| 1368 | your L<atan2(3)> manpage for more information. | |
| 1369 | ||
| 1370 | =end original | |
| 1371 | ||
| 1372 | C<atan2(0,0)> の返り値は実装依存です; さらなる情報については | |
| 1373 | L<atan2(3)> man ページを参照してください。 | |
| 1374 | ||
| 1375 | =begin original | |
| 1376 | ||
| 1377 | Portability issues: L<perlport/atan2>. | |
| 1378 | ||
| 1379 | =end original | |
| 1380 | ||
| 1381 | 移植性の問題: L<perlport/atan2>。 | |
| 1382 | ||
| 1383 | 887 | =item bind SOCKET,NAME |
| 1384 | X<bind> | |
| 1385 | 888 | |
| 1386 | =for Pod::Functions binds an address to a socket | |
| 1387 | ||
| 1388 | 889 | =begin original |
| 1389 | 890 | |
| 1390 | Binds a network address to a socket, just as | |
| 891 | Binds a network address to a socket, just as the bind system call | |
| 1391 | 892 | does. Returns true if it succeeded, false otherwise. NAME should be a |
| 1392 | 893 | packed address of the appropriate type for the socket. See the examples in |
| 1393 | 894 | L<perlipc/"Sockets: Client/Server Communication">. |
| 1394 | 895 | |
| 1395 | 896 | =end original |
| 1396 | 897 | |
| 1397 | ||
| 898 | bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。 | |
| 1398 | ||
| 899 | 成功時には真を返し、失敗時には偽を返します。 | |
| 1399 | ||
| 900 | NAME は、ソケットに対する、適切な型のパックされたアドレスでなければなりません。 | |
| 1400 | NAME は、ソケットに対する、適切な型のパックされた | |
| 1401 | アドレスでなければなりません。 | |
| 1402 | 901 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 1403 | 902 | |
| 1404 | =item binmode FILEHANDLE, L | |
| 903 | =item binmode FILEHANDLE, DISCIPLINE | |
| 1405 | X<binmode> X<binary> X<text> X<DOS> X<Windows> | |
| 1406 | 904 | |
| 1407 | 905 | =item binmode FILEHANDLE |
| 1408 | 906 | |
| 1409 | =for Pod::Functions prepare binary files for I/O | |
| 1410 | ||
| 1411 | 907 | =begin original |
| 1412 | 908 | |
| 1413 | Arranges for FILEHANDLE to be read or written in "binary" or "text" | |
| 909 | Arranges for FILEHANDLE to be read or written in "binary" or "text" mode | |
| 1414 | ||
| 910 | on systems where the run-time libraries distinguish between binary and | |
| 1415 | ||
| 911 | text files. If FILEHANDLE is an expression, the value is taken as the | |
| 1416 | ||
| 912 | name of the filehandle. DISCIPLINE can be either of C<":raw"> for | |
| 1417 | o | |
| 913 | binary mode or C<":crlf"> for "text" mode. If the DISCIPLINE is | |
| 1418 | ||
| 914 | omitted, it defaults to C<":raw">. | |
| 1419 | 915 | |
| 1420 | 916 | =end original |
| 1421 | 917 | |
| 1422 | 918 | バイナリファイルとテキストファイルを区別する OS において、 |
| 1423 | 919 | FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように |
| 1424 | 920 | 指定します。 |
| 1425 | 921 | FILEHANDLE が式である場合には、その式の値がファイルハンドルの |
| 1426 | 922 | 名前として使われます。 |
| 1427 | ||
| 923 | DISCIPLINE はバイナリモードを示す C<":raw"> か | |
| 1428 | ||
| 924 | テキストモードを示す C<":crlf"> のどちらかです。 | |
| 925 | DISCIPLINE を省略すると、デフォルトとして C<":raw"> が使われます。 | |
| 1429 | 926 | |
| 1430 | 927 | =begin original |
| 1431 | 928 | |
| 1432 | ||
| 929 | binmode() should be called after open() but before any I/O is done on | |
| 1433 | ||
| 930 | the filehandle. | |
| 1434 | working with a text file. For the sake of portability it is a good idea | |
| 1435 | always to use it when appropriate, and never to use it when it isn't | |
| 1436 | appropriate. Also, people can set their I/O to be by default | |
| 1437 | UTF8-encoded Unicode, not bytes. | |
| 1438 | 931 | |
| 1439 | 932 | =end original |
| 1440 | 933 | |
| 1441 | ||
| 934 | binmode() は open() の後、ファイルハンドルに対する入出力が | |
| 1442 | ||
| 935 | 行われる前に呼び出されるべきです。 | |
| 1443 | システムもあります(一般的には DOS と Windows ベースのシステムです)。 | |
| 1444 | 移植性のために、適切なときには常にこれを使い、適切でないときには | |
| 1445 | 決して使わないというのは良い考えです。 | |
| 1446 | また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた | |
| 1447 | Unicode にセットすることも出来ます。 | |
| 1448 | 936 | |
| 1449 | 937 | =begin original |
| 1450 | 938 | |
| 1451 | ||
| 939 | On many systems binmode() currently has no effect, but in future, it | |
| 1452 | ||
| 940 | will be extended to support user-defined input and output disciplines. | |
| 1453 | ||
| 941 | On some systems binmode() is necessary when you're not working with a | |
| 942 | text file. For the sake of portability it is a good idea to always use | |
| 943 | it when appropriate, and to never use it when it isn't appropriate. | |
| 1454 | 944 | |
| 1455 | 945 | =end original |
| 1456 | 946 | |
| 1457 | ||
| 947 | 多くのシステムでは現在のところ binmode() は何の効果もありませんが、 | |
| 1458 | ||
| 948 | 将来ユーザーが定義した入出力機能に対応するように拡張される予定です。 | |
| 1459 | ||
| 949 | テキストファイルでないものを扱う場合に binmode() が必要な | |
| 950 | システムもあります。 | |
| 951 | 移植性のために、適切なときには常にこれを使い、適切でないときには | |
| 952 | 決して使わないというのは良い考えです。 | |
| 1460 | 953 | |
| 1461 | 954 | =begin original |
| 1462 | 955 | |
| 1463 | I | |
| 956 | In other words: Regardless of platform, use binmode() on binary | |
| 1464 | ||
| 957 | files, and do not use binmode() on text files. | |
| 1465 | When LAYER is present, using binmode on a text file makes sense. | |
| 1466 | 958 | |
| 1467 | 959 | =end original |
| 1468 | 960 | |
| 1469 | ||
| 961 | 言い換えると: プラットフォームに関わらず、 | |
| 1470 | ||
| 962 | バイナリファイルに対しては binmode() を使ってください。 | |
| 1471 | ||
| 963 | テキストファイルには binmode() を使わないでください。 | |
| 1472 | LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。 | |
| 1473 | 964 | |
| 1474 | 965 | =begin original |
| 1475 | 966 | |
| 1476 | ||
| 967 | The C<open> pragma can be used to establish default disciplines. | |
| 1477 | ||
| 968 | See L<open>. | |
| 1478 | translation and marking it as bytes (as opposed to Unicode characters). | |
| 1479 | Note that, despite what may be implied in I<"Programming Perl"> (the | |
| 1480 | Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>. | |
| 1481 | Other layers that would affect the binary nature of the stream are | |
| 1482 | I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the | |
| 1483 | PERLIO environment variable. | |
| 1484 | 969 | |
| 1485 | 970 | =end original |
| 1486 | 971 | |
| 1487 | ||
| 972 | C<open> プラグマを使って、デフォルトの動作を設定できます。 | |
| 1488 | ||
| 973 | L<open> を参照して下さい。 | |
| 1489 | これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく) | |
| 1490 | バイトであるとマークしたりすることを含みます。 | |
| 1491 | I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、 | |
| 1492 | C<:raw> は単なる C<:crlf> の I<逆ではありません>。 | |
| 1493 | ストリームのバイナリとしての性質に影響を与える | |
| 1494 | I<その他の層も無効にされます>。 | |
| 1495 | L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。 | |
| 1496 | 974 | |
| 1497 | 975 | =begin original |
| 1498 | 976 | |
| 1499 | The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the | |
| 1500 | form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to | |
| 1501 | establish default I/O layers. | |
| 1502 | ||
| 1503 | =end original | |
| 1504 | ||
| 1505 | C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は | |
| 1506 | I/O I<層> が呼び出されます。 | |
| 1507 | L<open> プラグマはデフォルト I/O 層を指定するために使われます。 | |
| 1508 | ||
| 1509 | =begin original | |
| 1510 | ||
| 1511 | I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER> | |
| 1512 | function is described as "DISCIPLINE" in "Programming Perl, 3rd | |
| 1513 | Edition". However, since the publishing of this book, by many known as | |
| 1514 | "Camel III", the consensus of the naming of this functionality has moved | |
| 1515 | from "discipline" to "layer". All documentation of this version of Perl | |
| 1516 | therefore refers to "layers" rather than to "disciplines". Now back to | |
| 1517 | the regularly scheduled documentation...> | |
| 1518 | ||
| 1519 | =end original | |
| 1520 | ||
| 1521 | I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは | |
| 1522 | 「プログラミングPerl 第 3 版」では | |
| 1523 | 「ディシプリン(DISCIPLINE)」と表現されていました。 | |
| 1524 | しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は | |
| 1525 | 「ディシプリン」から「層」に変更することで合意されました。 | |
| 1526 | 従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく | |
| 1527 | 「層」と記述されています。では通常の解説に戻ります…> | |
| 1528 | ||
| 1529 | =begin original | |
| 1530 | ||
| 1531 | To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>. | |
| 1532 | C<:utf8> just marks the data as UTF-8 without further checking, | |
| 1533 | while C<:encoding(UTF-8)> checks the data for actually being valid | |
| 1534 | UTF-8. More details can be found in L<PerlIO::encoding>. | |
| 1535 | ||
| 1536 | =end original | |
| 1537 | ||
| 1538 | FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か | |
| 1539 | C<:encoding(UTF-8)> を使ってください。 | |
| 1540 | C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、 | |
| 1541 | C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。 | |
| 1542 | さらなる詳細は L<PerlIO::encoding> にあります。 | |
| 1543 | ||
| 1544 | =begin original | |
| 1545 | ||
| 1546 | In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called | |
| 1547 | after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the | |
| 1548 | filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally | |
| 1549 | flushes any pending buffered output data (and perhaps pending input | |
| 1550 | data) on the handle. An exception to this is the C<:encoding> layer | |
| 1551 | that changes the default character encoding of the handle. | |
| 1552 | The C<:encoding> layer sometimes needs to be called in | |
| 1553 | mid-stream, and it doesn't flush the stream. C<:encoding> | |
| 1554 | also implicitly pushes on top of itself the C<:utf8> layer because | |
| 1555 | internally Perl operates on UTF8-encoded Unicode characters. | |
| 1556 | ||
| 1557 | =end original | |
| 1558 | ||
| 1559 | 一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は | |
| 1560 | L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに対する | |
| 1561 | I/O 操作をする前に呼び出すべきです。 | |
| 1562 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの | |
| 1563 | ファイルハンドルに対してバッファリングされている全ての出力データ | |
| 1564 | (およびおそらくは入力データ)をフラッシュします。 | |
| 1565 | 例外は、このハンドルに対するデフォルト文字エンコーディングを変更する | |
| 1566 | C<:encoding> 層です。 | |
| 1567 | C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、 | |
| 1568 | それによってストリームはフラッシュされません。 | |
| 1569 | Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、 | |
| 1570 | C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。 | |
| 1571 | ||
| 1572 | =begin original | |
| 1573 | ||
| 1574 | 977 | The operating system, device drivers, C libraries, and Perl run-time |
| 1575 | system all | |
| 978 | system all work together to let the programmer treat a single | |
| 1576 | character (C<\n>) as the line terminator, irrespective of external | |
| 979 | character (C<\n>) as the line terminator, irrespective of the external | |
| 1577 | 980 | representation. On many operating systems, the native text file |
| 1578 | 981 | representation matches the internal representation, but on some |
| 1579 | 982 | platforms the external representation of C<\n> is made up of more than |
| 1580 | 983 | one character. |
| 1581 | 984 | |
| 1582 | 985 | =end original |
| 1583 | 986 | |
| 1584 | 987 | オペレーティングシステム、デバイスドライバ、C ライブラリ、 |
| 1585 | 988 | Perl ランタイムシステムは全て、プログラマが外部表現に関わらず |
| 1586 | 989 | 1 文字 (C<\n>) を行終端として扱えるように協調作業します。 |
| 1587 | 990 | 多くのオペレーティングシステムでは、ネイティブテキストファイル表現は |
| 1588 | 991 | 内部表現と同じですが、C<\n> の外部表現が複数文字になる |
| 1589 | 992 | プラットフォームもあります。 |
| 1590 | 993 | |
| 1591 | 994 | =begin original |
| 1592 | 995 | |
| 1593 | ||
| 996 | Mac OS and all variants of Unix use a single character to end each line | |
| 1594 | ||
| 997 | in the external representation of text (even though that single | |
| 1595 | ||
| 998 | character is not necessarily the same across these platforms). | |
| 1596 | ||
| 999 | Consequently binmode() has no effect on these operating systems. In | |
| 1597 | systems like | |
| 1000 | other systems like VMS, MS-DOS and the various flavors of MS-Windows | |
| 1598 | sees a C<\n> as a simple C<\cJ>, but what's stored in text | |
| 1001 | your program sees a C<\n> as a simple C<\cJ>, but what's stored in text | |
| 1599 | two characters C<\cM\cJ>. That means that if you don't | |
| 1002 | files are the two characters C<\cM\cJ>. That means that, if you don't | |
| 1600 | ||
| 1003 | use binmode() on these systems, C<\cM\cJ> sequences on disk will be | |
| 1601 | ||
| 1004 | converted to C<\n> on input, and any C<\n> in your program will be | |
| 1602 | ||
| 1005 | converted back to C<\cM\cJ> on output. This is what you want for text | |
| 1603 | ||
| 1006 | files, but it can be disastrous for binary files. | |
| 1604 | 1007 | |
| 1605 | 1008 | =end original |
| 1606 | 1009 | |
| 1607 | 全ての Unix 系 | |
| 1010 | Mac OS と全ての Unix 系はテキストの外部表現として各行の末尾に 1 つの文字を | |
| 1608 | ||
| 1011 | 使っています(その文字はプラットフォームによって異なる場合もあります)。 | |
| 1609 | ||
| 1012 | その結果、binmode() はこれらの OS では何の効果もありません。 | |
| 1610 | Unix とほとんどのVMS のファイルでは改行です)。 | |
| 1611 | 1013 | VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、 |
| 1612 | 1014 | プログラムからは C<\n> は単純に C<\cJ> に見えますが、 |
| 1613 | 1015 | テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。 |
| 1614 | つまり、もしこれらのシステムで | |
| 1016 | つまり、もしこれらのシステムで binmode() を使わないと、 | |
| 1615 | ||
| 1017 | ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、 | |
| 1616 | 1018 | プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。 |
| 1617 | 1019 | これはテキストファイルの場合は思い通りの結果でしょうが、 |
| 1618 | 1020 | バイナリファイルの場合は悲惨です。 |
| 1619 | 1021 | |
| 1620 | 1022 | =begin original |
| 1621 | 1023 | |
| 1622 | Another consequence of using | |
| 1024 | Another consequence of using binmode() (on some systems) is that | |
| 1623 | ||
| 1025 | special end-of-file markers will be seen as part of the data stream. | |
| 1624 | ||
| 1026 | For systems from the Microsoft family this means that if your binary | |
| 1625 | ||
| 1027 | data contains C<\cZ>, the I/O subsystem will regard it as the end of | |
| 1626 | ||
| 1028 | the file, unless you use binmode(). | |
| 1627 | L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 1628 | 1029 | |
| 1629 | 1030 | =end original |
| 1630 | 1031 | |
| 1631 | ||
| 1032 | binmode() を(いくつかのシステムで)使うことによるその他の作用としては、 | |
| 1632 | ||
| 1033 | 特別なファイル終端マーカーがデータストリームの一部として | |
| 1633 | ||
| 1034 | 見られることです。 | |
| 1634 | Microsoft ファミリーのシステムでは、 | |
| 1035 | Microsoft ファミリーのシステムでは、binmode() を使っていないと | |
| 1635 | ||
| 1036 | もしバイナリデータに C<\cZ> が含まれていたときに、I/O サブシステムが | |
| 1636 | ||
| 1037 | これをファイル終端とみなすことを意味します。 | |
| 1637 | I/O サブシステムがこれをファイル終端とみなすことを意味します。 | |
| 1638 | 1038 | |
| 1639 | 1039 | =begin original |
| 1640 | 1040 | |
| 1641 | ||
| 1041 | binmode() is not only important for readline() and print() operations, | |
| 1642 | ||
| 1042 | but also when using read(), seek(), sysread(), syswrite() and tell() | |
| 1643 | ||
| 1043 | (see L<perlport> for more details). See the C<$/> and C<$\> variables | |
| 1644 | L< | |
| 1044 | in L<perlvar> for how to manually set your input and output | |
| 1645 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 1646 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1647 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and | |
| 1648 | L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the | |
| 1649 | L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in | |
| 1650 | L<perlvar> for how to manually set your input and output | |
| 1651 | 1045 | line-termination sequences. |
| 1652 | 1046 | |
| 1653 | 1047 | =end original |
| 1654 | 1048 | |
| 1655 | ||
| 1049 | binmode() は readline() と print() 操作にだけではなく、 | |
| 1656 | ||
| 1050 | read(), seek(), sysread(), syswrite(), tell() を使うときにも重要です | |
| 1657 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1658 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 1659 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1660 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 1661 | L<C<tell>|/tell FILEHANDLE> を使うときにも重要です | |
| 1662 | 1051 | (詳細は L<perlport> を参照してください)。 |
| 1663 | 1052 | 入出力の行端末シーケンスを手動でセットする方法については |
| 1664 | L<perlvar> の | |
| 1053 | L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。 | |
| 1665 | L<C<$\>|perlvar/$\> 変数を参照してください。 | |
| 1666 | 1054 | |
| 1667 | =begin original | |
| 1668 | ||
| 1669 | Portability issues: L<perlport/binmode>. | |
| 1670 | ||
| 1671 | =end original | |
| 1672 | ||
| 1673 | 移植性の問題: L<perlport/binmode>。 | |
| 1674 | ||
| 1675 | 1055 | =item bless REF,CLASSNAME |
| 1676 | X<bless> | |
| 1677 | 1056 | |
| 1678 | 1057 | =item bless REF |
| 1679 | 1058 | |
| 1680 | =for Pod::Functions create an object | |
| 1681 | ||
| 1682 | 1059 | =begin original |
| 1683 | 1060 | |
| 1684 | 1061 | This function tells the thingy referenced by REF that it is now an object |
| 1685 | in the CLASSNAME package. If CLASSNAME is | |
| 1062 | in the CLASSNAME package. If CLASSNAME is omitted, the current package | |
| 1686 | i | |
| 1063 | is used. Because a C<bless> is often the last thing in a constructor, | |
| 1687 | ||
| 1064 | it returns the reference for convenience. Always use the two-argument | |
| 1688 | ||
| 1065 | version if the function doing the blessing might be inherited by a | |
| 1689 | ||
| 1066 | derived class. See L<perltoot> and L<perlobj> for more about the blessing | |
| 1690 | Always use the two-argument version if a derived class might inherit the | |
| 1691 | method doing the blessing. See L<perlobj> for more about the blessing | |
| 1692 | 1067 | (and blessings) of objects. |
| 1693 | 1068 | |
| 1694 | 1069 | =end original |
| 1695 | 1070 | |
| 1696 | 1071 | この関数は、REF で渡された オブジェクトに対し、 |
| 1697 | 1072 | CLASSNAME 内のオブジェクトとなったことを伝えます。 |
| 1698 | CLASSNAME が空文字列の場合、C<main> パッケージを参照しているものと | |
| 1699 | 解釈されます。 | |
| 1700 | 1073 | CLASSNAME が省略された場合には、その時点のパッケージとなります。 |
| 1701 | ||
| 1074 | C<bless> は通常、コンストラクタの最後に置かれますので、 | |
| 1702 | ||
| 1075 | 簡便のためにそのリファレンスを返します。 | |
| 1703 | ||
| 1076 | bless される関数が派生クラスによって継承される場合は、 | |
| 1704 | 1077 | 常に 2 引数版を使ってください。 |
| 1705 | オブジェクトの bless (や再 bless) について、 | |
| 1078 | オブジェクトの bless (や再 bless) について、 | |
| 1706 | 参照してください。 | |
| 1079 | 詳しくは L<perltoot> と L<perlobj> を参照してください。 | |
| 1707 | 1080 | |
| 1708 | 1081 | =begin original |
| 1709 | 1082 | |
| 1710 | 1083 | Consider always blessing objects in CLASSNAMEs that are mixed case. |
| 1711 | 1084 | Namespaces with all lowercase names are considered reserved for |
| 1712 | Perl pragma | |
| 1085 | Perl pragmata. Builtin types have all uppercase names, so to prevent | |
| 1713 | confusion, you may wish to avoid such package names as well. | |
| 1086 | confusion, you may wish to avoid such package names as well. Make sure | |
| 1714 | ||
| 1087 | that CLASSNAME is a true value. | |
| 1715 | uses the result of L<C<ref>|/ref EXPR> as a truth value. | |
| 1716 | 1088 | |
| 1717 | 1089 | =end original |
| 1718 | 1090 | |
| 1719 | 1091 | 大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを |
| 1720 | 1092 | 考慮してください。 |
| 1721 | 1093 | 全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。 |
| 1722 | 組み込みの型は全て大文字の名前を持ちます | |
| 1094 | 組み込みの型は全て大文字の名前を持ちますので、混乱を避けるために、 | |
| 1723 | 混乱を避けるために、 | |
| 1724 | 1095 | パッケージ名としてこのような名前は避けるべきです。 |
| 1725 | 1096 | CLASSNAME は真の値を持つようにしてください。 |
| 1726 | クラス名として C<0> は避けてください; 多くのコードが誤って | |
| 1727 | L<C<ref>|/ref EXPR> の結果を真の値として使っているからです。 | |
| 1728 | 1097 | |
| 1729 | 1098 | =begin original |
| 1730 | 1099 | |
| 1731 | 1100 | See L<perlmod/"Perl Modules">. |
| 1732 | 1101 | |
| 1733 | 1102 | =end original |
| 1734 | 1103 | |
| 1735 | L<perlmod/"Perl Modules"> を参照して | |
| 1104 | L<perlmod/"Perl Modules"> を参照して下さい。 | |
| 1736 | 1105 | |
| 1737 | =item break | |
| 1738 | ||
| 1739 | =for Pod::Functions +switch break out of a C<given> block | |
| 1740 | ||
| 1741 | =begin original | |
| 1742 | ||
| 1743 | Break out of a C<given> block. | |
| 1744 | ||
| 1745 | =end original | |
| 1746 | ||
| 1747 | C<given> ブロックから脱出します。 | |
| 1748 | ||
| 1749 | =begin original | |
| 1750 | ||
| 1751 | L<C<break>|/break> is available only if the | |
| 1752 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it | |
| 1753 | is prefixed with C<CORE::>. The | |
| 1754 | L<C<"switch"> feature|feature/The 'switch' feature> is enabled | |
| 1755 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 1756 | scope. | |
| 1757 | ||
| 1758 | =end original | |
| 1759 | ||
| 1760 | L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が | |
| 1761 | 有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。 | |
| 1762 | L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで | |
| 1763 | C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。 | |
| 1764 | ||
| 1765 | 1106 | =item caller EXPR |
| 1766 | X<caller> X<call stack> X<stack> X<stack trace> | |
| 1767 | 1107 | |
| 1768 | 1108 | =item caller |
| 1769 | 1109 | |
| 1770 | =for Pod::Functions get context of the current subroutine call | |
| 1771 | ||
| 1772 | 1110 | =begin original |
| 1773 | 1111 | |
| 1774 | Returns the context of the current | |
| 1112 | Returns the context of the current subroutine call. In scalar context, | |
| 1775 | ||
| 1113 | returns the caller's package name if there is a caller, that is, if | |
| 1776 | we're in a subroutine or | |
| 1114 | we're in a subroutine or C<eval> or C<require>, and the undefined value | |
| 1777 | ||
| 1115 | otherwise. In list context, returns | |
| 1778 | caller never returns XS subs and they are skipped. The next pure perl | |
| 1779 | sub will appear instead of the XS sub in caller's return values. In | |
| 1780 | list context, caller returns | |
| 1781 | 1116 | |
| 1782 | 1117 | =end original |
| 1783 | 1118 | |
| 1784 | その時点の | |
| 1119 | その時点のサブルーチン呼び出しのコンテキストを返します。 | |
| 1785 | スカラコンテキストでは、呼び元が | |
| 1120 | スカラコンテキストでは、呼び元がある場合 | |
| 1786 | (サブルーチン、 | |
| 1121 | (サブルーチン、C<eval>、C<require> の中にいるとき) には | |
| 1787 | ||
| 1122 | 呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。 | |
| 1788 | ||
| 1123 | リストコンテキストでは、以下を返します: | |
| 1789 | caller は XS サブルーチンを返すことはなく、それらは飛ばされます。 | |
| 1790 | XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に | |
| 1791 | なります。 | |
| 1792 | リストコンテキストでは、caller は以下を返します: | |
| 1793 | 1124 | |
| 1794 | | |
| 1125 | ($package, $filename, $line) = caller; | |
| 1795 | my ($package, $filename, $line) = caller; | |
| 1796 | 1126 | |
| 1797 | 1127 | =begin original |
| 1798 | 1128 | |
| 1799 | 1129 | With EXPR, it returns some extra information that the debugger uses to |
| 1800 | 1130 | print a stack trace. The value of EXPR indicates how many call frames |
| 1801 | 1131 | to go back before the current one. |
| 1802 | 1132 | |
| 1803 | 1133 | =end original |
| 1804 | 1134 | |
| 1805 | 1135 | EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。 |
| 1806 | 1136 | EXPR の値は、現状から数えて、 |
| 1807 | 1137 | いくつ前のコールフレームまで戻るかを示します。 |
| 1808 | 1138 | |
| 1809 | | |
| 1139 | ($package, $filename, $line, $subroutine, $hasargs, | |
| 1810 | | |
| 1140 | $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller($i); | |
| 1811 | 1141 | |
| 1812 | # 5 6 7 8 9 10 | |
| 1813 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) | |
| 1814 | = caller($i); | |
| 1815 | ||
| 1816 | 1142 | =begin original |
| 1817 | 1143 | |
| 1818 | Here | |
| 1144 | Here $subroutine may be C<(eval)> if the frame is not a subroutine | |
| 1819 | ||
| 1145 | call, but an C<eval>. In such a case additional elements $evaltext and | |
| 1820 | ||
| 1146 | C<$is_require> are set: C<$is_require> is true if the frame is created by a | |
| 1821 | ||
| 1147 | C<require> or C<use> statement, $evaltext contains the text of the | |
| 1822 | C< | |
| 1148 | C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement, | |
| 1823 | ||
| 1149 | $filename is C<(eval)>, but $evaltext is undefined. (Note also that | |
| 1824 | statement | |
| 1150 | each C<use> statement creates a C<require> frame inside an C<eval EXPR>) | |
| 1825 | ||
| 1151 | frame. C<$hasargs> is true if a new instance of C<@_> was set up for the | |
| 1826 | ||
| 1152 | frame. C<$hints> and C<$bitmask> contain pragmatic hints that the caller | |
| 1827 | ||
| 1153 | was compiled with. The C<$hints> and C<$bitmask> values are subject to | |
| 1828 | ||
| 1154 | change between versions of Perl, and are not meant for external use. | |
| 1829 | $subroutine may also be C<(unknown)> if this particular subroutine | |
| 1830 | happens to have been deleted from the symbol table. C<$hasargs> is true | |
| 1831 | if a new instance of L<C<@_>|perlvar/@_> was set up for the frame. | |
| 1832 | C<$hints> and C<$bitmask> contain pragmatic hints that the caller was | |
| 1833 | compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and | |
| 1834 | C<$bitmask> corresponds to | |
| 1835 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and | |
| 1836 | C<$bitmask> values are subject to change between versions of Perl, and | |
| 1837 | are not meant for external use. | |
| 1838 | 1155 | |
| 1839 | 1156 | =end original |
| 1840 | 1157 | |
| 1841 | ||
| 1158 | もしフレームがサブルーチン呼び出しではなく C<eval> だった場合、この | |
| 1842 | ||
| 1159 | $subroutine は C<(eval)> になります。 | |
| 1843 | フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この | |
| 1844 | $subroutine は C<(eval)> になることに注意してください。 | |
| 1845 | 1160 | この場合、追加の要素である $evaltext と C<$is_require> がセットされます: |
| 1846 | C<$is_require> はフレームが | |
| 1161 | C<$is_require> はフレームが C<require> または C<use> で作られた場合に | |
| 1847 | ||
| 1162 | 真になり、$evaltext は C<eval EXPR> のテキストが入ります。 | |
| 1848 | ||
| 1163 | 特に、C<eval BLOCK> の場合、$filename は C<(eval)> になりますが、 | |
| 1849 | 特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、 | |
| 1850 | 1164 | $evaltext は未定義値になります。 |
| 1851 | (それぞれの | |
| 1165 | (それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに | |
| 1852 | ||
| 1166 | 注意してください。) | |
| 1853 | $s | |
| 1167 | C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に真となります。 | |
| 1854 | C<(unknown)> になります。 | |
| 1855 | C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が | |
| 1856 | 設定された場合に真となります。 | |
| 1857 | 1168 | C<$hints> と C<$bitmask> は caller がコンパイルされたときの |
| 1858 | 1169 | 実際的なヒントを含みます。 |
| 1859 | C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は | |
| 1860 | L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に | |
| 1861 | 対応します。 | |
| 1862 | 1170 | C<$hints> は C<$bitmask> は Perl のバージョンによって変更される |
| 1863 | 可能性があるので、外部での使用を想定していません。 | |
| 1171 | 可能性があるので、外部での使用を想定していません。 | |
| 1864 | 1172 | |
| 1865 | 1173 | =begin original |
| 1866 | 1174 | |
| 1867 | ||
| 1175 | Furthermore, when called from within the DB package, caller returns more | |
| 1868 | L<C<%^H>|perlvar/%^H> when the caller was compiled, or | |
| 1869 | L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not | |
| 1870 | modify the values of this hash, as they are the actual values stored in | |
| 1871 | the optree. | |
| 1872 | ||
| 1873 | =end original | |
| 1874 | ||
| 1875 | C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を | |
| 1876 | 含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は | |
| 1877 | L<C<undef>|/undef EXPR> です。 | |
| 1878 | このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。 | |
| 1879 | ||
| 1880 | =begin original | |
| 1881 | ||
| 1882 | Furthermore, when called from within the DB package in | |
| 1883 | list context, and with an argument, caller returns more | |
| 1884 | 1176 | detailed information: it sets the list variable C<@DB::args> to be the |
| 1885 | 1177 | arguments with which the subroutine was invoked. |
| 1886 | 1178 | |
| 1887 | 1179 | =end original |
| 1888 | 1180 | |
| 1889 | さらに、DB パッケージの中から | |
| 1181 | さらに、DB パッケージの中から呼ばれた場合は、caller は | |
| 1890 | ||
| 1182 | より詳細な情報を返します。 | |
| 1891 | 変数 C<@DB::args> に設定します。 | |
| 1183 | サブルーチンが起動されたときの引数を変数 C<@DB::args> に設定します。 | |
| 1892 | 1184 | |
| 1893 | 1185 | =begin original |
| 1894 | 1186 | |
| 1895 | 1187 | Be aware that the optimizer might have optimized call frames away before |
| 1896 | ||
| 1188 | C<caller> had a chance to get the information. That means that C<caller(N)> | |
| 1897 | m | |
| 1189 | might not return information about the call frame you expect it do, for | |
| 1898 | ||
| 1190 | C<< N > 1 >>. In particular, C<@DB::args> might have information from the | |
| 1899 | ||
| 1191 | previous time C<caller> was called. | |
| 1900 | was called. | |
| 1901 | 1192 | |
| 1902 | 1193 | =end original |
| 1903 | 1194 | |
| 1904 | ||
| 1195 | C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して | |
| 1905 | ||
| 1196 | しまうかもしれないことに注意してください。 | |
| 1906 | 1197 | これは、C<caller(N)> が C<< N > 1 >> のとき、 |
| 1907 | 1198 | あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。 |
| 1908 | 特に、C<@DB::args> は | |
| 1199 | 特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を | |
| 1909 | 1200 | 持っているかもしれません。 |
| 1910 | 1201 | |
| 1911 | =begin original | |
| 1912 | ||
| 1913 | Be aware that setting C<@DB::args> is I<best effort>, intended for | |
| 1914 | debugging or generating backtraces, and should not be relied upon. In | |
| 1915 | particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's | |
| 1916 | arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so | |
| 1917 | C<@DB::args> will contain modifications the subroutine makes to | |
| 1918 | L<C<@_>|perlvar/@_> or its contents, not the original values at call | |
| 1919 | time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit | |
| 1920 | references to its elements, so under certain cases its elements may have | |
| 1921 | become freed and reallocated for other variables or temporary values. | |
| 1922 | Finally, a side effect of the current implementation is that the effects | |
| 1923 | of C<shift @_> can I<normally> be undone (but not C<pop @_> or other | |
| 1924 | splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been | |
| 1925 | taken, I<and> subject to the caveat about reallocated elements), so | |
| 1926 | C<@DB::args> is actually a hybrid of the current state and initial state | |
| 1927 | of L<C<@_>|perlvar/@_>. Buyer beware. | |
| 1928 | ||
| 1929 | =end original | |
| 1930 | ||
| 1931 | C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの | |
| 1932 | 生成を目的としていて、これに依存するべきではないということにも | |
| 1933 | 注意してください。 | |
| 1934 | 特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、 | |
| 1935 | Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は | |
| 1936 | サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、 | |
| 1937 | 呼び出し時の元の値ではありません。 | |
| 1938 | C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な | |
| 1939 | リファレンスを保持しないので、ある種の状況では、解放されて他の変数や | |
| 1940 | 一時的な値のために再割り当てされているかもしれません。 | |
| 1941 | 最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない | |
| 1942 | (しかし C<pop @_> やその他の splice は違い、I<そして> もし | |
| 1943 | L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた | |
| 1944 | 要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の | |
| 1945 | 状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。 | |
| 1946 | ご用心を。 | |
| 1947 | ||
| 1948 | 1202 | =item chdir EXPR |
| 1949 | X<chdir> | |
| 1950 | X<cd> | |
| 1951 | X<directory, change> | |
| 1952 | 1203 | |
| 1953 | =item chdir FILEHANDLE | |
| 1954 | ||
| 1955 | =item chdir DIRHANDLE | |
| 1956 | ||
| 1957 | =item chdir | |
| 1958 | ||
| 1959 | =for Pod::Functions change your current working directory | |
| 1960 | ||
| 1961 | 1204 | =begin original |
| 1962 | 1205 | |
| 1963 | 1206 | Changes the working directory to EXPR, if possible. If EXPR is omitted, |
| 1964 | 1207 | changes to the directory specified by C<$ENV{HOME}>, if set; if not, |
| 1965 | changes to the directory specified by C<$ENV{LOGDIR}>. | |
| 1208 | changes to the directory specified by C<$ENV{LOGDIR}>. If neither is | |
| 1966 | ||
| 1209 | set, C<chdir> does nothing. It returns true upon success, false | |
| 1967 | ||
| 1210 | otherwise. See the example under C<die>. | |
| 1968 | returns true on success, false otherwise. See the example under | |
| 1969 | L<C<die>|/die LIST>. | |
| 1970 | 1211 | |
| 1971 | 1212 | =end original |
| 1972 | 1213 | |
| 1973 | 1214 | (可能であれば、) カレントディレクトリを EXPR に移します。 |
| 1974 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、 | |
| 1215 | EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、 | |
| 1975 | ||
| 1216 | そのディレクトリに移ります。 | |
| 1976 | 移ります。 | |
| 1217 | そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに移ります。 | |
| 1977 | ||
| 1218 | どちらも設定されていなければ、C<chdir> は何もしません。 | |
| 1978 | 使われます。) | |
| 1979 | どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。 | |
| 1980 | 1219 | 成功時には真を返し、そうでなければ偽を返します。 |
| 1981 | ||
| 1220 | C<die> の項の例を参照してください。 | |
| 1982 | 1221 | |
| 1983 | =begin original | |
| 1984 | ||
| 1985 | On systems that support L<fchdir(2)>, you may pass a filehandle or | |
| 1986 | directory handle as the argument. On systems that don't support L<fchdir(2)>, | |
| 1987 | passing handles raises an exception. | |
| 1988 | ||
| 1989 | =end original | |
| 1990 | ||
| 1991 | L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや | |
| 1992 | ディレクトリハンドルを引数として渡せます。 | |
| 1993 | L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。 | |
| 1994 | ||
| 1995 | 1222 | =item chmod LIST |
| 1996 | X<chmod> X<permission> X<mode> | |
| 1997 | 1223 | |
| 1998 | =for Pod::Functions changes the permissions on a list of files | |
| 1999 | ||
| 2000 | 1224 | =begin original |
| 2001 | 1225 | |
| 2002 | 1226 | Changes the permissions of a list of files. The first element of the |
| 2003 | list must be the numeric mode, which should probably be an octal | |
| 1227 | list must be the numerical mode, which should probably be an octal | |
| 2004 | number, and which definitely should I<not> | |
| 1228 | number, and which definitely should I<not> a string of octal digits: | |
| 2005 | C<0644> is okay, | |
| 1229 | C<0644> is okay, C<'0644'> is not. Returns the number of files | |
| 2006 | successfully changed. See also L< | |
| 1230 | successfully changed. See also L</oct>, if all you have is a string. | |
| 2007 | string. | |
| 2008 | 1231 | |
| 2009 | 1232 | =end original |
| 2010 | 1233 | |
| 2011 | 1234 | LIST に含まれるファイルの、パーミッションを変更します。 |
| 2012 | LIST の最初の要素は、数値表現のモードでなければなりません | |
| 1235 | LIST の最初の要素は、数値表現のモードでなければなりません。 | |
| 2013 | 恐らく 8 進表記の数であるべきでしょう | |
| 1236 | 恐らく 8 進表記の数であるべきでしょう。しかし、8 進表記のC<文字列ではいけません>。 | |
| 2014 | ||
| 1237 | C<0644> は OK ですが、 C<'0644'> はだめ、ということです。 | |
| 2015 | だめ、ということです。 | |
| 2016 | 1238 | 変更に成功したファイルの数を返します。 |
| 2017 | 文字列を使いたい場合は、L< | |
| 1239 | 文字列を使いたい場合は、L</oct> を参照してください。 | |
| 2018 | 1240 | |
| 2019 | | |
| 1241 | $cnt = chmod 0755, 'foo', 'bar'; | |
| 2020 | 1242 | chmod 0755, @executables; |
| 2021 | | |
| 1243 | $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to | |
| 2022 | | |
| 1244 | # --w----r-T | |
| 2023 | | |
| 1245 | $mode = '0644'; chmod oct($mode), 'foo'; # this is better | |
| 2024 | | |
| 1246 | $mode = 0644; chmod $mode, 'foo'; # this is best | |
| 2025 | 1247 | |
| 2026 | 1248 | =begin original |
| 2027 | 1249 | |
| 2028 | ||
| 1250 | You can also import the symbolic C<S_I*> constants from the Fcntl | |
| 2029 | ||
| 1251 | module: | |
| 2030 | an exception. Filehandles must be passed as globs or glob references to be | |
| 2031 | recognized; barewords are considered filenames. | |
| 2032 | 1252 | |
| 2033 | 1253 | =end original |
| 2034 | 1254 | |
| 2035 | ||
| 1255 | シンボリックな C<S_I*> 定数を Fcntl モジュールからインポートすることもできます。 | |
| 2036 | 渡せます。 | |
| 2037 | L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 2038 | 例外が発生します。 | |
| 2039 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして | |
| 2040 | 渡されなければなりません; | |
| 2041 | 裸の単語はファイル名として扱われます。 | |
| 2042 | 1256 | |
| 2043 | | |
| 1257 | use Fcntl ':mode'; | |
| 2044 | my $perm = (stat $fh)[2] & 07777; | |
| 2045 | chmod($perm | 0600, $fh); | |
| 2046 | 1258 | |
| 2047 | =begin original | |
| 2048 | ||
| 2049 | You can also import the symbolic C<S_I*> constants from the | |
| 2050 | L<C<Fcntl>|Fcntl> module: | |
| 2051 | ||
| 2052 | =end original | |
| 2053 | ||
| 2054 | L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を | |
| 2055 | インポートすることもできます: | |
| 2056 | ||
| 2057 | use Fcntl qw( :mode ); | |
| 2058 | 1259 | chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; |
| 2059 | # | |
| 1260 | # This is identical to the chmod 0755 of the above example. | |
| 2060 | 1261 | |
| 2061 | =begin original | |
| 2062 | ||
| 2063 | Portability issues: L<perlport/chmod>. | |
| 2064 | ||
| 2065 | =end original | |
| 2066 | ||
| 2067 | 移植性の問題: L<perlport/chmod>。 | |
| 2068 | ||
| 2069 | 1262 | =item chomp VARIABLE |
| 2070 | X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol> | |
| 2071 | 1263 | |
| 2072 | =item chomp | |
| 1264 | =item chomp LIST | |
| 2073 | 1265 | |
| 2074 | 1266 | =item chomp |
| 2075 | 1267 | |
| 2076 | =for Pod::Functions remove a trailing record separator from a string | |
| 2077 | ||
| 2078 | 1268 | =begin original |
| 2079 | 1269 | |
| 2080 | This safer version of L< | |
| 1270 | This safer version of L</chop> removes any trailing string | |
| 2081 | ||
| 1271 | that corresponds to the current value of C<$/> (also known as | |
| 2082 | ||
| 1272 | $INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total | |
| 2083 | in the L<C<English>|English> module). It returns the total | |
| 2084 | 1273 | number of characters removed from all its arguments. It's often used to |
| 2085 | 1274 | remove the newline from the end of an input record when you're worried |
| 2086 | 1275 | that the final record may be missing its newline. When in paragraph |
| 2087 | mode (C<$/ = | |
| 1276 | mode (C<$/ = "">), it removes all trailing newlines from the string. | |
| 2088 | When in slurp mode (C<$/ = undef>) or fixed-length record mode | |
| 1277 | When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is | |
| 2089 | ||
| 1278 | a reference to an integer or the like, see L<perlvar>) chomp() won't | |
| 2090 | ||
| 1279 | remove anything. | |
| 2091 | If VARIABLE is omitted, it chomps | |
| 1280 | If VARIABLE is omitted, it chomps C<$_>. Example: | |
| 2092 | 1281 | |
| 2093 | 1282 | =end original |
| 2094 | 1283 | |
| 2095 | より安全な | |
| 1284 | より安全な C<chop> (以下を参照してください) です。 | |
| 2096 | ||
| 1285 | C<$/> (C<English> モジュールでは、$INPUT_RECORD_SEPARATOR | |
| 2097 | ||
| 1286 | とも言う) のその時点の値に対応する行末文字を削除します。 | |
| 2098 | 値に対応する行末文字を削除します。 | |
| 2099 | 1287 | 全ての引数から削除した文字数の合計を返します。 |
| 2100 | 1288 | 入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が |
| 2101 | 1289 | 入っているのかわからないような場合に、使用できます。 |
| 2102 | 段落モード (C<$/ = | |
| 1290 | 段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。 | |
| 2103 | 1291 | 吸い込みモード (C<$/ = undef>) や 固定長レコードモード |
| 2104 | ( | |
| 1292 | (C<$/> が整数へのリファレンスや類似のものの場合。L<perlvar>を参照してください) | |
| 2105 | ||
| 1293 | では、chomp() は何も取り除きません。 | |
| 2106 | ||
| 1294 | VARIABLE が省略されると、$_ を対象として chomp します。 | |
| 2107 | VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。 | |
| 2108 | 1295 | 例: |
| 2109 | 1296 | |
| 1297 | =begin original | |
| 1298 | ||
| 2110 | 1299 | while (<>) { |
| 2111 | ||
| 1300 | chomp; # avoid \n on last field | |
| 2112 | ||
| 1301 | @array = split(/:/); | |
| 2113 | ||
| 1302 | # ... | |
| 2114 | 1303 | } |
| 2115 | 1304 | |
| 1305 | =end original | |
| 1306 | ||
| 1307 | while (<>) { | |
| 1308 | chomp; # 最後のフィールドの \n を避ける | |
| 1309 | @array = split(/:/); | |
| 1310 | #... | |
| 1311 | } | |
| 1312 | ||
| 2116 | 1313 | =begin original |
| 2117 | 1314 | |
| 2118 | If VARIABLE is a hash, it chomps the hash's values, but not its keys | |
| 1315 | If VARIABLE is a hash, it chomps the hash's values, but not its keys. | |
| 2119 | resetting the L<C<each>|/each HASH> iterator in the process. | |
| 2120 | 1316 | |
| 2121 | 1317 | =end original |
| 2122 | 1318 | |
| 2123 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し | |
| 1319 | VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。 | |
| 2124 | このプロセスの L<C<each>|/each HASH> 反復子をリセットします。 | |
| 2125 | 1320 | |
| 2126 | 1321 | =begin original |
| 2127 | 1322 | |
| 2128 | 1323 | You can actually chomp anything that's an lvalue, including an assignment: |
| 2129 | 1324 | |
| 2130 | 1325 | =end original |
| 2131 | 1326 | |
| 2132 | 1327 | 左辺値であれば、代入を含めて、任意のものを chomp できます: |
| 2133 | 1328 | |
| 2134 | chomp( | |
| 1329 | chomp($cwd = `pwd`); | |
| 2135 | chomp( | |
| 1330 | chomp($answer = <STDIN>); | |
| 2136 | 1331 | |
| 2137 | 1332 | =begin original |
| 2138 | 1333 | |
| 2139 | 1334 | If you chomp a list, each element is chomped, and the total number of |
| 2140 | 1335 | characters removed is returned. |
| 2141 | 1336 | |
| 2142 | 1337 | =end original |
| 2143 | 1338 | |
| 2144 | 1339 | リストを chomp すると、個々の要素が chomp され、 |
| 2145 | 1340 | 削除された文字数の合計が返されます。 |
| 2146 | 1341 | |
| 2147 | =begin original | |
| 2148 | ||
| 2149 | Note that parentheses are necessary when you're chomping anything | |
| 2150 | that is not a simple variable. This is because C<chomp $cwd = `pwd`;> | |
| 2151 | is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as | |
| 2152 | C<chomp( $cwd = `pwd` )> which you might expect. Similarly, | |
| 2153 | C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than | |
| 2154 | as C<chomp($a, $b)>. | |
| 2155 | ||
| 2156 | =end original | |
| 2157 | ||
| 2158 | 単純な変数以外のものを chomp する場合はかっこが必要であることに | |
| 2159 | 注意してください。 | |
| 2160 | これは、C<chomp $cwd = `pwd`;> は、予測している | |
| 2161 | C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と | |
| 2162 | 解釈されるからです。 | |
| 2163 | 同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b> | |
| 2164 | と解釈されます。 | |
| 2165 | ||
| 2166 | 1342 | =item chop VARIABLE |
| 2167 | X<chop> | |
| 2168 | 1343 | |
| 2169 | =item chop | |
| 1344 | =item chop LIST | |
| 2170 | 1345 | |
| 2171 | 1346 | =item chop |
| 2172 | 1347 | |
| 2173 | =for Pod::Functions remove the last character from a string | |
| 2174 | ||
| 2175 | 1348 | =begin original |
| 2176 | 1349 | |
| 2177 | 1350 | Chops off the last character of a string and returns the character |
| 2178 | 1351 | chopped. It is much more efficient than C<s/.$//s> because it neither |
| 2179 | scans nor copies the string. If VARIABLE is omitted, chops | |
| 1352 | scans nor copies the string. If VARIABLE is omitted, chops C<$_>. | |
| 2180 | L | |
| 1353 | If VARIABLE is a hash, it chops the hash's values, but not its keys. | |
| 2181 | If VARIABLE is a hash, it chops the hash's values, but not its keys, | |
| 2182 | resetting the L<C<each>|/each HASH> iterator in the process. | |
| 2183 | 1354 | |
| 2184 | 1355 | =end original |
| 2185 | 1356 | |
| 2186 | 1357 | 文字列の最後の文字を切り捨てて、その切り取った文字を返します。 |
| 2187 | 1358 | 文字列の検索もコピーも行ないませんので |
| 2188 | 1359 | C<s/.$//s> よりも、ずっと効率的です。 |
| 2189 | VARIABLE が省略されると、 | |
| 1360 | VARIABLE が省略されると、C<$_> を対象として chop します。 | |
| 2190 | VARIABLE がハッシュの場合、ハッシュの | |
| 1361 | VARIABLE がハッシュの場合、ハッシュの value を chop しますが、 | |
| 2191 | ||
| 1362 | key は chop しません。 | |
| 2192 | 1363 | |
| 2193 | 1364 | =begin original |
| 2194 | 1365 | |
| 2195 | 1366 | You can actually chop anything that's an lvalue, including an assignment. |
| 2196 | 1367 | |
| 2197 | 1368 | =end original |
| 2198 | 1369 | |
| 2199 | 1370 | 実際のところ、代入を含む左辺値となりうるなんでも chop できます。 |
| 2200 | 1371 | |
| 2201 | 1372 | =begin original |
| 2202 | 1373 | |
| 2203 | 1374 | If you chop a list, each element is chopped. Only the value of the |
| 2204 | last | |
| 1375 | last C<chop> is returned. | |
| 2205 | 1376 | |
| 2206 | 1377 | =end original |
| 2207 | 1378 | |
| 2208 | 1379 | リストを chop すると、個々の要素が chop されます。 |
| 2209 | 最後の | |
| 1380 | 最後の C<chop> の値だけが返されます。 | |
| 2210 | 1381 | |
| 2211 | 1382 | =begin original |
| 2212 | 1383 | |
| 2213 | Note that | |
| 1384 | Note that C<chop> returns the last character. To return all but the last | |
| 2214 | ||
| 1385 | character, use C<substr($string, 0, -1)>. | |
| 2215 | 1386 | |
| 2216 | 1387 | =end original |
| 2217 | 1388 | |
| 2218 | ||
| 1389 | C<chop> は最後の文字を返すことに注意してください。 | |
| 2219 | 1390 | 最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を |
| 2220 | 1391 | 使ってください。 |
| 2221 | 1392 | |
| 2222 | =begin original | |
| 2223 | ||
| 2224 | See also L<C<chomp>|/chomp VARIABLE>. | |
| 2225 | ||
| 2226 | =end original | |
| 2227 | ||
| 2228 | L<C<chomp>|/chomp VARIABLE> も参照してください。 | |
| 2229 | ||
| 2230 | 1393 | =item chown LIST |
| 2231 | X<chown> X<owner> X<user> X<group> | |
| 2232 | 1394 | |
| 2233 | =for Pod::Functions change the ownership on a list of files | |
| 2234 | ||
| 2235 | 1395 | =begin original |
| 2236 | 1396 | |
| 2237 | 1397 | Changes the owner (and group) of a list of files. The first two |
| 2238 | 1398 | elements of the list must be the I<numeric> uid and gid, in that |
| 2239 | 1399 | order. A value of -1 in either position is interpreted by most |
| 2240 | 1400 | systems to leave that value unchanged. Returns the number of files |
| 2241 | 1401 | successfully changed. |
| 2242 | 1402 | |
| 2243 | 1403 | =end original |
| 2244 | 1404 | |
| 2245 | 1405 | LIST に含まれるファイルの所有者 (とグループ) を変更します。 |
| 2246 | LIST の最初の | |
| 1406 | LIST の最初の 2 つの要素には、I<数値表現> の uid と gid を | |
| 2247 | 1407 | この順序で与えなければなりません。 |
| 2248 | 1408 | どちらかの値を -1 にすると、ほとんどのシステムではその値は |
| 2249 | 1409 | 変更しないと解釈します。 |
| 2250 | 変更に成功したファイルの数 | |
| 1410 | 変更に成功したファイルの数が返されます。 | |
| 2251 | 1411 | |
| 2252 | | |
| 1412 | $cnt = chown $uid, $gid, 'foo', 'bar'; | |
| 2253 | 1413 | chown $uid, $gid, @filenames; |
| 2254 | 1414 | |
| 2255 | 1415 | =begin original |
| 2256 | 1416 | |
| 2257 | On systems that support L<fchown(2)>, you may pass filehandles among the | |
| 2258 | files. On systems that don't support L<fchown(2)>, passing filehandles raises | |
| 2259 | an exception. Filehandles must be passed as globs or glob references to be | |
| 2260 | recognized; barewords are considered filenames. | |
| 2261 | ||
| 2262 | =end original | |
| 2263 | ||
| 2264 | L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。 | |
| 2265 | L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 2266 | 例外が発生します。 | |
| 2267 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして | |
| 2268 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 | |
| 2269 | ||
| 2270 | =begin original | |
| 2271 | ||
| 2272 | 1417 | Here's an example that looks up nonnumeric uids in the passwd file: |
| 2273 | 1418 | |
| 2274 | 1419 | =end original |
| 2275 | 1420 | |
| 2276 | 1421 | passwd ファイルから数値表現でない uid を検索する例を |
| 2277 | 1422 | 示します: |
| 2278 | 1423 | |
| 2279 | 1424 | print "User: "; |
| 2280 | chomp( | |
| 1425 | chomp($user = <STDIN>); | |
| 2281 | 1426 | print "Files: "; |
| 2282 | chomp( | |
| 1427 | chomp($pattern = <STDIN>); | |
| 2283 | 1428 | |
| 2284 | | |
| 1429 | ($login,$pass,$uid,$gid) = getpwnam($user) | |
| 2285 | ||
| 1430 | or die "$user not in passwd file"; | |
| 2286 | 1431 | |
| 2287 | | |
| 1432 | @ary = glob($pattern); # expand filenames | |
| 2288 | 1433 | chown $uid, $gid, @ary; |
| 2289 | 1434 | |
| 2290 | 1435 | =begin original |
| 2291 | 1436 | |
| 2292 | 1437 | On most systems, you are not allowed to change the ownership of the |
| 2293 | 1438 | file unless you're the superuser, although you should be able to change |
| 2294 | 1439 | the group to any of your secondary groups. On insecure systems, these |
| 2295 | 1440 | restrictions may be relaxed, but this is not a portable assumption. |
| 2296 | 1441 | On POSIX systems, you can detect this condition this way: |
| 2297 | 1442 | |
| 2298 | 1443 | =end original |
| 2299 | 1444 | |
| 2300 | 1445 | ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を |
| 2301 | 1446 | 変更できますが、グループは実行者の副グループに変更できるべきです。 |
| 2302 | 安全でないシステムでは、この制限はゆるめられています | |
| 1447 | 安全でないシステムでは、この制限はゆるめられています。 | |
| 2303 | 移植性のある仮定ではありません。 | |
| 1448 | しかしこれは移植性のある仮定ではありません。 | |
| 2304 | 1449 | POSIX システムでは、以下のようにしてこの条件を検出できます: |
| 2305 | 1450 | |
| 2306 | 1451 | use POSIX qw(sysconf _PC_CHOWN_RESTRICTED); |
| 2307 | | |
| 1452 | $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED); | |
| 2308 | 1453 | |
| 2309 | =begin original | |
| 2310 | ||
| 2311 | Portability issues: L<perlport/chown>. | |
| 2312 | ||
| 2313 | =end original | |
| 2314 | ||
| 2315 | 移植性の問題: L<perlport/chown>。 | |
| 2316 | ||
| 2317 | 1454 | =item chr NUMBER |
| 2318 | X<chr> X<character> X<ASCII> X<Unicode> | |
| 2319 | 1455 | |
| 2320 | 1456 | =item chr |
| 2321 | 1457 | |
| 2322 | =for Pod::Functions get character this number represents | |
| 2323 | ||
| 2324 | 1458 | =begin original |
| 2325 | 1459 | |
| 2326 | 1460 | Returns the character represented by that NUMBER in the character set. |
| 2327 | 1461 | For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and |
| 2328 | chr(0x263a) is a Unicode smiley face | |
| 1462 | chr(0x263a) is a Unicode smiley face (but only within the scope of | |
| 1463 | a C<use utf8>). For the reverse, use L</ord>. | |
| 1464 | See L<utf8> for more about Unicode. | |
| 2329 | 1465 | |
| 2330 | 1466 | =end original |
| 2331 | 1467 | |
| 2332 | 1468 | 特定の文字セットでの NUMBER で表わされる文字を返します。 |
| 2333 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります | |
| 1469 | たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります。 | |
| 2334 | chr(0x263a) は Unicode のスマイリーフェイスです | |
| 1470 | chr(0x263a) は Unicode のスマイリーフェイスです | |
| 1471 | (ただし C<use utf8> のスコープ内のみです)。 | |
| 1472 | 逆を行うためには、L</ord> を参照してください。 | |
| 1473 | Unicode についてもっと知りたいなら、L<utf8> を参照してください。 | |
| 2335 | 1474 | |
| 2336 | 1475 | =begin original |
| 2337 | 1476 | |
| 2338 | N | |
| 1477 | If NUMBER is omitted, uses C<$_>. | |
| 2339 | except under the L<bytes> pragma, where the low eight bits of the value | |
| 2340 | (truncated to an integer) are used. | |
| 2341 | 1478 | |
| 2342 | 1479 | =end original |
| 2343 | 1480 | |
| 2344 | ||
| 1481 | NUMBER が省略された場合、C<$_> を使います。 | |
| 2345 | L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが | |
| 2346 | 使われます。 | |
| 2347 | 1482 | |
| 2348 | =begin original | |
| 2349 | ||
| 2350 | If NUMBER is omitted, uses L<C<$_>|perlvar/$_>. | |
| 2351 | ||
| 2352 | =end original | |
| 2353 | ||
| 2354 | NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。 | |
| 2355 | ||
| 2356 | =begin original | |
| 2357 | ||
| 2358 | For the reverse, use L<C<ord>|/ord EXPR>. | |
| 2359 | ||
| 2360 | =end original | |
| 2361 | ||
| 2362 | 逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。 | |
| 2363 | ||
| 2364 | =begin original | |
| 2365 | ||
| 2366 | Note that characters from 128 to 255 (inclusive) are by default | |
| 2367 | internally not encoded as UTF-8 for backward compatibility reasons. | |
| 2368 | ||
| 2369 | =end original | |
| 2370 | ||
| 2371 | 128 から 255 までの文字は過去との互換性のために | |
| 2372 | デフォルトでは UTF-8 Unicode にエンコードされません。 | |
| 2373 | ||
| 2374 | =begin original | |
| 2375 | ||
| 2376 | See L<perlunicode> for more about Unicode. | |
| 2377 | ||
| 2378 | =end original | |
| 2379 | ||
| 2380 | Unicode については L<perlunicode> を参照してください。 | |
| 2381 | ||
| 2382 | 1483 | =item chroot FILENAME |
| 2383 | X<chroot> X<root> | |
| 2384 | 1484 | |
| 2385 | 1485 | =item chroot |
| 2386 | 1486 | |
| 2387 | =for Pod::Functions make directory new root for path lookups | |
| 2388 | ||
| 2389 | 1487 | =begin original |
| 2390 | 1488 | |
| 2391 | 1489 | This function works like the system call by the same name: it makes the |
| 2392 | 1490 | named directory the new root directory for all further pathnames that |
| 2393 | 1491 | begin with a C</> by your process and all its children. (It doesn't |
| 2394 | 1492 | change your current working directory, which is unaffected.) For security |
| 2395 | 1493 | reasons, this call is restricted to the superuser. If FILENAME is |
| 2396 | omitted, does a | |
| 1494 | omitted, does a C<chroot> to C<$_>. | |
| 2397 | 1495 | |
| 2398 | 1496 | =end original |
| 2399 | 1497 | |
| 2400 | 同じ名前のシステムコールと同じことをします | |
| 1498 | 同じ名前のシステムコールと同じことをします。 | |
| 2401 | 対して、C</>で始まるパス名に関して | |
| 1499 | 現在のプロセス及び子プロセスに対して、C</>で始まるパス名に関して | |
| 2402 | ルートディレクトリとして扱います。 | |
| 1500 | 指定されたディレクトリを新しいルートディレクトリとして扱います。 | |
| 2403 | (これはカレントディレクトリを変更しません | |
| 1501 | (これはカレントディレクトリを変更しません。カレントディレクトリはそのままです)。 | |
| 2404 | そのままです。) | |
| 2405 | 1502 | セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。 |
| 2406 | FILENAME を省略すると、 | |
| 1503 | FILENAME を省略すると、C<$_> へ C<chroot> します。 | |
| 2407 | L<C<chroot>|/chroot FILENAME> します。 | |
| 2408 | 1504 | |
| 2409 | =begin original | |
| 2410 | ||
| 2411 | B<NOTE:> It is good security practice to do C<chdir("/")> | |
| 2412 | (L<C<chdir>|/chdir EXPR> to the root directory) immediately after a | |
| 2413 | L<C<chroot>|/chroot FILENAME>. | |
| 2414 | ||
| 2415 | =end original | |
| 2416 | ||
| 2417 | B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに | |
| 2418 | L<C<chdir>|/chdir EXPR> する) | |
| 2419 | C<chdir("/")> するのはセキュリティ上の良い習慣です。 | |
| 2420 | ||
| 2421 | =begin original | |
| 2422 | ||
| 2423 | Portability issues: L<perlport/chroot>. | |
| 2424 | ||
| 2425 | =end original | |
| 2426 | ||
| 2427 | 移植性の問題: L<perlport/chroot>。 | |
| 2428 | ||
| 2429 | 1505 | =item close FILEHANDLE |
| 2430 | X<close> | |
| 2431 | 1506 | |
| 2432 | 1507 | =item close |
| 2433 | 1508 | |
| 2434 | =for Pod::Functions close file (or pipe or socket) handle | |
| 2435 | ||
| 2436 | 1509 | =begin original |
| 2437 | 1510 | |
| 2438 | Closes the file or pipe associated with the filehandle, | |
| 1511 | Closes the file or pipe associated with the file handle, returning true | |
| 2439 | buffers | |
| 1512 | only if stdio successfully flushes buffers and closes the system file | |
| 2440 | ||
| 1513 | descriptor. Closes the currently selected filehandle if the argument | |
| 2441 | ||
| 1514 | is omitted. | |
| 2442 | omitted. | |
| 2443 | 1515 | |
| 2444 | 1516 | =end original |
| 2445 | 1517 | |
| 2446 | FILEHANDLE に対応したファイルまたはパイプをクローズし | |
| 1518 | FILEHANDLE に対応したファイルまたはパイプをクローズします。 | |
| 2447 | ||
| 1519 | 標準入出力が正常にバッファのフラッシュを行なって、 | |
| 2448 | ||
| 1520 | ファイル記述子のクローズしたときにのみ「真」を返します。 | |
| 2449 | 1521 | 引数が省略された場合、現在選択されているファイルハンドルをクローズします。 |
| 2450 | 1522 | |
| 2451 | 1523 | =begin original |
| 2452 | 1524 | |
| 2453 | 1525 | You don't have to close FILEHANDLE if you are immediately going to do |
| 2454 | another | |
| 1526 | another C<open> on it, because C<open> will close it for you. (See | |
| 2455 | ||
| 1527 | C<open>.) However, an explicit C<close> on an input file resets the line | |
| 2456 | ||
| 1528 | counter (C<$.>), while the implicit close done by C<open> does not. | |
| 2457 | L<C<close>|/close FILEHANDLE> on an input file resets the line counter | |
| 2458 | (L<C<$.>|perlvar/$.>), while the implicit close done by | |
| 2459 | L<C<open>|/open FILEHANDLE,EXPR> does not. | |
| 2460 | 1529 | |
| 2461 | 1530 | =end original |
| 2462 | 1531 | |
| 2463 | クローズしてすぐにまた、同じファイルハンドルに | |
| 1532 | クローズしてすぐにまた、同じファイルハンドルに | |
| 2464 | 場合には、 | |
| 1533 | 対してオープンを行なう場合には、C<open> が自動的に C<close> | |
| 2465 | ||
| 1534 | を行ないますので、close FILEHANDLE する必要はありません | |
| 2466 | ||
| 1535 | (C<open> を参照してください)。 | |
| 2467 | (L<C<open>|/open FILEHANDLE,EXPR> を参照してください。) | |
| 2468 | 1536 | ただし、明示的にクローズを行なったときにのみ入力ファイルの |
| 2469 | 行番号 ( | |
| 1537 | 行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる | |
| 2470 | ||
| 1538 | 暗黙の C<close>では行なわれません。 | |
| 2471 | 暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。 | |
| 2472 | 1539 | |
| 2473 | 1540 | =begin original |
| 2474 | 1541 | |
| 2475 | If the filehandle came from a piped open | |
| 1542 | If the file handle came from a piped open C<close> will additionally | |
| 2476 | return | |
| 1543 | return false if one of the other system calls involved fails or if the | |
| 2477 | program exits with non-zero status. If the only problem was that the | |
| 1544 | program exits with non-zero status. (If the only problem was that the | |
| 2478 | program exited non-zero | |
| 1545 | program exited non-zero C<$!> will be set to C<0>.) Closing a pipe | |
| 2479 | ||
| 1546 | also waits for the process executing on the pipe to complete, in case you | |
| 2480 | ||
| 1547 | want to look at the output of the pipe afterwards, and | |
| 2481 | implicitly puts the exit status value of that command into | |
| 1548 | implicitly puts the exit status value of that command into C<$?>. | |
| 2482 | L<C<$?>|perlvar/$?> and | |
| 2483 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 2484 | 1549 | |
| 2485 | 1550 | =end original |
| 2486 | 1551 | |
| 2487 | ファイルハンドルがパイプつきオープンなら、 | |
| 1552 | ファイルハンドルがパイプつきオープンなら、 | |
| 2488 | その他のシステムコールが失敗したり | |
| 1553 | C<close> はその他のシステムコールが失敗したり | |
| 2489 | 場合にも偽を返します | |
| 1554 | プログラムが非ゼロのステータスで終了した場合にも偽を返します | |
| 2490 | プログラムが非ゼロで終了しただけの場合は、 | |
| 1555 | (プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます)。 | |
| 2491 | ||
| 1556 | 後でパイプの出力を見たい場合のために、 | |
| 2492 | ||
| 1557 | パイプのクローズでは、パイプ上で実行されている | |
| 2493 | ||
| 1558 | プロセスの完了を待ちます。 | |
| 2494 | ||
| 1559 | また自動的にコマンドのステータス値を C<$?> に設定します。 | |
| 2495 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。 | |
| 2496 | 1560 | |
| 2497 | 1561 | =begin original |
| 2498 | 1562 | |
| 2499 | ||
| 1563 | Prematurely closing the read end of a pipe (i.e. before the process | |
| 2500 | ||
| 1564 | writing to it at the other end has closed it) will result in a | |
| 2501 | ||
| 1565 | SIGPIPE being delivered to the writer. If the other end can't | |
| 2502 | thread. | |
| 1566 | handle that, be sure to read all the data before closing the pipe. | |
| 2503 | 1567 | |
| 2504 | 1568 | =end original |
| 2505 | 1569 | |
| 2506 | ||
| 1570 | 途中で(つまり、書き込み側が閉じる前に) | |
| 2507 | ||
| 1571 | パイプの読み込み側が閉じた場合、 | |
| 2508 | まだ開かれている場合、子プロセスの終了を待たずに真を返します。 | |
| 2509 | ||
| 2510 | =begin original | |
| 2511 | ||
| 2512 | Closing the read end of a pipe before the process writing to it at the | |
| 2513 | other end is done writing results in the writer receiving a SIGPIPE. If | |
| 2514 | the other end can't handle that, be sure to read all the data before | |
| 2515 | closing the pipe. | |
| 2516 | ||
| 2517 | =end original | |
| 2518 | ||
| 2519 | 書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、 | |
| 2520 | 1572 | 書き込み側に SIGPIPE が配送されます。 |
| 2521 | 1573 | 書き込み側がこれを扱えない場合、パイプを閉じる前に |
| 2522 | 1574 | 確実に全てのデータが読み込まれるようにする必要があります。 |
| 2523 | 1575 | |
| 2524 | 1576 | =begin original |
| 2525 | 1577 | |
| 2526 | 1578 | Example: |
| 2527 | 1579 | |
| 2528 | 1580 | =end original |
| 2529 | 1581 | |
| 2530 | 1582 | 例: |
| 2531 | 1583 | |
| 2532 | 1584 | open(OUTPUT, '|sort >foo') # pipe to sort |
| 2533 | 1585 | or die "Can't start sort: $!"; |
| 2534 | #... | |
| 1586 | #... # print stuff to output | |
| 2535 | close OUTPUT | |
| 1587 | close OUTPUT # wait for sort to finish | |
| 2536 | 1588 | or warn $! ? "Error closing sort pipe: $!" |
| 2537 | 1589 | : "Exit status $? from sort"; |
| 2538 | open(INPUT, 'foo') | |
| 1590 | open(INPUT, 'foo') # get sort's results | |
| 2539 | 1591 | or die "Can't open 'foo' for input: $!"; |
| 2540 | 1592 | |
| 2541 | 1593 | =begin original |
| 2542 | 1594 | |
| 2543 | 1595 | FILEHANDLE may be an expression whose value can be used as an indirect |
| 2544 | filehandle, usually the real filehandle name | |
| 1596 | filehandle, usually the real filehandle name. | |
| 2545 | 1597 | |
| 2546 | 1598 | =end original |
| 2547 | 1599 | |
| 2548 | FILEHANDLE は式でもかまいません | |
| 1600 | FILEHANDLE は式でもかまいません。この場合、値は間接ファイルハンドルと | |
| 2549 | して扱われ、普通は実際のファイルハンドル名 | |
| 1601 | して扱われ、普通は実際のファイルハンドル名です。 | |
| 2550 | 1602 | |
| 2551 | 1603 | =item closedir DIRHANDLE |
| 2552 | X<closedir> | |
| 2553 | 1604 | |
| 2554 | =for Pod::Functions close directory handle | |
| 2555 | ||
| 2556 | 1605 | =begin original |
| 2557 | 1606 | |
| 2558 | Closes a directory opened by | |
| 1607 | Closes a directory opened by C<opendir> and returns the success of that | |
| 2559 | ||
| 1608 | system call. | |
| 2560 | 1609 | |
| 2561 | 1610 | =end original |
| 2562 | 1611 | |
| 2563 | ||
| 1612 | C<opendir> でオープンしたディレクトリをクローズし、 | |
| 2564 | 1613 | システムコールの返り値を返します。 |
| 2565 | 1614 | |
| 2566 | = | |
| 1615 | =begin original | |
| 2567 | X<connect> | |
| 2568 | 1616 | |
| 2569 | ||
| 1617 | DIRHANDLE may be an expression whose value can be used as an indirect | |
| 1618 | dirhandle, usually the real dirhandle name. | |
| 2570 | 1619 | |
| 1620 | =end original | |
| 1621 | ||
| 1622 | DIRHANDLE は式でもかまいません。この場合、値は相対ディレクトリハンドルと | |
| 1623 | して扱われ、普通は実際のディレクトリハンドル名です。 | |
| 1624 | ||
| 1625 | =item connect SOCKET,NAME | |
| 1626 | ||
| 2571 | 1627 | =begin original |
| 2572 | 1628 | |
| 2573 | Attempts to connect to a remote socket, just | |
| 1629 | Attempts to connect to a remote socket, just as the connect system call | |
| 2574 | Returns true if it succeeded, false otherwise. NAME should be a | |
| 1630 | does. Returns true if it succeeded, false otherwise. NAME should be a | |
| 2575 | 1631 | packed address of the appropriate type for the socket. See the examples in |
| 2576 | 1632 | L<perlipc/"Sockets: Client/Server Communication">. |
| 2577 | 1633 | |
| 2578 | 1634 | =end original |
| 2579 | 1635 | |
| 2580 | ||
| 1636 | connect(2) システムコールと同様に、リモートソケットへの接続を試みます。 | |
| 2581 | 成功時には真を、 | |
| 1637 | 成功時には真を返し、失敗時には偽を返します。 | |
| 2582 | 1638 | NAME は、ソケットに対する、適切な型のパックされた |
| 2583 | 1639 | アドレスでなければなりません。 |
| 2584 | 1640 | L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。 |
| 2585 | 1641 | |
| 2586 | 1642 | =item continue BLOCK |
| 2587 | X<continue> | |
| 2588 | 1643 | |
| 2589 | =item continue | |
| 2590 | ||
| 2591 | =for Pod::Functions optional trailing block in a while or foreach | |
| 2592 | ||
| 2593 | 1644 | =begin original |
| 2594 | 1645 | |
| 2595 | ||
| 1646 | Actually a flow control statement rather than a function. If there is a | |
| 2596 | ||
| 1647 | C<continue> BLOCK attached to a BLOCK (typically in a C<while> or | |
| 2597 | ||
| 1648 | C<foreach>), it is always executed just before the conditional is about to | |
| 2598 | ||
| 1649 | be evaluated again, just like the third part of a C<for> loop in C. Thus | |
| 2599 | ||
| 1650 | it can be used to increment a loop variable, even when the loop has been | |
| 2600 | ||
| 1651 | continued via the C<next> statement (which is similar to the C C<continue> | |
| 2601 | even when the loop has been continued via the L<C<next>|/next LABEL> | |
| 2602 | statement (which is similar to the C L<C<continue>|/continue BLOCK> | |
| 2603 | 1652 | statement). |
| 2604 | 1653 | |
| 2605 | 1654 | =end original |
| 2606 | 1655 | |
| 2607 | ||
| 1656 | 実際には関数ではなく、実行制御文です。 | |
| 2608 | ||
| 1657 | C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、 | |
| 2609 | ||
| 1658 | これは条件文が再評価される直前に常に実行されます。 | |
| 2610 | C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます; | |
| 2611 | 1659 | これは C における C<for> ループの 3 番目の部分と同様です。 |
| 2612 | 従って、これは | |
| 1660 | 従って、これは C<next> 文 | |
| 2613 | ||
| 1661 | (これは C の C<continue> 文と似ています)を使ってループが繰り返されるときでも | |
| 2614 | ループ | |
| 1662 | ループ変数を増やしたいときに使えます。 | |
| 2615 | 1663 | |
| 2616 | 1664 | =begin original |
| 2617 | 1665 | |
| 2618 | ||
| 1666 | C<last>, C<next>, or C<redo> may appear within a C<continue> | |
| 2619 | ||
| 1667 | block. C<last> and C<redo> will behave as if they had been executed within | |
| 2620 | ||
| 1668 | the main block. So will C<next>, but since it will execute a C<continue> | |
| 2621 | ||
| 1669 | block, it may be more entertaining. | |
| 2622 | main block. So will L<C<next>|/next LABEL>, but since it will execute a | |
| 2623 | L<C<continue>|/continue BLOCK> block, it may be more entertaining. | |
| 2624 | 1670 | |
| 2625 | 1671 | =end original |
| 2626 | 1672 | |
| 2627 | ||
| 1673 | C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性があります。 | |
| 2628 | ||
| 1674 | C<last> と C<redo> はメインブロックの中で実行されたのと同じように振舞います。 | |
| 2629 | ||
| 1675 | C<next> の場合は、C<continue> ブロックを実行することになるので、 | |
| 2630 | ||
| 1676 | より面白いことになります。 | |
| 2631 | L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを | |
| 2632 | 実行することになるので、より面白いことになります。 | |
| 2633 | 1677 | |
| 2634 | 1678 | while (EXPR) { |
| 2635 | ||
| 1679 | ### redo always comes here | |
| 2636 | ||
| 1680 | do_something; | |
| 2637 | 1681 | } continue { |
| 2638 | ||
| 1682 | ### next always comes here | |
| 2639 | ||
| 1683 | do_something_else; | |
| 2640 | ||
| 1684 | # then back the top to re-check EXPR | |
| 2641 | 1685 | } |
| 2642 | 1686 | ### last always comes here |
| 2643 | 1687 | |
| 2644 | 1688 | =begin original |
| 2645 | 1689 | |
| 2646 | Omitting the | |
| 1690 | Omitting the C<continue> section is semantically equivalent to using an | |
| 2647 | ||
| 1691 | empty one, logically enough. In that case, C<next> goes directly back | |
| 2648 | ||
| 1692 | to check the condition at the top of the loop. | |
| 2649 | 1693 | |
| 2650 | 1694 | =end original |
| 2651 | 1695 | |
| 2652 | ||
| 1696 | C<continue> 節を省略するのは、文法的には空の節を指定したのと同じで、 | |
| 2653 | 論理的には十分 | |
| 1697 | 論理的には十分です。 | |
| 2654 | 条件チェックに戻ります。 | |
| 1698 | この場合、C<next> は直接ループ先頭の条件チェックに戻ります。 | |
| 2655 | 1699 | |
| 2656 | =begin original | |
| 2657 | ||
| 2658 | When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function | |
| 2659 | that falls through the current C<when> or C<default> block instead of | |
| 2660 | iterating a dynamically enclosing C<foreach> or exiting a lexically | |
| 2661 | enclosing C<given>. In Perl 5.14 and earlier, this form of | |
| 2662 | L<C<continue>|/continue BLOCK> was only available when the | |
| 2663 | L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See | |
| 2664 | L<feature> and L<perlsyn/"Switch Statements"> for more information. | |
| 2665 | ||
| 2666 | =end original | |
| 2667 | ||
| 2668 | BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や | |
| 2669 | レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または | |
| 2670 | C<default> のブロックを通り抜けるための文です。 | |
| 2671 | Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は | |
| 2672 | L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ | |
| 2673 | 利用可能です。 | |
| 2674 | さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を | |
| 2675 | 参照してください。 | |
| 2676 | ||
| 2677 | 1700 | =item cos EXPR |
| 2678 | X<cos> X<cosine> X<acos> X<arccosine> | |
| 2679 | 1701 | |
| 2680 | 1702 | =item cos |
| 2681 | 1703 | |
| 2682 | =for Pod::Functions cosine function | |
| 2683 | ||
| 2684 | 1704 | =begin original |
| 2685 | 1705 | |
| 2686 | 1706 | Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, |
| 2687 | takes | |
| 1707 | takes cosine of C<$_>. | |
| 2688 | 1708 | |
| 2689 | 1709 | =end original |
| 2690 | 1710 | |
| 2691 | 1711 | (ラジアンで示した) EXPR の余弦を返します。 |
| 2692 | EXPR が省略されたときには、 | |
| 1712 | EXPR が省略されたときには、C<$_> の余弦を取ります。 | |
| 2693 | 1713 | |
| 2694 | 1714 | =begin original |
| 2695 | 1715 | |
| 2696 | For the inverse cosine operation, you may use the | |
| 1716 | For the inverse cosine operation, you may use the C<Math::Trig::acos()> | |
| 2697 | ||
| 1717 | function, or use this relation: | |
| 2698 | 1718 | |
| 2699 | 1719 | =end original |
| 2700 | 1720 | |
| 2701 | 逆余弦を求めるためには、 | |
| 1721 | 逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、 | |
| 2702 | 1722 | 以下の関係を使ってください。 |
| 2703 | 1723 | |
| 2704 | 1724 | sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } |
| 2705 | 1725 | |
| 2706 | 1726 | =item crypt PLAINTEXT,SALT |
| 2707 | X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password> | |
| 2708 | X<decrypt> X<cryptography> X<passwd> X<encrypt> | |
| 2709 | 1727 | |
| 2710 | =for Pod::Functions one-way passwd-style encryption | |
| 2711 | ||
| 2712 | 1728 | =begin original |
| 2713 | 1729 | |
| 2714 | ||
| 1730 | Encrypts a string exactly like the crypt(3) function in the C library | |
| 2715 | ||
| 1731 | (assuming that you actually have a version there that has not been | |
| 2716 | ||
| 1732 | extirpated as a potential munition). This can prove useful for checking | |
| 1733 | the password file for lousy passwords, amongst other things. Only the | |
| 1734 | guys wearing white hats should do this. | |
| 2717 | 1735 | |
| 2718 | 1736 | =end original |
| 2719 | 1737 | |
| 2720 | C ライブラリの | |
| 1738 | C ライブラリの crypt(3) 関数と全く同じように、文字列を暗号化します | |
| 2721 | ||
| 1739 | (一時的な必需品として、まだ絶滅していないバージョンを持っていると仮定しています)。 | |
| 2722 | ||
| 1740 | パスワードファイルの中で、 | |
| 1741 | あまり良くないものをチェックするために使うことができます。 | |
| 1742 | 公正な人だけが、これを行なうべきです。 | |
| 2723 | 1743 | |
| 2724 | 1744 | =begin original |
| 2725 | 1745 | |
| 2726 | ||
| 1746 | Note that C<crypt> is intended to be a one-way function, much like breaking | |
| 2727 | ||
| 1747 | eggs to make an omelette. There is no (known) corresponding decrypt | |
| 2728 | ||
| 1748 | function. As a result, this function isn't all that useful for | |
| 2729 | ||
| 1749 | cryptography. (For that, see your nearby CPAN mirror.) | |
| 2730 | (known) way to get the original PLAINTEXT from the hash. Small | |
| 2731 | changes in the PLAINTEXT or SALT will result in large changes in the | |
| 2732 | digest. | |
| 2733 | 1750 | |
| 2734 | 1751 | =end original |
| 2735 | 1752 | |
| 2736 | ||
| 1753 | C<crypt> は一方向関数を指向していることに注意してください。 | |
| 2737 | ||
| 1754 | オムレツを作るのに卵を割るようなものです。 | |
| 2738 | ||
| 1755 | (知られている限り)対応する復号化関数はありません。 | |
| 2739 | ||
| 1756 | 結果として、この関数はあらゆる暗号に対して有効というわけではありません | |
| 2740 | ||
| 1757 | (このためには、お近くの CPAN を参照してください)。 | |
| 2741 | PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。 | |
| 2742 | 1758 | |
| 2743 | 1759 | =begin original |
| 2744 | 1760 | |
| 2745 | ||
| 1761 | When verifying an existing encrypted string you should use the encrypted | |
| 2746 | ||
| 1762 | text as the salt (like C<crypt($plain, $crypted) eq $crypted>). This | |
| 2747 | ||
| 1763 | allows your code to work with the standard C<crypt> and with more | |
| 2748 | ||
| 1764 | exotic implementations. When choosing a new salt create a random two | |
| 2749 | ha | |
| 1765 | character string whose characters come from the set C<[./0-9A-Za-z]> | |
| 2750 | i | |
| 1766 | (like C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). | |
| 2751 | not the password itself. The user types in a password that is | |
| 2752 | L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored | |
| 2753 | digest. If the two digests match, the password is correct. | |
| 2754 | 1767 | |
| 2755 | 1768 | =end original |
| 2756 | 1769 | |
| 2757 | ||
| 1770 | すでにある暗号化された文字列の検証するには、暗号化されたテキストを | |
| 2758 | ||
| 1771 | (C<crypt($plain, $crypted) eq $crypted> のようにして)salt として使います。 | |
| 2759 | ||
| 1772 | これによって標準的な C<crypt> や、より風変わりな実装で動作します。 | |
| 2760 | "crypt" という名前は少し間違った名前です。 | |
| 2761 | その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを | |
| 2762 | 転送したり保管したりせずにチェックするために使います。 | |
| 2763 | 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 | |
| 2764 | パスワード自身ではなく、パスワードのダイジェストが保管されます。 | |
| 2765 | ユーザーがパスワードを入力すると、保管されているダイジェストと同じ | |
| 2766 | salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。 | |
| 2767 | 二つのダイジェストが同じなら、パスワードは正しいです。 | |
| 2768 | ||
| 2769 | =begin original | |
| 2770 | ||
| 2771 | When verifying an existing digest string you should use the digest as | |
| 2772 | the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used | |
| 2773 | to create the digest is visible as part of the digest. This ensures | |
| 2774 | L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same | |
| 2775 | salt as the digest. This allows your code to work with the standard | |
| 2776 | L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations. | |
| 2777 | In other words, assume nothing about the returned string itself nor | |
| 2778 | about how many bytes of SALT may matter. | |
| 2779 | ||
| 2780 | =end original | |
| 2781 | ||
| 2782 | すでにあるダイジェスト文字列を検証するには、ダイジェストを | |
| 2783 | (C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。 | |
| 2784 | ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 | |
| 2785 | これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を | |
| 2786 | ダイジェストとしてハッシュ化できるようにします。 | |
| 2787 | これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな | |
| 2788 | 実装でも動作します。 | |
| 2789 | 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 | |
| 2790 | どのような仮定もしてはいけません。 | |
| 2791 | ||
| 2792 | =begin original | |
| 2793 | ||
| 2794 | Traditionally the result is a string of 13 bytes: two first bytes of | |
| 2795 | the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only | |
| 2796 | the first eight bytes of PLAINTEXT mattered. But alternative | |
| 2797 | hashing schemes (like MD5), higher level security schemes (like C2), | |
| 2798 | and implementations on non-Unix platforms may produce different | |
| 2799 | strings. | |
| 2800 | ||
| 2801 | =end original | |
| 2802 | ||
| 2803 | 伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて | |
| 2804 | 集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の | |
| 2805 | 8 バイトだけが意味があります。 | |
| 2806 | しかし、(MD5 のように) 異なったハッシュ手法、 | |
| 2807 | (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの | |
| 2808 | 実装などでは異なった文字列が生成されることがあります。 | |
| 2809 | ||
| 2810 | =begin original | |
| 2811 | ||
| 2812 | When choosing a new salt create a random two character string whose | |
| 2813 | characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.', | |
| 2814 | '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of | |
| 2815 | characters is just a recommendation; the characters allowed in | |
| 2816 | the salt depend solely on your system's crypt library, and Perl can't | |
| 2817 | restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts. | |
| 2818 | ||
| 2819 | =end original | |
| 2820 | ||
| 2821 | 1773 | 新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から |
| 2822 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の | |
| 1774 | (C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして) | |
| 2823 | ||
| 1775 | ランダムに2 つの文字を選びます。 | |
| 2824 | この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 | |
| 2825 | ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が | |
| 2826 | どのような salt を受け付けるかについて制限しません。 | |
| 2827 | 1776 | |
| 2828 | 1777 | =begin original |
| 2829 | 1778 | |
| 2830 | 1779 | Here's an example that makes sure that whoever runs this program knows |
| 2831 | their password: | |
| 1780 | their own password: | |
| 2832 | 1781 | |
| 2833 | 1782 | =end original |
| 2834 | 1783 | |
| 2835 | 1784 | プログラムを実行する人が、 |
| 2836 | 1785 | 自分のパスワードを知っていることを確認する例です: |
| 2837 | 1786 | |
| 2838 | | |
| 1787 | $pwd = (getpwuid($<))[1]; | |
| 2839 | 1788 | |
| 2840 | 1789 | system "stty -echo"; |
| 2841 | 1790 | print "Password: "; |
| 2842 | chomp( | |
| 1791 | chomp($word = <STDIN>); | |
| 2843 | 1792 | print "\n"; |
| 2844 | 1793 | system "stty echo"; |
| 2845 | 1794 | |
| 2846 | 1795 | if (crypt($word, $pwd) ne $pwd) { |
| 2847 | ||
| 1796 | die "Sorry...\n"; | |
| 2848 | 1797 | } else { |
| 2849 | ||
| 1798 | print "ok\n"; | |
| 2850 | 1799 | } |
| 2851 | 1800 | |
| 2852 | 1801 | =begin original |
| 2853 | 1802 | |
| 2854 | 1803 | Of course, typing in your own password to whoever asks you |
| 2855 | 1804 | for it is unwise. |
| 2856 | 1805 | |
| 2857 | 1806 | =end original |
| 2858 | 1807 | |
| 2859 | 1808 | もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。 |
| 2860 | 1809 | |
| 2861 | 1810 | =begin original |
| 2862 | 1811 | |
| 2863 | The L< | |
| 1812 | The L<crypt> function is unsuitable for encrypting large quantities | |
| 2864 | ||
| 1813 | of data, not least of all because you can't get the information | |
| 2865 | ||
| 1814 | back. Look at the F<by-module/Crypt> and F<by-module/PGP> directories | |
| 2866 | a | |
| 1815 | on your favorite CPAN mirror for a slew of potentially useful | |
| 1816 | modules. | |
| 2867 | 1817 | |
| 2868 | 1818 | =end original |
| 2869 | 1819 | |
| 2870 | L< | |
| 1820 | L<crypt> 関数は大量のデータの暗号化には向いていません。 | |
| 2871 | ||
| 1821 | これは情報を戻せないという理由だけではありません。 | |
| 2872 | ||
| 1822 | あなたのお好みの CPAN ミラー の F<by-module/Crypt> と F<by-module/PGP> | |
| 1823 | ディレクトリを見れば、あなたの役に立ちそうなモジュールが大量にあります。 | |
| 2873 | 1824 | |
| 2874 | =begin original | |
| 2875 | ||
| 2876 | If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which | |
| 2877 | I<potentially> has characters with codepoints above 255), Perl tries to | |
| 2878 | make sense of the situation by trying to downgrade (a copy of) the | |
| 2879 | string back to an eight-bit byte string before calling | |
| 2880 | L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good. | |
| 2881 | If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with | |
| 2882 | L<C<Wide character in crypt>|perldiag/Wide character in %s>. | |
| 2883 | ||
| 2884 | =end original | |
| 2885 | ||
| 2886 | Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を | |
| 2887 | 含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は | |
| 2888 | L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた | |
| 2889 | 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) | |
| 2890 | ことで状況のつじつまを合わせようとします。 | |
| 2891 | うまく動けば、それでよし。 | |
| 2892 | 動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は | |
| 2893 | L<C<Wide character in crypt>|perldiag/Wide character in %s> という | |
| 2894 | メッセージと共に die します。 | |
| 2895 | ||
| 2896 | =begin original | |
| 2897 | ||
| 2898 | Portability issues: L<perlport/crypt>. | |
| 2899 | ||
| 2900 | =end original | |
| 2901 | ||
| 2902 | 移植性の問題: L<perlport/crypt>。 | |
| 2903 | ||
| 2904 | 1825 | =item dbmclose HASH |
| 2905 | X<dbmclose> | |
| 2906 | 1826 | |
| 2907 | =for Pod::Functions breaks binding on a tied dbm file | |
| 2908 | ||
| 2909 | 1827 | =begin original |
| 2910 | 1828 | |
| 2911 | [This function has been largely superseded by the | |
| 1829 | [This function has been largely superseded by the C<untie> function.] | |
| 2912 | L<C<untie>|/untie VARIABLE> function.] | |
| 2913 | 1830 | |
| 2914 | =end original | |
| 2915 | ||
| 2916 | [この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。] | |
| 2917 | ||
| 2918 | =begin original | |
| 2919 | ||
| 2920 | 1831 | Breaks the binding between a DBM file and a hash. |
| 2921 | 1832 | |
| 2922 | 1833 | =end original |
| 2923 | 1834 | |
| 1835 | [この関数は、C<untie> 関数に大きくとって代わられました。] | |
| 1836 | ||
| 2924 | 1837 | DBM ファイルとハッシュの連結をはずします。 |
| 2925 | 1838 | |
| 2926 | =begin original | |
| 2927 | ||
| 2928 | Portability issues: L<perlport/dbmclose>. | |
| 2929 | ||
| 2930 | =end original | |
| 2931 | ||
| 2932 | 移植性の問題: L<perlport/dbmclose>。 | |
| 2933 | ||
| 2934 | 1839 | =item dbmopen HASH,DBNAME,MASK |
| 2935 | X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm> | |
| 2936 | 1840 | |
| 2937 | =for Pod::Functions create binding on a tied dbm file | |
| 2938 | ||
| 2939 | 1841 | =begin original |
| 2940 | 1842 | |
| 2941 | [This function has been largely superseded by the | |
| 1843 | [This function has been largely superseded by the C<tie> function.] | |
| 2942 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.] | |
| 2943 | 1844 | |
| 2944 | ||
| 1845 | This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a | |
| 1846 | hash. HASH is the name of the hash. (Unlike normal C<open>, the first | |
| 2946 | ||
| 1847 | argument is I<not> a filehandle, even though it looks like one). DBNAME | |
| 2947 | ||
| 1848 | is the name of the database (without the F<.dir> or F<.pag> extension if | |
| 1849 | any). If the database does not exist, it is created with protection | |
| 2949 | ||
| 1850 | specified by MASK (as modified by the C<umask>). If your system supports | |
| 1851 | only the older DBM functions, you may perform only one C<dbmopen> in your | |
| 2951 | This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley | |
| 2952 | DB file to a hash. HASH is the name of the hash. (Unlike normal | |
| 2953 | L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a | |
| 2954 | filehandle, even though it looks like one). DBNAME is the name of the | |
| 2955 | database (without the F<.dir> or F<.pag> extension if any). If the | |
| 2956 | database does not exist, it is created with protection specified by MASK | |
| 2957 | (as modified by the L<C<umask>|/umask EXPR>). To prevent creation of | |
| 2958 | the database if it doesn't exist, you may specify a MODE of 0, and the | |
| 2959 | function will return a false value if it can't find an existing | |
| 2960 | database. If your system supports only the older DBM functions, you may | |
| 2961 | make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your | |
| 2962 | 1852 | program. In older versions of Perl, if your system had neither DBM nor |
| 2963 | ndbm, calling | |
| 1853 | ndbm, calling C<dbmopen> produced a fatal error; it now falls back to | |
| 2964 | ||
| 1854 | sdbm(3). | |
| 2965 | 1855 | |
| 2966 | 1856 | =end original |
| 2967 | 1857 | |
| 2968 | ||
| 1858 | [この関数は、C<tie> 関数に大きくとって代わられました。] | |
| 2969 | ||
| 1860 | dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB | |
| 1861 | ファイルを連想配列に結び付けます。 | |
| 2970 | 1862 | HASH は、その連想配列の名前です。 |
| 2971 | (普通の | |
| 1863 | (普通の C<open> とは違って、最初の引数はファイルハンドル | |
| 2972 | ||
| 1864 | I<ではありません>。まあ、似たようなものですが。) | |
| 2973 | DBNAME は、データベースの名前です (拡張子の .dir や | |
| 1865 | DBNAME は、データベースの名前です (拡張子の .dir や | |
| 2974 | つけません)。 | |
| 1866 | .pag はもしあってもつけません)。 | |
| 2975 | データベースが存在しなければ、MODE MASK (を | |
| 1867 | データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの) で | |
| 2976 | ||
| 1868 | 指定されたモードで作られます。 | |
| 2977 | 存在しないときにデータベースを作成しないようにするには、MODE に 0 を | |
| 2978 | 設定でき、データベースを見つけられなかった場合は関数は偽を返します。 | |
| 2979 | 1869 | 古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ |
| 2980 | ||
| 1870 | dbmopen() を実行することができます。 | |
| 2981 | 1871 | 昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、 |
| 2982 | ||
| 1872 | dbmopen() を呼び出すと致命的エラーになります。 | |
| 2983 | 現在では | |
| 1873 | 現在では sdbm(3) にフォールバックします。 | |
| 2984 | 1874 | |
| 2985 | 1875 | =begin original |
| 2986 | 1876 | |
| 2987 | 1877 | If you don't have write access to the DBM file, you can only read hash |
| 2988 | 1878 | variables, not set them. If you want to test whether you can write, |
| 2989 | either use file tests or try setting a dummy hash entry inside an | |
| 1879 | either use file tests or try setting a dummy hash entry inside an C<eval>, | |
| 2990 | ||
| 1880 | which will trap the error. | |
| 2991 | 1881 | |
| 2992 | 1882 | =end original |
| 2993 | 1883 | |
| 2994 | 1884 | DBM ファイルに対して、書き込み権が無いときには、ハッシュ |
| 2995 | 1885 | 配列を読みだすことだけができ、設定することはできません。 |
| 2996 | 1886 | 書けるか否かを調べたい場合には、ファイルテスト |
| 2997 | 演算子を使うか、エラーをトラップ | |
| 1887 | 演算子を使うか、エラーをトラップしてくれる、C<eval> | |
| 2998 | ダミーのハッシュエントリを設定してみることになります。 | |
| 1888 | の中で、ダミーのハッシュエントリを設定してみることになります。 | |
| 2999 | 1889 | |
| 3000 | 1890 | =begin original |
| 3001 | 1891 | |
| 3002 | Note that functions such as | |
| 1892 | Note that functions such as C<keys> and C<values> may return huge lists | |
| 3003 | ||
| 1893 | when used on large DBM files. You may prefer to use the C<each> | |
| 3004 | fi | |
| 1894 | function to iterate over large DBM files. Example: | |
| 3005 | iterate over large DBM files. Example: | |
| 3006 | 1895 | |
| 3007 | 1896 | =end original |
| 3008 | 1897 | |
| 3009 | 大きな DBM ファイルを扱うときには、 | |
| 1898 | 大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、 | |
| 3010 | ||
| 1899 | 巨大なリストを返します。 | |
| 3011 | 大きな DBM ファイルでは、 | |
| 1900 | 大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が | |
| 3012 | ||
| 1901 | 良いかもしれません。 | |
| 3013 | 1902 | 例: |
| 3014 | 1903 | |
| 3015 | 1904 | # print out history file offsets |
| 3016 | 1905 | dbmopen(%HIST,'/usr/lib/news/history',0666); |
| 3017 | 1906 | while (($key,$val) = each %HIST) { |
| 3018 | ||
| 1907 | print $key, ' = ', unpack('L',$val), "\n"; | |
| 3019 | 1908 | } |
| 3020 | 1909 | dbmclose(%HIST); |
| 3021 | 1910 | |
| 3022 | 1911 | =begin original |
| 3023 | 1912 | |
| 3024 | 1913 | See also L<AnyDBM_File> for a more general description of the pros and |
| 3025 | 1914 | cons of the various dbm approaches, as well as L<DB_File> for a particularly |
| 3026 | 1915 | rich implementation. |
| 3027 | 1916 | |
| 3028 | 1917 | =end original |
| 3029 | 1918 | |
| 3030 | 1919 | 様々な dbm 手法に対する利点欠点に関するより一般的な記述および |
| 3031 | 1920 | 特にリッチな実装である L<DB_File> に関しては |
| 3032 | 1921 | L<AnyDBM_File> も参照してください。 |
| 3033 | 1922 | |
| 3034 | 1923 | =begin original |
| 3035 | 1924 | |
| 3036 | 1925 | You can control which DBM library you use by loading that library |
| 3037 | before you call | |
| 1926 | before you call dbmopen(): | |
| 3038 | 1927 | |
| 3039 | 1928 | =end original |
| 3040 | 1929 | |
| 3041 | ||
| 1930 | dbmopen() を呼び出す前にライブラリを読み込むことで、 | |
| 3042 | ||
| 1931 | どの DBM ライブラリを使うかを制御できます: | |
| 3043 | 1932 | |
| 3044 | 1933 | use DB_File; |
| 3045 | 1934 | dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db") |
| 3046 | ||
| 1935 | or die "Can't open netscape history file: $!"; | |
| 3047 | 1936 | |
| 3048 | =begin original | |
| 3049 | ||
| 3050 | Portability issues: L<perlport/dbmopen>. | |
| 3051 | ||
| 3052 | =end original | |
| 3053 | ||
| 3054 | 移植性の問題: L<perlport/dbmopen>。 | |
| 3055 | ||
| 3056 | 1937 | =item defined EXPR |
| 3057 | X<defined> X<undef> X<undefined> | |
| 3058 | 1938 | |
| 3059 | 1939 | =item defined |
| 3060 | 1940 | |
| 3061 | =for Pod::Functions test whether a value, variable, or function is defined | |
| 3062 | ||
| 3063 | 1941 | =begin original |
| 3064 | 1942 | |
| 3065 | Returns a Boolean value telling whether EXPR has a value other than | |
| 1943 | Returns a Boolean value telling whether EXPR has a value other than | |
| 3066 | undefined value | |
| 1944 | the undefined value C<undef>. If EXPR is not present, C<$_> will be | |
| 3067 | ||
| 1945 | checked. | |
| 3068 | 1946 | |
| 3069 | 1947 | =end original |
| 3070 | 1948 | |
| 3071 | 左辺値 EXPR が未定義値 | |
| 1949 | 左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を | |
| 3072 | ||
| 1950 | 返します。 | |
| 3073 | EXPR がない場合は、 | |
| 1951 | EXPR がない場合は、C<$_> がチェックされます。 | |
| 3074 | 1952 | |
| 3075 | 1953 | =begin original |
| 3076 | 1954 | |
| 3077 | Many operations return | |
| 1955 | Many operations return C<undef> to indicate failure, end of file, | |
| 3078 | ||
| 1956 | system error, uninitialized variable, and other exceptional | |
| 3079 | conditions. This function allows you to distinguish | |
| 1957 | conditions. This function allows you to distinguish C<undef> from | |
| 3080 | ||
| 1958 | other values. (A simple Boolean test will not distinguish among | |
| 3081 | ||
| 1959 | C<undef>, zero, the empty string, and C<"0">, which are all equally | |
| 3082 | ||
| 1960 | false.) Note that since C<undef> is a valid scalar, its presence | |
| 3083 | ||
| 1961 | doesn't I<necessarily> indicate an exceptional condition: C<pop> | |
| 3084 | ||
| 1962 | returns C<undef> when its argument is an empty array, I<or> when the | |
| 3085 | return | |
| 1963 | element to return happens to be C<undef>. | |
| 3086 | I<or> when the element to return happens to be L<C<undef>|/undef EXPR>. | |
| 3087 | 1964 | |
| 3088 | 1965 | =end original |
| 3089 | 1966 | |
| 3090 | 1967 | 多くの演算子が、EOF や未初期化変数、システムエラーといった、 |
| 3091 | 例外的な条件で | |
| 1968 | 例外的な条件で C<undef> を返すようになっています。 | |
| 3092 | この関数は、他の値と | |
| 1969 | この関数は、他の値と C<undef> とを区別するために使えます。 | |
| 3093 | (単純な真偽値テストでは、 | |
| 1970 | (単純な真偽値テストでは、C<undef>、0、空文字、C<"0"> のいずれも偽を返すので、 | |
| 3094 | ||
| 1971 | 区別することができません。) | |
| 3095 | ||
| 1972 | C<undef> は有効なスカラ値なので、その存在が I<必ずしも> | |
| 3096 | 1973 | 例外的な状況を表すとは限らないということに注意してください: |
| 3097 | ||
| 1974 | C<pop> は引数が空の配列だったときに C<undef> を返しますが、 | |
| 3098 | ||
| 1975 | I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。 | |
| 3099 | L<C<undef>|/undef EXPR> だったのかもしれません。 | |
| 3100 | 1976 | |
| 3101 | 1977 | =begin original |
| 3102 | 1978 | |
| 3103 | You may also use C<defined(&func)> to check whether subroutine C<func> | |
| 1979 | You may also use C<defined(&func)> to check whether subroutine C<&func> | |
| 3104 | 1980 | has ever been defined. The return value is unaffected by any forward |
| 3105 | declarations of C<f | |
| 1981 | declarations of C<&foo>. Note that a subroutine which is not defined | |
| 3106 | 1982 | may still be callable: its package may have an C<AUTOLOAD> method that |
| 3107 | makes it spring into existence the first time that it is called | |
| 1983 | makes it spring into existence the first time that it is called -- see | |
| 3108 | 1984 | L<perlsub>. |
| 3109 | 1985 | |
| 3110 | 1986 | =end original |
| 3111 | 1987 | |
| 3112 | C<defined(&func)> とすることでサブルーチン C<func> の存在を、 | |
| 1988 | C<defined(&func)> とすることでサブルーチン C<&func> の存在を、 | |
| 3113 | 1989 | 確かめることもできます。 |
| 3114 | 返り値は C<f | |
| 1990 | 返り値は C<&foo> の前方定義には影響されません。 | |
| 3115 | 定義されていないサブルーチンも呼び出し可能で | |
| 1991 | 定義されていないサブルーチンも呼び出し可能であることに注意してください。 | |
| 3116 | 1992 | 最初に呼び出されたときに存在するようにするための |
| 3117 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません | |
| 1993 | C<AUTOLOAD> メソッドを持ったパッケージかもしれません-- | |
| 3118 | L<perlsub> を参照して | |
| 1994 | L<perlsub> を参照して下さい。 | |
| 3119 | 1995 | |
| 3120 | 1996 | =begin original |
| 3121 | 1997 | |
| 3122 | Use of | |
| 1998 | Use of C<defined> on aggregates (hashes and arrays) is deprecated. It | |
| 3123 | ||
| 1999 | used to report whether memory for that aggregate has ever been | |
| 3124 | a | |
| 2000 | allocated. This behavior may disappear in future versions of Perl. | |
| 3125 | test for size: | |
| 2001 | You should instead use a simple test for size: | |
| 3126 | 2002 | |
| 3127 | 2003 | =end original |
| 3128 | 2004 | |
| 3129 | 集合(ハッシュや配列)への | |
| 2005 | 集合(ハッシュや配列)への C<defined> の使用は非推奨です。 | |
| 3130 | ||
| 2006 | これはその集合にメモリが割り当てられたかを報告するのに | |
| 3131 | ||
| 2007 | 用いられていました。 | |
| 2008 | この振る舞いは将来のバージョンの Perl では消滅するかもしれません。 | |
| 3132 | 2009 | 代わりにサイズに対する簡単なテストを使うべきです。 |
| 3133 | 2010 | |
| 3134 | 2011 | if (@an_array) { print "has array elements\n" } |
| 3135 | 2012 | if (%a_hash) { print "has hash members\n" } |
| 3136 | 2013 | |
| 3137 | 2014 | =begin original |
| 3138 | 2015 | |
| 3139 | 2016 | When used on a hash element, it tells you whether the value is defined, |
| 3140 | not whether the key exists in the hash. Use L< | |
| 2017 | not whether the key exists in the hash. Use L</exists> for the latter | |
| 3141 | ||
| 2018 | purpose. | |
| 3142 | 2019 | |
| 2020 | Examples: | |
| 2021 | ||
| 3143 | 2022 | =end original |
| 3144 | 2023 | |
| 3145 | 2024 | ハッシュの要素に対して用いると、value が定義されているか否かを |
| 3146 | 2025 | 返すものであって、ハッシュに key が存在するか否かを返すのではありません。 |
| 3147 | この用途には、L< | |
| 2026 | この用途には、L</exists> を使ってください。 | |
| 3148 | 2027 | |
| 3149 | =begin original | |
| 3150 | ||
| 3151 | Examples: | |
| 3152 | ||
| 3153 | =end original | |
| 3154 | ||
| 3155 | 2028 | 例: |
| 3156 | 2029 | |
| 3157 | print if defined $switch{D}; | |
| 2030 | print if defined $switch{'D'}; | |
| 3158 | 2031 | print "$val\n" while defined($val = pop(@ary)); |
| 3159 | 2032 | die "Can't readlink $sym: $!" |
| 3160 | ||
| 2033 | unless defined($value = readlink $sym); | |
| 3161 | sub foo { defined &$bar ? $bar | |
| 2034 | sub foo { defined &$bar ? &$bar(@_) : die "No bar"; } | |
| 3162 | 2035 | $debugging = 0 unless defined $debugging; |
| 3163 | 2036 | |
| 3164 | 2037 | =begin original |
| 3165 | 2038 | |
| 3166 | Note: Many folks tend to overuse | |
| 2039 | Note: Many folks tend to overuse C<defined>, and then are surprised to | |
| 3167 | ||
| 2040 | discover that the number C<0> and C<""> (the zero-length string) are, in fact, | |
| 3168 | ||
| 2041 | defined values. For example, if you say | |
| 3169 | say | |
| 3170 | 2042 | |
| 3171 | 2043 | =end original |
| 3172 | 2044 | |
| 3173 | 注意: 多くの人々が | |
| 2045 | 注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が | |
| 3174 | ||
| 2046 | 実際のところ定義された値であることに驚くようです。 | |
| 3175 | 2047 | 例えば、以下のように書くと: |
| 3176 | 2048 | |
| 3177 | 2049 | "ab" =~ /a(.*)b/; |
| 3178 | 2050 | |
| 3179 | 2051 | =begin original |
| 3180 | 2052 | |
| 3181 | The pattern match succeeds and C<$1> is defined, a | |
| 2053 | The pattern match succeeds, and C<$1> is defined, despite the fact that it | |
| 3182 | matched "nothing". | |
| 2054 | matched "nothing". But it didn't really match nothing--rather, it | |
| 3183 | 2055 | matched something that happened to be zero characters long. This is all |
| 3184 | 2056 | very above-board and honest. When a function returns an undefined value, |
| 3185 | 2057 | it's an admission that it couldn't give you an honest answer. So you |
| 3186 | should use | |
| 2058 | should use C<defined> only when you're questioning the integrity of what | |
| 3187 | ||
| 2059 | you're trying to do. At other times, a simple comparison to C<0> or C<""> is | |
| 3188 | ||
| 2060 | what you want. | |
| 3189 | 2061 | |
| 3190 | 2062 | =end original |
| 3191 | 2063 | |
| 3192 | 2064 | パターンマッチングが成功し、C<$1> が定義されても、実際には |
| 3193 | 2065 | 「なし」にマッチしています。 |
| 3194 | しかしこれは何にもマッチしていないわけではありません | |
| 2066 | しかしこれは何にもマッチしていないわけではありません-- | |
| 3195 | 2067 | 何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。 |
| 3196 | 2068 | これは非常に率直で正直なことです。 |
| 3197 | 2069 | 関数が未定義値を返すとき、正直な答えを返すことができないことを |
| 3198 | 2070 | 告白しています。 |
| 3199 | 2071 | ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ |
| 3200 | ||
| 2072 | C<defined> を使うべきです。 | |
| 3201 | 2073 | その他の場合では、単に C<0> または C<""> と比較するというのがあなたの |
| 3202 | 2074 | 求めているものです。 |
| 3203 | 2075 | |
| 3204 | 2076 | =begin original |
| 3205 | 2077 | |
| 3206 | See also L< | |
| 2078 | See also L</undef>, L</exists>, L</ref>. | |
| 3207 | L<C<ref>|/ref EXPR>. | |
| 3208 | 2079 | |
| 3209 | 2080 | =end original |
| 3210 | 2081 | |
| 3211 | L< | |
| 2082 | L</undef>, L</exists>, L</ref> も参照してください。 | |
| 3212 | 参照してください。 | |
| 3213 | 2083 | |
| 3214 | 2084 | =item delete EXPR |
| 3215 | X<delete> | |
| 3216 | 2085 | |
| 3217 | =for Pod::Functions deletes a value from a hash | |
| 3218 | ||
| 3219 | 2086 | =begin original |
| 3220 | 2087 | |
| 3221 | Given an expression that specifies a | |
| 2088 | Given an expression that specifies a hash element, array element, hash slice, | |
| 3222 | ||
| 2089 | or array slice, deletes the specified element(s) from the hash or array. | |
| 3223 | ||
| 2090 | In the case of an array, if the array elements happen to be at the end, | |
| 3224 | t | |
| 2091 | the size of the array will shrink to the highest element that tests | |
| 3225 | ||
| 2092 | true for exists() (or 0 if no such element exists). | |
| 3226 | 2093 | |
| 3227 | 2094 | =end original |
| 3228 | 2095 | |
| 3229 | ハッシュ | |
| 2096 | ハッシュ要素、配列要素、ハッシュスライス、配列スライスを指定する式を取り、 | |
| 3230 | 指定された要素をハッシュから削除す | |
| 2097 | 指定された要素をハッシュや配列からを削除します。 | |
| 3231 | ||
| 2098 | 配列の場合、配列要素が最後にあった場合は、 | |
| 3232 | ||
| 2099 | 配列の大きさは exists() が真を返す最後尾の要素に縮みます | |
| 3233 | ||
| 2100 | (そのような要素がない場合は 0 になります)。 | |
| 3234 | 2101 | |
| 3235 | 2102 | =begin original |
| 3236 | 2103 | |
| 3237 | ||
| 2104 | Returns each element so deleted or the undefined value if there was no such | |
| 3238 | element in | |
| 2105 | element. Deleting from C<$ENV{}> modifies the environment. Deleting from | |
| 3239 | ||
| 2106 | a hash tied to a DBM file deletes the entry from the DBM file. Deleting | |
| 3240 | ||
| 2107 | from a C<tie>d hash or array may not necessarily return anything. | |
| 3241 | L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> is passed to | |
| 3242 | C<delete>, the return value is a list of key/value pairs (two elements for each | |
| 3243 | item deleted from the hash). | |
| 3244 | 2108 | |
| 3245 | 2109 | =end original |
| 3246 | 2110 | |
| 3247 | ||
| 2111 | 削除された値か、(何も削除されなかった場合には) 未定義値が返されます。 | |
| 3248 | 削除 | |
| 2112 | C<$ENV{}> から削除を行なうと、実際に環境変数を変更します。 | |
| 3249 | 返されたリストの長さは常に引数リストの長さに対応します: | |
| 3250 | 存在しない要素を削除すると、対応する位置に未定義値をセットして返します。 | |
| 3251 | L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> が | |
| 3252 | C<delete> に渡されると、返り値はキー/値の組(それぞれのアイテムについて | |
| 3253 | 二つの要素が元のハッシュから削除されたもの)です。 | |
| 3254 | ||
| 3255 | =begin original | |
| 3256 | ||
| 3257 | L<C<delete>|/delete EXPR> may also be used on arrays and array slices, | |
| 3258 | but its behavior is less straightforward. Although | |
| 3259 | L<C<exists>|/exists EXPR> will return false for deleted entries, | |
| 3260 | deleting array elements never changes indices of existing values; use | |
| 3261 | L<C<shift>|/shift ARRAY> or L<C<splice>|/splice | |
| 3262 | ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements | |
| 3263 | fall at the end of an array, the array's size shrinks to the position of | |
| 3264 | the highest element that still tests true for L<C<exists>|/exists EXPR>, | |
| 3265 | or to 0 if none do. In other words, an array won't have trailing | |
| 3266 | nonexistent elements after a delete. | |
| 3267 | ||
| 3268 | =end original | |
| 3269 | ||
| 3270 | L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その | |
| 3271 | 振る舞いはあまり直感的ではありません。 | |
| 3272 | 削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、 | |
| 3273 | 配列要素を削除しても、存在する値の添え字は変わりません; このためには | |
| 3274 | L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を | |
| 3275 | 使ってください。 | |
| 3276 | しかし、削除された要素が配列の末尾であった場合、配列のサイズは | |
| 3277 | L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に | |
| 3278 | 切り詰められます。 | |
| 3279 | 言い換えると、delete の後には配列の末尾に値のない要素はありません。 | |
| 3280 | ||
| 3281 | =begin original | |
| 3282 | ||
| 3283 | B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is | |
| 3284 | strongly discouraged. The | |
| 3285 | notion of deleting or checking the existence of Perl array elements is not | |
| 3286 | conceptually coherent, and can lead to surprising behavior. | |
| 3287 | ||
| 3288 | =end original | |
| 3289 | ||
| 3290 | B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く | |
| 3291 | 非推奨です。 | |
| 3292 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
| 3293 | 驚くべき振る舞いを引き起こすことがあります。 | |
| 3294 | ||
| 3295 | =begin original | |
| 3296 | ||
| 3297 | Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment. | |
| 3298 | Deleting from a hash tied to a DBM file deletes the entry from the DBM | |
| 3299 | file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not | |
| 3300 | necessarily return anything; it depends on the implementation of the | |
| 3301 | L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever | |
| 3302 | it pleases. | |
| 3303 | ||
| 3304 | =end original | |
| 3305 | ||
| 3306 | L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。 | |
| 3307 | 2113 | DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを |
| 3308 | 2114 | 削除します。 |
| 3309 | しかし、 | |
| 2115 | しかし、C<tie> されたハッシュや配列からの削除は、 | |
| 3310 | ||
| 2116 | 値を返すとは限りません。 | |
| 3311 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE | |
| 3312 | メソッドの実装に依存するので、どんなことでも起こります。 | |
| 3313 | 2117 | |
| 3314 | 2118 | =begin original |
| 3315 | 2119 | |
| 3316 | ||
| 2120 | Deleting an array element effectively returns that position of the array | |
| 3317 | ||
| 2121 | to its initial, uninitialized state. Subsequently testing for the same | |
| 3318 | ||
| 2122 | element with exists() will return false. Note that deleting array | |
| 3319 | of | |
| 2123 | elements in the middle of an array will not shift the index of the ones | |
| 2124 | after them down--use splice() for that. See L</exists>. | |
| 3320 | 2125 | |
| 3321 | 2126 | =end original |
| 3322 | 2127 | |
| 3323 | ||
| 2128 | 配列要素を削除した場合、配列の位置は初期の、初期化されていない状態になります。 | |
| 3324 | ||
| 2129 | 引き続いて同じ要素に対して exists() でテストすると偽を返します。 | |
| 3325 | ||
| 2130 | 配列の途中の配列要素を削除してもインデックスはシフトしないことに | |
| 3326 | ||
| 2131 | 注意してください -- このためには splice() を使ってください。 | |
| 2132 | L</exists> を参照してください。 | |
| 3327 | 2133 | |
| 3328 | my %hash = (foo => 11, bar => 22, baz => 33); | |
| 3329 | my $scalar = delete $hash{foo}; # $scalar is 11 | |
| 3330 | $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 | |
| 3331 | my @array = delete @hash{qw(foo baz)}; # @array is (undef,33) | |
| 3332 | ||
| 3333 | 2134 | =begin original |
| 3334 | 2135 | |
| 3335 | 2136 | The following (inefficiently) deletes all the values of %HASH and @ARRAY: |
| 3336 | 2137 | |
| 3337 | 2138 | =end original |
| 3338 | 2139 | |
| 3339 | 2140 | 以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します: |
| 3340 | 2141 | |
| 3341 | foreach | |
| 2142 | foreach $key (keys %HASH) { | |
| 3342 | ||
| 2143 | delete $HASH{$key}; | |
| 3343 | 2144 | } |
| 3344 | 2145 | |
| 3345 | foreach | |
| 2146 | foreach $index (0 .. $#ARRAY) { | |
| 3346 | ||
| 2147 | delete $ARRAY[$index]; | |
| 3347 | 2148 | } |
| 3348 | 2149 | |
| 3349 | 2150 | =begin original |
| 3350 | 2151 | |
| 3351 | 2152 | And so do these: |
| 3352 | 2153 | |
| 3353 | 2154 | =end original |
| 3354 | 2155 | |
| 3355 | 2156 | そして以下のようにもできます: |
| 3356 | 2157 | |
| 3357 | 2158 | delete @HASH{keys %HASH}; |
| 3358 | 2159 | |
| 3359 | 2160 | delete @ARRAY[0 .. $#ARRAY]; |
| 3360 | 2161 | |
| 3361 | 2162 | =begin original |
| 3362 | 2163 | |
| 3363 | But both are slower than assigning the empty list | |
| 2164 | But both of these are slower than just assigning the empty list | |
| 3364 | or undefining %HASH or @ARRAY | |
| 2165 | or undefining %HASH or @ARRAY: | |
| 3365 | way to empty out an aggregate: | |
| 3366 | 2166 | |
| 3367 | 2167 | =end original |
| 3368 | 2168 | |
| 3369 | しかし、これら二つは | |
| 2169 | しかし、これら二つは単に空リストを代入するか、%HASH や @ARRAY を | |
| 3370 | 単に空リストを代入するか、%HASH や @ARRAY を | |
| 3371 | 2170 | undef するより遅いです: |
| 3372 | 2171 | |
| 3373 | %HASH = (); | |
| 2172 | %HASH = (); # completely empty %HASH | |
| 3374 | undef %HASH; | |
| 2173 | undef %HASH; # forget %HASH ever existed | |
| 3375 | 2174 | |
| 3376 | @ARRAY = (); | |
| 2175 | @ARRAY = (); # completely empty @ARRAY | |
| 3377 | undef @ARRAY; | |
| 2176 | undef @ARRAY; # forget @ARRAY ever existed | |
| 3378 | 2177 | |
| 3379 | 2178 | =begin original |
| 3380 | 2179 | |
| 3381 | ||
| 2180 | Note that the EXPR can be arbitrarily complicated as long as the final | |
| 3382 | ||
| 2181 | operation is a hash element, array element, hash slice, or array slice | |
| 2182 | lookup: | |
| 3383 | 2183 | |
| 3384 | 2184 | =end original |
| 3385 | 2185 | |
| 3386 | 最終的な操作が | |
| 2186 | 最終的な操作がハッシュ要素、配列要素、ハッシュスライス、配列スライスの | |
| 3387 | いずれかである限りは、EXPR には任意の複雑な式を置くことができ | |
| 2187 | いずれかである限りは、EXPR には任意の複雑な式を置くことができることに | |
| 2188 | 注意してください: | |
| 3388 | 2189 | |
| 3389 | 2190 | delete $ref->[$x][$y]{$key}; |
| 3390 | 2191 | delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys}; |
| 3391 | 2192 | |
| 3392 | 2193 | delete $ref->[$x][$y][$index]; |
| 3393 | 2194 | delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices]; |
| 3394 | 2195 | |
| 3395 | 2196 | =item die LIST |
| 3396 | X<die> X<throw> X<exception> X<raise> X<$@> X<abort> | |
| 3397 | 2197 | |
| 3398 | =for Pod::Functions raise an exception or bail out | |
| 3399 | ||
| 3400 | 2198 | =begin original |
| 3401 | 2199 | |
| 3402 | ||
| 2200 | Outside an C<eval>, prints the value of LIST to C<STDERR> and | |
| 3403 | ||
| 2201 | exits with the current value of C<$!> (errno). If C<$!> is C<0>, | |
| 3404 | ||
| 2202 | exits with the value of C<<< ($? >> 8) >>> (backtick `command` | |
| 3405 | ||
| 2203 | status). If C<<< ($? >> 8) >>> is C<0>, exits with C<255>. Inside | |
| 3406 | e | |
| 2204 | an C<eval(),> the error message is stuffed into C<$@> and the | |
| 3407 | ||
| 2205 | C<eval> is terminated with the undefined value. This makes | |
| 3408 | ||
| 2206 | C<die> the way to raise an exception. | |
| 3409 | 2207 | |
| 3410 | 2208 | =end original |
| 3411 | 2209 | |
| 3412 | ||
| 2210 | C<eval> の外では、LIST の値を C<STDERR> に出力し、その時点の | |
| 3413 | ||
| 2211 | C<$!> (errno) の値で exit します。 | |
| 3414 | ||
| 2212 | C<$!> の値が C<0> ならば、 | |
| 3415 | ||
| 2213 | C<<< ($? >> 8) >>> (backtick `command` のステータス) の値で exitします。 | |
| 3416 | ||
| 2214 | C<<< ($? >> 8) >>> も C<0> であれば、C<255> で exit することになります。 | |
| 3417 | C< | |
| 2215 | C<eval> の中で使用すると、エラーメッセージが、 | |
| 3418 | ||
| 2216 | C<$@> に入れられます。 | |
| 3419 | ||
| 2217 | C<eval> は中断され、未定義値を返します。 | |
| 2218 | これが C<die> が例外を発生させる方法です。 | |
| 3420 | 2219 | |
| 3421 | 2220 | =begin original |
| 3422 | 2221 | |
| 3423 | 2222 | Equivalent examples: |
| 3424 | 2223 | |
| 3425 | 2224 | =end original |
| 3426 | 2225 | |
| 3427 | 2226 | 等価な例: |
| 3428 | 2227 | |
| 3429 | 2228 | die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; |
| 3430 | 2229 | chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" |
| 3431 | 2230 | |
| 3432 | 2231 | =begin original |
| 3433 | 2232 | |
| 3434 | ||
| 2233 | If the value of EXPR does not end in a newline, the current script line | |
| 3435 | ||
| 2234 | number and input line number (if any) are also printed, and a newline | |
| 3436 | ||
| 2235 | is supplied. Note that the "input line number" (also known as "chunk") | |
| 3437 | ||
| 2236 | is subject to whatever notion of "line" happens to be currently in | |
| 2237 | effect, and is also available as the special variable C<$.>. | |
| 2238 | See L<perlvar/"$/"> and L<perlvar/"$.">. | |
| 3438 | 2239 | |
| 3439 | 2240 | =end original |
| 3440 | 2241 | |
| 3441 | ||
| 2242 | EXPR の評価結果が改行で終わっていなければ、その時点の | |
| 3442 | ||
| 2243 | スクリプト名とスクリプトの行番号、(もしあれば) | |
| 3443 | ||
| 2244 | 入力ファイルの行番号と改行文字が、続けて表示されます。 | |
| 3444 | ||
| 2245 | 「入力行番号」("chunk" とも呼ばれます)は | |
| 2246 | 「行」という概念が現在有効であると仮定しています。 | |
| 3446 | ||
| 2247 | また特殊変数 C<$.> でも利用可能です。 | |
| 3447 | ||
| 3448 | If the string exception does not end in a newline, the current | |
| 3449 | script line number and input line number (if any) and a newline | |
| 3450 | are appended to it. Note that the "input line number" (also | |
| 3451 | known as "chunk") is subject to whatever notion of "line" happens to | |
| 3452 | be currently in effect, and is also available as the special variable | |
| 3453 | L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">. | |
| 3454 | ||
| 3455 | =end original | |
| 3456 | ||
| 3457 | 文字列例外が改行で終わっていなければ、その時点のスクリプト名と | |
| 3458 | スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が | |
| 3459 | それに追加されます。 | |
| 3460 | 「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると | |
| 3461 | 仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。 | |
| 3462 | 2248 | L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。 |
| 3463 | 2249 | |
| 3464 | 2250 | =begin original |
| 3465 | 2251 | |
| 3466 | Hint: sometimes appending C<", stopped"> to your message | |
| 2252 | Hint: sometimes appending C<", stopped"> to your message | |
| 3467 | to make better sense when the string C<"at foo line 123"> is | |
| 2253 | will cause it to make better sense when the string C<"at foo line 123"> is | |
| 3468 | Suppose you are running script "canasta". | |
| 2254 | appended. Suppose you are running script "canasta". | |
| 3469 | 2255 | |
| 3470 | 2256 | =end original |
| 3471 | 2257 | |
| 3472 | 2258 | ヒント: メッセージの最後を C<", stopped"> のようなもので |
| 3473 | 2259 | 終わるようにしておけば、C<"at foo line 123"> のように |
| 3474 | 2260 | 追加されて、わかりやすくなります。 |
| 3475 | 2261 | "canasta" というスクリプトを実行しているとします。 |
| 3476 | 2262 | |
| 3477 | 2263 | die "/etc/games is no good"; |
| 3478 | 2264 | die "/etc/games is no good, stopped"; |
| 3479 | 2265 | |
| 3480 | 2266 | =begin original |
| 3481 | 2267 | |
| 3482 | 2268 | produce, respectively |
| 3483 | 2269 | |
| 3484 | 2270 | =end original |
| 3485 | 2271 | |
| 3486 | 2272 | これは、それぞれ以下のように表示します。 |
| 3487 | 2273 | |
| 3488 | 2274 | /etc/games is no good at canasta line 123. |
| 3489 | 2275 | /etc/games is no good, stopped at canasta line 123. |
| 3490 | 2276 | |
| 3491 | 2277 | =begin original |
| 3492 | 2278 | |
| 3493 | ||
| 2279 | See also exit(), warn(), and the Carp module. | |
| 3494 | already contains an exception value (typically from a previous | |
| 3495 | L<C<eval>|/eval EXPR>), then that value is reused after | |
| 3496 | appending C<"\t...propagated">. This is useful for propagating exceptions: | |
| 3497 | 2280 | |
| 3498 | 2281 | =end original |
| 3499 | 2282 | |
| 3500 | ||
| 2283 | exit() と warn() と Carp モジュールも参照してください。 | |
| 3501 | (典型的には前回の L<C<eval>|/eval EXPR> で) | |
| 3502 | 既に例外値を持っている場合、 | |
| 3503 | 値は C<"\t...propagated"> を追加した後再利用されます。 | |
| 3504 | これは例外を伝播させる場合に有効です: | |
| 3505 | 2284 | |
| 3506 | eval { ... }; | |
| 3507 | die unless $@ =~ /Expected exception/; | |
| 3508 | ||
| 3509 | 2285 | =begin original |
| 3510 | 2286 | |
| 3511 | If LIST | |
| 2287 | If LIST is empty and C<$@> already contains a value (typically from a | |
| 3512 | ||
| 2288 | previous eval) that value is reused after appending C<"\t...propagated">. | |
| 3513 | ||
| 2289 | This is useful for propagating exceptions: | |
| 3514 | with additional file and line number parameters. The return value | |
| 3515 | replaces the value in L<C<$@>|perlvar/$@>; i.e., as if | |
| 3516 | C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called. | |
| 3517 | 2290 | |
| 3518 | 2291 | =end original |
| 3519 | 2292 | |
| 3520 | ||
| 2293 | LIST が空で C<$@> が(典型的には前回の eval で)既に値を持っている場合、 | |
| 3521 | ||
| 2294 | 値は C<"\t...propagated"> を追加した後再利用されます。 | |
| 3522 | こ | |
| 2295 | これは例外を伝播させる場合に有効です: | |
| 3523 | 返り値は L<C<$@>|perlvar/$@> の値を置き換えます; | |
| 3524 | つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が | |
| 3525 | 呼び出されたかのようになります。 | |
| 3526 | 2296 | |
| 3527 | ||
| 2297 | eval { ... }; | |
| 2298 | die unless $@ =~ /Expected exception/; | |
| 3528 | 2299 | |
| 3529 | If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@> | |
| 3530 | is also empty, then the string C<"Died"> is used. | |
| 3531 | ||
| 3532 | =end original | |
| 3533 | ||
| 3534 | LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> も空の場合、 | |
| 3535 | C<"Died"> が使われます。 | |
| 3536 | ||
| 3537 | 2300 | =begin original |
| 3538 | 2301 | |
| 3539 | ||
| 2302 | If C<$@> is empty then the string C<"Died"> is used. | |
| 3540 | this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@> | |
| 3541 | contains that reference. This permits more elaborate exception handling | |
| 3542 | using objects that maintain arbitrary state about the exception. Such a | |
| 3543 | scheme is sometimes preferable to matching particular string values of | |
| 3544 | L<C<$@>|perlvar/$@> with regular expressions. | |
| 3545 | 2303 | |
| 3546 | 2304 | =end original |
| 3547 | 2305 | |
| 3548 | ||
| 2306 | C<$@> が空の場合、C<"Died"> が使われます。 | |
| 3549 | L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は | |
| 3550 | そのリファレンスを持ちます。 | |
| 3551 | これは、例外の性質について任意の状態を管理するオブジェクトを使った | |
| 3552 | より複雑な例外処理の実装を可能にします。 | |
| 3553 | このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って | |
| 3554 | マッチングするときに時々好まれます。 | |
| 3555 | 2307 | |
| 3556 | 2308 | =begin original |
| 3557 | 2309 | |
| 3558 | ||
| 2310 | die() can also be called with a reference argument. If this happens to be | |
| 3559 | ||
| 2311 | trapped within an eval(), $@ contains the reference. This behavior permits | |
| 3560 | exception | |
| 2312 | a more elaborate exception handling implementation using objects that | |
| 3561 | ||
| 2313 | maintain arbitrary state about the nature of the exception. Such a scheme | |
| 3562 | i | |
| 2314 | is sometimes preferable to matching particular string values of $@ using | |
| 3563 | ||
| 2315 | regular expressions. Here's an example: | |
| 3564 | without destroying it, Perl doesn't attempt to append location or other | |
| 3565 | information to a reference exception. If you want location information | |
| 3566 | with a complex exception object, you'll have to arrange to put the | |
| 3567 | location information into the object yourself. | |
| 3568 | 2316 | |
| 3569 | 2317 | =end original |
| 3570 | 2318 | |
| 3571 | ||
| 2319 | die() はリファレンス引数と共に呼び出すこともできます。 | |
| 3572 | このよう | |
| 2320 | eval() 内部でこのように呼び出された場合、$@ はリファレンスを持ちます。 | |
| 3573 | ||
| 2321 | この振る舞いは、例外の性質にすいて任意の状態を管理するオブジェクトを使った | |
| 3574 | ||
| 2322 | より複雑な例外ハンドリングの実装を可能にします。 | |
| 3575 | ||
| 2323 | このようなスキーマは $@ の特定の文字列値を正規表現を使って | |
| 3576 | ||
| 2324 | マッチングするときに時々好まれます。以下に例を示します: | |
| 3577 | また、例外オブジェクトリファレンスはそれを破壊することなく | |
| 3578 | 文字列化することができないので、Perl はリファレンス例外に位置や | |
| 3579 | その他の情報を追加しようとしません。 | |
| 3580 | 複雑な例外オブジェクトに位置情報が欲しい場合、 | |
| 3581 | オブジェクト自身に位置情報を設定するように用意する必要があります。 | |
| 3582 | 2325 | |
| 3583 | =begin original | |
| 3584 | ||
| 3585 | Because L<C<$@>|perlvar/$@> is a global variable, be careful that | |
| 3586 | analyzing an exception caught by C<eval> doesn't replace the reference | |
| 3587 | in the global variable. It's | |
| 3588 | easiest to make a local copy of the reference before any manipulations. | |
| 3589 | Here's an example: | |
| 3590 | ||
| 3591 | =end original | |
| 3592 | ||
| 3593 | L<C<$@>|perlvar/$@> はグローバル変数なので、 | |
| 3594 | C<eval> により補足された例外の解析はグローバル変数の | |
| 3595 | リファレンスを置き換えないことに注意を払わなければなりません。 | |
| 3596 | 他の操作をする前にリファレンスのローカルコピーを | |
| 3597 | 作るのが一番簡単です。 | |
| 3598 | 以下に例を示します: | |
| 3599 | ||
| 3600 | use Scalar::Util "blessed"; | |
| 3601 | ||
| 3602 | 2326 | eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; |
| 3603 | if ( | |
| 2327 | if ($@) { | |
| 3604 | if ( | |
| 2328 | if (ref($@) && UNIVERSAL::isa($@,"Some::Module::Exception")) { | |
| 3605 | && $ev_err->isa("Some::Module::Exception")) { | |
| 3606 | 2329 | # handle Some::Module::Exception |
| 3607 | 2330 | } |
| 3608 | 2331 | else { |
| 3609 | 2332 | # handle all other possible exceptions |
| 3610 | 2333 | } |
| 3611 | 2334 | } |
| 3612 | 2335 | |
| 3613 | 2336 | =begin original |
| 3614 | 2337 | |
| 3615 | ||
| 2338 | Because perl will stringify uncaught exception messages before displaying | |
| 3616 | ||
| 2339 | them, you may want to overload stringification operations on such custom | |
| 3617 | L< | |
| 2340 | exception objects. See L<overload> for details about that. | |
| 3618 | 2341 | |
| 3619 | 2342 | =end original |
| 3620 | 2343 | |
| 3621 | ||
| 2344 | perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、 | |
| 3622 | ||
| 2345 | このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと | |
| 3623 | ||
| 2346 | 思うかもしれません。 | |
| 2347 | これに関する詳細は L<overload> を参照してください。 | |
| 3624 | 2348 | |
| 3625 | exit $! if $!; # errno | |
| 3626 | exit $? >> 8 if $? >> 8; # child exit status | |
| 3627 | exit 255; # last resort | |
| 3628 | ||
| 3629 | 2349 | =begin original |
| 3630 | 2350 | |
| 3631 | ||
| 2351 | You can arrange for a callback to be run just before the C<die> | |
| 3632 | ||
| 2352 | does its deed, by setting the C<$SIG{__DIE__}> hook. The associated | |
| 3633 | al | |
| 2353 | handler will be called with the error text and can change the error | |
| 2354 | message, if it sees fit, by calling C<die> again. See | |
| 3635 | ||
| 2355 | L<perlvar/$SIG{expr}> for details on setting C<%SIG> entries, and | |
| 2356 | L<"eval BLOCK"> for some examples. Although this feature was meant | |
| 3637 | ||
| 2357 | to be run only right before your program was to exit, this is not | |
| 3638 | ||
| 2358 | currently the case--the C<$SIG{__DIE__}> hook is currently called | |
| 3639 | ||
| 2359 | even inside eval()ed blocks/strings! If one wants the hook to do | |
| 3640 | ||
| 3641 | =begin original | |
| 3642 | ||
| 3643 | The intent is to squeeze as much possible information about the likely cause | |
| 3644 | into the limited space of the system exit code. However, as | |
| 3645 | L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by | |
| 3646 | any system call, this means that the value of the exit code used by | |
| 3647 | L<C<die>|/die LIST> can be non-predictable, so should not be relied | |
| 3648 | upon, other than to be non-zero. | |
| 3649 | ||
| 3650 | =end original | |
| 3651 | ||
| 3652 | この意図は、できるだけ多くの似たような原因に関する情報を、システム終了 | |
| 3653 | コードという限られた領域に圧縮することです。 | |
| 3654 | しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の | |
| 3655 | C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は | |
| 3656 | 予測不能であることを意味するので、非 0 ということ以上にこの値に | |
| 3657 | 依存するべきではありません。 | |
| 3658 | ||
| 3659 | =begin original | |
| 3660 | ||
| 3661 | You can arrange for a callback to be run just before the | |
| 3662 | L<C<die>|/die LIST> does its deed, by setting the | |
| 3663 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called | |
| 3664 | with the exception as an argument, and can change the exception, | |
| 3665 | if it sees fit, by | |
| 3666 | calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on | |
| 3667 | setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some | |
| 3668 | examples. Although this feature was to be run only right before your | |
| 3669 | program was to exit, this is not currently so: the | |
| 3670 | L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside | |
| 3671 | L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do | |
| 3672 | 2360 | nothing in such situations, put |
| 3673 | 2361 | |
| 3674 | 2362 | =end original |
| 3675 | 2363 | |
| 3676 | ||
| 2364 | C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う | |
| 3677 | L<C<die>|/die LIST> がその行動を行う | |
| 3678 | 2365 | 直前に実行されるコールバックを設定できます。 |
| 3679 | 結び付けられたハンドラは | |
| 2366 | 結び付けられたハンドラはエラーテキストと共に呼び出され、 | |
| 3680 | 必要なら再び | |
| 2367 | 必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス。 | |
| 3681 | ||
| 2368 | C<%SIG> のエントリをセットする詳細については、L<perlvar/$SIG{expr}> を、 | |
| 3682 | ||
| 2369 | 例については L<"eval BLOCK"> を参照してください。 | |
| 3683 | この機能はプログラムが終了しようとする前に 1 回だけ実行 | |
| 2370 | この機能はプログラムが終了しようとする前に 1 回だけ実行されることを | |
| 3684 | 現在ではそうではありません | |
| 2371 | 意味していましたが、現在ではそうではありません -- | |
| 3685 | ||
| 2372 | C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも | |
| 3686 | ||
| 2373 | 呼ばれるのです! | |
| 3687 | 2374 | もしそのような状況で何もしなくない時は: |
| 3688 | 2375 | |
| 3689 | ||
| 2376 | die @_ if $^S; | |
| 3690 | 2377 | |
| 3691 | 2378 | =begin original |
| 3692 | 2379 | |
| 3693 | 2380 | as the first line of the handler (see L<perlvar/$^S>). Because |
| 3694 | 2381 | this promotes strange action at a distance, this counterintuitive |
| 3695 | behavior may be fixed in a future release. | |
| 2382 | behavior may be fixed in a future release. | |
| 3696 | 2383 | |
| 3697 | 2384 | =end original |
| 3698 | 2385 | |
| 3699 | 2386 | をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。 |
| 3700 | 2387 | これは離れたところで不思議な行動を引き起こすので、 |
| 3701 | 2388 | この直感的でない振る舞いは将来のリリースで修正されるかもしれません。 |
| 3702 | 2389 | |
| 3703 | =begin original | |
| 3704 | ||
| 3705 | See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp> | |
| 3706 | module. | |
| 3707 | ||
| 3708 | =end original | |
| 3709 | ||
| 3710 | L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも | |
| 3711 | 参照してください。 | |
| 3712 | ||
| 3713 | 2390 | =item do BLOCK |
| 3714 | X<do> X<block> | |
| 3715 | 2391 | |
| 3716 | =for Pod::Functions turn a BLOCK into a TERM | |
| 3717 | ||
| 3718 | 2392 | =begin original |
| 3719 | 2393 | |
| 3720 | 2394 | Not really a function. Returns the value of the last command in the |
| 3721 | sequence of commands indicated by BLOCK. When modified by | |
| 2395 | sequence of commands indicated by BLOCK. When modified by a loop | |
| 3722 | ||
| 2396 | modifier, executes the BLOCK once before testing the loop condition. | |
| 3723 | ||
| 2397 | (On other statements the loop modifiers test the conditional first.) | |
| 3724 | first.) | |
| 3725 | 2398 | |
| 3726 | 2399 | =end original |
| 3727 | 2400 | |
| 3728 | 2401 | 実際は関数ではありません。 |
| 3729 | 2402 | BLOCK で示されるコマンド列の最後の値を返します。 |
| 3730 | ||
| 2403 | ループ修飾子で修飾すると、 | |
| 3731 | 2404 | ループ条件を調べる前に 1 度、BLOCK を実行します。 |
| 3732 | 2405 | (これ以外の実行文は、ループ修飾子により、条件が最初に |
| 3733 | 2406 | 調べられます。) |
| 3734 | 2407 | |
| 3735 | 2408 | =begin original |
| 3736 | 2409 | |
| 3737 | 2410 | C<do BLOCK> does I<not> count as a loop, so the loop control statements |
| 3738 | ||
| 2411 | C<next>, C<last>, or C<redo> cannot be used to leave or restart the block. | |
| 3739 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
| 3740 | 2412 | See L<perlsyn> for alternative strategies. |
| 3741 | 2413 | |
| 3742 | 2414 | =end original |
| 3743 | 2415 | |
| 3744 | C<do BLOCK> はループとしては I<扱われません> | |
| 2416 | C<do BLOCK> はループとしては I<扱われません>。 | |
| 3745 | ||
| 2417 | 従って、C<next>, C<last>, C<redo> といったループ制御文は | |
| 3746 | 2418 | ブロックから抜けたり再開することはできません。 |
| 3747 | その他の戦略については L<perlsyn> を参照して | |
| 2419 | その他の戦略については L<perlsyn> を参照して下さい。 | |
| 3748 | 2420 | |
| 2421 | =item do SUBROUTINE(LIST) | |
| 2422 | ||
| 2423 | =begin original | |
| 2424 | ||
| 2425 | A deprecated form of subroutine call. See L<perlsub>. | |
| 2426 | ||
| 2427 | =end original | |
| 2428 | ||
| 2429 | 推奨されない形のサブルーチン呼び出しです。 | |
| 2430 | L<perlsub> を参照してください。 | |
| 2431 | ||
| 3749 | 2432 | =item do EXPR |
| 3750 | X<do> | |
| 3751 | 2433 | |
| 3752 | 2434 | =begin original |
| 3753 | 2435 | |
| 3754 | 2436 | Uses the value of EXPR as a filename and executes the contents of the |
| 3755 | file as a Perl script | |
| 2437 | file as a Perl script. Its primary use is to include subroutines | |
| 2438 | from a Perl subroutine library. | |
| 3756 | 2439 | |
| 3757 | 2440 | =end original |
| 3758 | 2441 | |
| 3759 | 2442 | EXPR の値をファイル名として用い、そのファイルの中身を |
| 3760 | Perl のスクリプトとして実行します | |
| 2443 | Perl のスクリプトとして実行します。 | |
| 2444 | 主に、Perl のサブルーチンライブラリからサブルーチンを | |
| 2445 | インクルードするために用います。 | |
| 3761 | 2446 | |
| 3762 | # load the exact specified file (./ and ../ special-cased) | |
| 3763 | do '/foo/stat.pl'; | |
| 3764 | do './stat.pl'; | |
| 3765 | do '../foo/stat.pl'; | |
| 3766 | ||
| 3767 | # search for the named file within @INC | |
| 3768 | 2447 | do 'stat.pl'; |
| 3769 | do 'foo/stat.pl'; | |
| 3770 | 2448 | |
| 3771 | 2449 | =begin original |
| 3772 | 2450 | |
| 3773 | ||
| 2451 | is just like | |
| 3774 | 2452 | |
| 3775 | 2453 | =end original |
| 3776 | 2454 | |
| 3777 | ||
| 2455 | は以下のものと同じようなものですが、 | |
| 3778 | 2456 | |
| 3779 | eval `cat stat.pl`; | |
| 2457 | scalar eval `cat stat.pl`; | |
| 3780 | 2458 | |
| 3781 | 2459 | =begin original |
| 3782 | 2460 | |
| 3783 | except that it's more concise, | |
| 2461 | except that it's more efficient and concise, keeps track of the current | |
| 3784 | ||
| 2462 | filename for error messages, searches the @INC libraries, and updates | |
| 3785 | ||
| 2463 | C<%INC> if the file is found. See L<perlvar/Predefined Names> for these | |
| 3786 | ||
| 2464 | variables. It also differs in that code evaluated with C<do FILENAME> | |
| 3787 | ||
| 2465 | cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the | |
| 3788 | ||
| 2466 | same, however, in that it does reparse the file every time you call it, | |
| 2467 | so you probably don't want to do this inside a loop. | |
| 3789 | 2468 | |
| 3790 | 2469 | =end original |
| 3791 | 2470 | |
| 3792 | より簡潔で | |
| 2471 | より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、 | |
| 2472 | カレントディレクトリでファイルが見つからなかったときに | |
| 2473 | @INC ライブラリを検索する、ファイルがあったときに C<%INC> を更新する、 | |
| 3793 | 2474 | といったことがあります。 |
| 3794 | ||
| 2475 | L<perlvar/Predefined Names> も参照してください。 | |
| 2476 | C<do FILENAME> で評価されたコードは、入れ子のスコープにある | |
| 3795 | 2477 | レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、 |
| 3796 | 2478 | という違いがあります。 |
| 3797 | 2479 | しかし、呼び出すたびにファイルを解析し直すという点では同じですから、 |
| 3798 | 2480 | ループ内でこれを使おうなどとは、間違っても思ったりしないように。 |
| 3799 | 2481 | |
| 3800 | 2482 | =begin original |
| 3801 | 2483 | |
| 3802 | ||
| 2484 | If C<do> cannot read the file, it returns undef and sets C<$!> to the | |
| 2485 | error. If C<do> can read the file but cannot compile it, it | |
| 2486 | returns undef and sets an error message in C<$@>. If the file is | |
| 2487 | successfully compiled, C<do> returns the value of the last expression | |
| 2488 | evaluated. | |
| 3803 | 2489 | |
| 3804 | 2490 | =end original |
| 3805 | 2491 | |
| 3806 | ||
| 2492 | C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に | |
| 2493 | エラーを設定します。 | |
| 2494 | C<do> がファイルを読み込めたがコンパイルできなかった場合、 | |
| 2495 | undef を返して C<$@> にエラーメッセージを設定します。 | |
| 2496 | ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。 | |
| 3807 | 2497 | |
| 3808 | do 'foo/stat.pl'; | |
| 3809 | ||
| 3810 | 2498 | =begin original |
| 3811 | 2499 | |
| 3812 | ||
| 2500 | Note that inclusion of library modules is better done with the | |
| 3813 | ||
| 2501 | C<use> and C<require> operators, which also do automatic error checking | |
| 3814 | and | |
| 2502 | and raise an exception if there's a problem. | |
| 3815 | whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the | |
| 3816 | current directory) making these two cases equivalent, that is no | |
| 3817 | longer necessarily the case, as '.' is not included in C<@INC> by default | |
| 3818 | in perl versions 5.26.0 onwards. Instead, perl will now warn: | |
| 3819 | 2503 | |
| 3820 | 2504 | =end original |
| 3821 | 2505 | |
| 3822 | ||
| 2506 | ライブラリモジュールのインクルードには、C<use> 演算子や | |
| 3823 | ||
| 2507 | C<require> 演算子を使った方がよいことに注意してください。 | |
| 3824 | これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。 | |
| 3825 | 特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を | |
| 3826 | 含んでいたのでこの二つの場合は等価でしたが、 | |
| 3827 | perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を | |
| 3828 | 含んでいないので、もはやそうではないことに注意してください。 | |
| 3829 | 代わりに、perl は次のような警告を出します: | |
| 3830 | ||
| 3831 | do "stat.pl" failed, '.' is no longer in @INC; | |
| 3832 | did you mean do "./stat.pl"? | |
| 3833 | ||
| 3834 | =begin original | |
| 3835 | ||
| 3836 | If L<C<do>|/do EXPR> can read the file but cannot compile it, it | |
| 3837 | returns L<C<undef>|/undef EXPR> and sets an error message in | |
| 3838 | L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it | |
| 3839 | returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check | |
| 3840 | L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also | |
| 3841 | sets L<C<$!>|perlvar/$!>. If the file is successfully compiled, | |
| 3842 | L<C<do>|/do EXPR> returns the value of the last expression evaluated. | |
| 3843 | ||
| 3844 | =end original | |
| 3845 | ||
| 3846 | L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、 | |
| 3847 | L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを | |
| 3848 | 設定します。 | |
| 3849 | L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して | |
| 3850 | L<C<$!>|perlvar/$!> にエラーを設定します。 | |
| 3851 | コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、 | |
| 3852 | 常に L<C<$@>|perlvar/$@> を先にチェックします。 | |
| 3853 | ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の | |
| 3854 | 値を返します。 | |
| 3855 | ||
| 3856 | =begin original | |
| 3857 | ||
| 3858 | Inclusion of library modules is better done with the | |
| 3859 | L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION> | |
| 3860 | operators, which also do automatic error checking and raise an exception | |
| 3861 | if there's a problem. | |
| 3862 | ||
| 3863 | =end original | |
| 3864 | ||
| 3865 | ライブラリモジュールのインクルードには、 | |
| 3866 | L<C<use>|/use Module VERSION LIST> 演算子や | |
| 3867 | L<C<require>|/require VERSION> 演算子を使った方がよいです; | |
| 3868 | 2508 | これらは自動的にエラーをチェックして、問題があれば例外を発生させます。 |
| 3869 | 2509 | |
| 3870 | 2510 | =begin original |
| 3871 | 2511 | |
| 3872 | You might like to use | |
| 2512 | You might like to use C<do> to read in a program configuration | |
| 3873 | ||
| 2513 | file. Manual error checking can be done this way: | |
| 3874 | 2514 | |
| 3875 | 2515 | =end original |
| 3876 | 2516 | |
| 3877 | ||
| 2517 | C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。 | |
| 3878 | 使いたいかもしれません。 | |
| 3879 | 2518 | 手動のエラーチェックは以下のようにして行えます: |
| 3880 | 2519 | |
| 3881 | # | |
| 2520 | # read in config files: system first, then user | |
| 3882 | # Beware of using relative pathnames here. | |
| 3883 | 2521 | for $file ("/share/prog/defaults.rc", |
| 3884 | "$ENV{HOME}/.someprogrc") | |
| 2522 | "$ENV{HOME}/.someprogrc") | |
| 3885 | | |
| 2523 | { | |
| 3886 | ||
| 2524 | unless ($return = do $file) { | |
| 3887 | ||
| 2525 | warn "couldn't parse $file: $@" if $@; | |
| 3888 | ||
| 2526 | warn "couldn't do $file: $!" unless defined $return; | |
| 3889 | ||
| 2527 | warn "couldn't run $file" unless $return; | |
| 3890 | ||
| 2528 | } | |
| 3891 | 2529 | } |
| 3892 | 2530 | |
| 3893 | 2531 | =item dump LABEL |
| 3894 | X<dump> X<core> X<undump> | |
| 3895 | 2532 | |
| 3896 | =item dump EXPR | |
| 3897 | ||
| 3898 | 2533 | =item dump |
| 3899 | 2534 | |
| 3900 | =for Pod::Functions create an immediate core dump | |
| 3901 | ||
| 3902 | 2535 | =begin original |
| 3903 | 2536 | |
| 3904 | 2537 | This function causes an immediate core dump. See also the B<-u> |
| 3905 | 2538 | command-line switch in L<perlrun>, which does the same thing. |
| 3906 | 2539 | Primarily this is so that you can use the B<undump> program (not |
| 3907 | 2540 | supplied) to turn your core dump into an executable binary after |
| 3908 | 2541 | having initialized all your variables at the beginning of the |
| 3909 | 2542 | program. When the new binary is executed it will begin by executing |
| 3910 | a C<goto LABEL> (with all the restrictions that | |
| 2543 | a C<goto LABEL> (with all the restrictions that C<goto> suffers). | |
| 3911 | suffers). | |
| 3912 | 2544 | Think of it as a goto with an intervening core dump and reincarnation. |
| 3913 | If C<LABEL> is omitted, restarts the program from the top. | |
| 2545 | If C<LABEL> is omitted, restarts the program from the top. | |
| 3914 | C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be | |
| 3915 | computed at run time, being otherwise identical to C<dump LABEL>. | |
| 3916 | 2546 | |
| 3917 | 2547 | =end original |
| 3918 | 2548 | |
| 3919 | 2549 | この関数は即座にコアダンプを行ないます。 |
| 3920 | 2550 | 同様のことを行う L<perlrun> の B<-u> オプションも参照してください。 |
| 3921 | 2551 | プログラムの先頭で、 |
| 3922 | 2552 | すべての変数を初期化したあとのコアダンプを B<undump> |
| 3923 | 2553 | プログラム(提供していません)を使って実行ファイルに返ることができます。 |
| 3924 | 2554 | この新しいバイナリが実行されると、C<goto LABEL> から始めます |
| 3925 | ( | |
| 2555 | (C<goto> に関する制限はすべて適用されます)。 | |
| 3926 | 2556 | コアダンプをはさんで再生する goto と考えてください。 |
| 3927 | 2557 | C<LABEL> が省略されると、プログラムを先頭から再開します。 |
| 3928 | Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される | |
| 3929 | 名前が使えます; その他は C<dump LABEL> と同一です。 | |
| 3930 | 2558 | |
| 3931 | 2559 | =begin original |
| 3932 | 2560 | |
| 3933 | 2561 | B<WARNING>: Any files opened at the time of the dump will I<not> |
| 3934 | 2562 | be open any more when the program is reincarnated, with possible |
| 3935 | resulting confusion | |
| 2563 | resulting confusion on the part of Perl. | |
| 3936 | 2564 | |
| 3937 | 2565 | =end original |
| 3938 | 2566 | |
| 3939 | B<警告>: dump 時点でオープンされていたファイルは、 | |
| 2567 | B<警告>: dump 時点でオープンされていたファイルは、 | |
| 3940 | 再生されたときには、もはやオープンされて | |
| 2568 | プログラムが再生されたときには、もはやオープンされていません。 | |
| 3941 | 混乱させる可能性があります。 | |
| 2569 | Perl を部分的に混乱させる可能性があります。 | |
| 3942 | 2570 | |
| 3943 | 2571 | =begin original |
| 3944 | 2572 | |
| 3945 | This function is now largely obsolete, | |
| 2573 | This function is now largely obsolete, partly because it's very | |
| 3946 | convert a core file into an executable | |
| 2574 | hard to convert a core file into an executable, and because the | |
| 3947 | as | |
| 2575 | real compiler backends for generating portable bytecode and compilable | |
| 2576 | C code have superseded it. | |
| 3948 | 2577 | |
| 3949 | 2578 | =end original |
| 3950 | 2579 | |
| 3951 | この関数は大幅に時代遅れのものです; | |
| 2580 | この関数は大幅に時代遅れのものです; 理由としては、コアファイルを | |
| 3952 | 実行形式に変換するのが非常に困難であること | |
| 2581 | 実行形式に変換するのが非常に困難であること、また移植性のある | |
| 3953 | ||
| 2582 | バイトコードとコンパイル可能な C コードが生成される | |
| 2583 | 実際のコンパイラバックエンドがこれを置き換えたことがあります。 | |
| 3954 | 2584 | |
| 3955 | 2585 | =begin original |
| 3956 | 2586 | |
| 3957 | ||
| 2587 | If you're looking to use L<dump> to speed up your program, consider | |
| 3958 | ||
| 2588 | generating bytecode or native C code as described in L<perlcc>. If | |
| 3959 | ||
| 2589 | you're just trying to accelerate a CGI script, consider using the | |
| 3960 | ||
| 2590 | C<mod_perl> extension to B<Apache>, or the CPAN module, Fast::CGI. | |
| 2591 | You might also consider autoloading or selfloading, which at least | |
| 2592 | make your program I<appear> to run faster. | |
| 3961 | 2593 | |
| 3962 | 2594 | =end original |
| 3963 | 2595 | |
| 3964 | ||
| 2596 | プログラムの速度を上げるために L<dump> を使うことを考えているなら、 | |
| 3965 | ||
| 2597 | L<perlcc> で記述されているような、バイトコードかネイティブな C コードを | |
| 3966 | すると | |
| 2598 | 生成することを検討してみてください。 | |
| 2599 | もし単に CGI スクリプトを高速化したいなら、B<Apache> の拡張である | |
| 2600 | C<mod_perl> や、CPAN モジュールである Fast::CGI を検討してみてください。 | |
| 2601 | 少なくともプログラムが速く動作する I<ようにみえる>、オートロードや | |
| 2602 | 自力ロードも検討してみてください。 | |
| 3967 | 2603 | |
| 3968 | =begin original | |
| 3969 | ||
| 3970 | Portability issues: L<perlport/dump>. | |
| 3971 | ||
| 3972 | =end original | |
| 3973 | ||
| 3974 | 移植性の問題: L<perlport/dump>。 | |
| 3975 | ||
| 3976 | 2604 | =item each HASH |
| 3977 | X<each> X<hash, iterator> | |
| 3978 | 2605 | |
| 3979 | =item each ARRAY | |
| 3980 | X<array, iterator> | |
| 3981 | ||
| 3982 | =for Pod::Functions retrieve the next key/value pair from a hash | |
| 3983 | ||
| 3984 | 2606 | =begin original |
| 3985 | 2607 | |
| 3986 | When called | |
| 2608 | When called in list context, returns a 2-element list consisting of the | |
| 3987 | ||
| 2609 | key and value for the next element of a hash, so that you can iterate over | |
| 3988 | ||
| 2610 | it. When called in scalar context, returns only the key for the next | |
| 3989 | element | |
| 2611 | element in the hash. | |
| 3990 | this a syntax error. When called in scalar context, returns only the key | |
| 3991 | (not the value) in a hash, or the index in an array. | |
| 3992 | 2612 | |
| 3993 | 2613 | =end original |
| 3994 | 2614 | |
| 3995 | ||
| 2615 | リストコンテキストで呼び出した場合は、 | |
| 3996 | ハッシュの | |
| 2616 | ハッシュの次の 要素 に対する、key と 要素 からなる | |
| 3997 | ||
| 2617 | 2 要素のリストを返しますので、ハッシュ上での繰り返しを | |
| 3998 | ||
| 2618 | 行なうことができます。 | |
| 3999 | 文法エラーと考えられます。 | |
| 4000 | 2619 | スカラコンテキストで呼び出した場合は、 |
| 4001 | ハッシュの | |
| 2620 | ハッシュの次の要素のための key を返します。 | |
| 4002 | 2621 | |
| 4003 | 2622 | =begin original |
| 4004 | 2623 | |
| 4005 | ||
| 2624 | Entries are returned in an apparently random order. The actual random | |
| 4006 | order is s | |
| 2625 | order is subject to change in future versions of perl, but it is guaranteed | |
| 4007 | on t | |
| 2626 | to be in the same order as either the C<keys> or C<values> function | |
| 4008 | ||
| 2627 | would produce on the same (unmodified) hash. | |
| 4009 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 4010 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 4011 | long as a given hash is unmodified you may rely on | |
| 4012 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
| 4013 | L<C<each>|/each HASH> to repeatedly return the same order | |
| 4014 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 4015 | details on why hash order is randomized. Aside from the guarantees | |
| 4016 | provided here the exact details of Perl's hash algorithm and the hash | |
| 4017 | traversal order are subject to change in any release of Perl. | |
| 4018 | 2628 | |
| 4019 | 2629 | =end original |
| 4020 | 2630 | |
| 4021 | ||
| 2631 | エントリは見かけ上、ランダムな順序で返されます。 | |
| 4022 | 実際のランダムな順 | |
| 2632 | 実際のランダムな順番は perl の将来のバージョンでは変わるかもしれませんが、 | |
| 4023 | ||
| 2633 | C<keys> や C<values> 関数が同じ(変更されていない)ハッシュに対して | |
| 4024 | ||
| 2634 | 生成するのと同じ順番であることは保証されます。 | |
| 4025 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 4026 | 最近のキーは順序を変えることなく削除できます。 | |
| 4027 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 4028 | L<C<each>|/each HASH> が繰り返し同じ順序で | |
| 4029 | 返すことに依存してもかまいません。 | |
| 4030 | なぜハッシュの順序がランダム化されているかの詳細については | |
| 4031 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
| 4032 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
| 4033 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
| 4034 | 2635 | |
| 4035 | 2636 | =begin original |
| 4036 | 2637 | |
| 4037 | ||
| 2638 | When the hash is entirely read, a null array is returned in list context | |
| 4038 | ||
| 2639 | (which when assigned produces a false (C<0>) value), and C<undef> in | |
| 4039 | ||
| 2640 | scalar context. The next call to C<each> after that will start iterating | |
| 4040 | ||
| 2641 | again. There is a single iterator for each hash, shared by all C<each>, | |
| 4041 | ||
| 2642 | C<keys>, and C<values> function calls in the program; it can be reset by | |
| 4042 | ||
| 2643 | reading all the elements from the hash, or by evaluating C<keys HASH> or | |
| 4043 | ||
| 2644 | C<values HASH>. If you add or delete elements of a hash while you're | |
| 4044 | ||
| 2645 | iterating over it, you may get entries skipped or duplicated, so | |
| 4045 | o | |
| 2646 | don't. Exception: It is always safe to delete the item most recently | |
| 4046 | t | |
| 2647 | returned by C<each()>, which means that the following code will work: | |
| 4047 | a hash's elements while iterating over it, the effect on the iterator is | |
| 4048 | unspecified; for example, entries may be skipped or duplicated--so don't | |
| 4049 | do that. Exception: It is always safe to delete the item most recently | |
| 4050 | returned by L<C<each>|/each HASH>, so the following code works properly: | |
| 4051 | 2648 | |
| 4052 | 2649 | =end original |
| 4053 | 2650 | |
| 4054 | ||
| 2651 | ハッシュをすべて読み込んでしまうと、リストコンテキストでは空配列が | |
| 4055 | ||
| 2652 | 返されます(これは代入されると、偽 (C<0>) となります)。 | |
| 4056 | ||
| 2653 | スカラコンテキストでは C<undef> が返されます。 | |
| 4057 | ||
| 2654 | そのあと、もう一度 C<each> を呼び出すと、 | |
| 4058 | ||
| 2655 | 再び繰り返しを始めます。 | |
| 4059 | ||
| 2656 | ハッシュごとに反復子が 1 つあり、プログラム中のすべての | |
| 4060 | ||
| 2657 | C<each> 関数、C<keys> 関数、C<values> 関数で共用されます。 | |
| 4061 | ||
| 2658 | 反復子は、配列の要素をすべて読むことによって、またはC<keys HASH>, | |
| 4062 | ||
| 2659 | C<values HASH>を評価することでリセットすることができます。 | |
| 4063 | (配列ではなく)ハッシュを参照ことで明示的にリセットできます。 | |
| 4064 | 2660 | 繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、 |
| 4065 | ||
| 2661 | 要素が飛ばされたり重複したりするので、してはいけません。 | |
| 4066 | ||
| 2662 | 例外: 一番最近に C<each()> から返されたものを削除するのは常に安全です。 | |
| 4067 | ||
| 2663 | これは以下のようなコードが正しく動くことを意味します: | |
| 4068 | 安全です; これは以下のようなコードが正しく動くことを意味します: | |
| 4069 | 2664 | |
| 4070 | while ( | |
| 2665 | while (($key, $value) = each %hash) { | |
| 4071 | print $key, "\n"; | |
| 2666 | print $key, "\n"; | |
| 4072 | delete $hash{$key}; # This is safe | |
| 2667 | delete $hash{$key}; # This is safe | |
| 4073 | } | |
| 2668 | } | |
| 4074 | 2669 | |
| 4075 | 2670 | =begin original |
| 4076 | 2671 | |
| 4077 | T | |
| 2672 | The following prints out your environment like the printenv(1) program, | |
| 4078 | ||
| 2673 | only in a different order: | |
| 4079 | 2674 | |
| 4080 | 2675 | =end original |
| 4081 | 2676 | |
| 4082 | ||
| 2677 | 以下のプログラムは、順番が異なるものの、 | |
| 2678 | printenv(1) プログラムのように環境変数を表示します: | |
| 4083 | 2679 | |
| 4084 | ||
| 2680 | while (($key,$value) = each %ENV) { | |
| 2681 | print "$key=$value\n"; | |
| 4086 | The iterator used by C<each> is attached to the hash or array, and is | |
| 4087 | shared between all iteration operations applied to the same hash or array. | |
| 4088 | Thus all uses of C<each> on a single hash or array advance the same | |
| 4089 | iterator location. All uses of C<each> are also subject to having the | |
| 4090 | iterator reset by any use of C<keys> or C<values> on the same hash or | |
| 4091 | array, or by the hash (but not array) being referenced in list context. | |
| 4092 | This makes C<each>-based loops quite fragile: it is easy to arrive at | |
| 4093 | such a loop with the iterator already part way through the object, or to | |
| 4094 | accidentally clobber the iterator state during execution of the loop body. | |
| 4095 | It's easy enough to explicitly reset the iterator before starting a loop, | |
| 4096 | but there is no way to insulate the iterator state used by a loop from | |
| 4097 | the iterator state used by anything else that might execute during the | |
| 4098 | loop body. To avoid these problems, use a C<foreach> loop rather than | |
| 4099 | C<while>-C<each>. | |
| 4100 | ||
| 4101 | =end original | |
| 4102 | ||
| 4103 | C<each> で使われる反復子はハッシュや配列に付随し、 | |
| 4104 | 同じハッシュや配列に適用される全ての反復操作の間で共有されます。 | |
| 4105 | 従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を | |
| 4106 | 進めます。 | |
| 4107 | また、全ての C<each> は、同じハッシュまたはキーに対する | |
| 4108 | C<keys> や C<values> の使用によって、または | |
| 4109 | (リストではなく)ハッシュがリストコンテキストで参照されることによって、 | |
| 4110 | 反復子がリセットされることになります。 | |
| 4111 | これは、C<each> を基にしたループをかなり不安定にします: | |
| 4112 | そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、 | |
| 4113 | ループ本体の実行中に誤って反復子の状態を壊すことは容易です。 | |
| 4114 | ループを始める前に反復子を明示的にリセットするのは十分容易ですが、 | |
| 4115 | ループ本体の間に実行しているかもしれない他の何かによって使われている | |
| 4116 | 反復子の状態から、 | |
| 4117 | ループによって使われている反復子の状態を分離する方法はありません。 | |
| 4118 | これらの問題を避けるには、C<while>-C<each> ではなく | |
| 4119 | C<foreach> ループを使ってください。 | |
| 4120 | ||
| 4121 | =begin original | |
| 4122 | ||
| 4123 | This prints out your environment like the L<printenv(1)> program, | |
| 4124 | but in a different order: | |
| 4125 | ||
| 4126 | =end original | |
| 4127 | ||
| 4128 | これは、L<printenv(1)> プログラムのように環境変数を表示しますが、 | |
| 4129 | 順序は異なっています: | |
| 4130 | ||
| 4131 | while (my ($key,$value) = each %ENV) { | |
| 4132 | print "$key=$value\n"; | |
| 4133 | 2682 | } |
| 4134 | 2683 | |
| 4135 | 2684 | =begin original |
| 4136 | 2685 | |
| 4137 | S | |
| 2686 | See also C<keys>, C<values> and C<sort>. | |
| 4138 | L<C<each>|/each HASH> to take a scalar expression. This experiment has | |
| 4139 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
| 4140 | 2687 | |
| 4141 | 2688 | =end original |
| 4142 | 2689 | |
| 4143 | ||
| 2690 | C<keys> や C<values> や C<sort> も参照してください。 | |
| 4144 | 実験的機能がありました。 | |
| 4145 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 4146 | 2691 | |
| 4147 | =begin original | |
| 4148 | ||
| 4149 | As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while> | |
| 4150 | loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
| 4151 | If either an C<each> expression or an explicit assignment of an C<each> | |
| 4152 | expression to a scalar is used as a C<while>/C<for> condition, then | |
| 4153 | the condition actually tests for definedness of the expression's value, | |
| 4154 | not for its regular truth value. | |
| 4155 | ||
| 4156 | =end original | |
| 4157 | ||
| 4158 | Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます; | |
| 4159 | これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。 | |
| 4160 | C<each> 式または C<each> 式からスカラへの明示的な代入が | |
| 4161 | C<while>/C<for> の条件部として使われた場合、 | |
| 4162 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 4163 | テストします。 | |
| 4164 | ||
| 4165 | while (each %ENV) { | |
| 4166 | print "$_=$ENV{$_}\n"; | |
| 4167 | } | |
| 4168 | ||
| 4169 | =begin original | |
| 4170 | ||
| 4171 | To avoid confusing would-be users of your code who are running earlier | |
| 4172 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
| 4173 | the top of your file to signal that your code will work I<only> on Perls of | |
| 4174 | a recent vintage: | |
| 4175 | ||
| 4176 | =end original | |
| 4177 | ||
| 4178 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
| 4179 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
| 4180 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
| 4181 | 書いてください: | |
| 4182 | ||
| 4183 | use 5.012; # so keys/values/each work on arrays | |
| 4184 | use 5.018; # so each assigns to $_ in a lone while test | |
| 4185 | ||
| 4186 | =begin original | |
| 4187 | ||
| 4188 | See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and | |
| 4189 | L<C<sort>|/sort SUBNAME LIST>. | |
| 4190 | ||
| 4191 | =end original | |
| 4192 | ||
| 4193 | L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や | |
| 4194 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
| 4195 | ||
| 4196 | 2692 | =item eof FILEHANDLE |
| 4197 | X<eof> | |
| 4198 | X<end of file> | |
| 4199 | X<end-of-file> | |
| 4200 | 2693 | |
| 4201 | 2694 | =item eof () |
| 4202 | 2695 | |
| 4203 | 2696 | =item eof |
| 4204 | 2697 | |
| 4205 | =for Pod::Functions test a filehandle for its end | |
| 4206 | ||
| 4207 | 2698 | =begin original |
| 4208 | 2699 | |
| 4209 | Returns 1 if the next read on FILEHANDLE will return end of file | |
| 2700 | Returns 1 if the next read on FILEHANDLE will return end of file, or if | |
| 4210 | 2701 | FILEHANDLE is not open. FILEHANDLE may be an expression whose value |
| 4211 | 2702 | gives the real filehandle. (Note that this function actually |
| 4212 | reads a character and then C<ungetc>s it, so isn't useful in an | |
| 2703 | reads a character and then C<ungetc>s it, so isn't very useful in an | |
| 4213 | 2704 | interactive context.) Do not read from a terminal file (or call |
| 4214 | 2705 | C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such |
| 4215 | 2706 | as terminals may lose the end-of-file condition if you do. |
| 4216 | 2707 | |
| 4217 | 2708 | =end original |
| 4218 | 2709 | |
| 4219 | 次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、 | |
| 2710 | 次に FILEHANDLE 上で読み込みを行なったときに、 EOF が返されるときか、 | |
| 4220 | ||
| 2711 | FILEHANDLE がオープンされていないと、1 を返します。 | |
| 4221 | 2712 | FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。 |
| 4222 | 2713 | (この関数は、実際に文字を読み、C<ungetc> を行ないますので、 |
| 4223 | 対話型の場合には有用ではありません。) | |
| 2714 | 対話型の場合には、それ程有用ではありません。) | |
| 4224 | 2715 | 端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を |
| 4225 | 2716 | 呼び出したりしてはいけません。 |
| 4226 | 2717 | そのようなことをすると、端末のようなファイルタイプは |
| 4227 | 2718 | EOF 状態を失ってしまうかもしれません。 |
| 4228 | 2719 | |
| 4229 | 2720 | =begin original |
| 4230 | 2721 | |
| 4231 | An | |
| 2722 | An C<eof> without an argument uses the last file read. Using C<eof()> | |
| 4232 | ||
| 2723 | with empty parentheses is very different. It refers to the pseudo file | |
| 4233 | ||
| 2724 | formed from the files listed on the command line and accessed via the | |
| 4234 | ||
| 2725 | C<< <> >> operator. Since C<< <> >> isn't explicitly opened, | |
| 4235 | ||
| 2726 | as a normal filehandle is, an C<eof()> before C<< <> >> has been | |
| 4236 | ||
| 2727 | used will cause C<@ARGV> to be examined to determine if input is | |
| 4237 | ||
| 2728 | available. | |
| 4238 | available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >> | |
| 4239 | has returned end-of-file will assume you are processing another | |
| 4240 | L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set | |
| 4241 | L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see | |
| 4242 | L<perlop/"I/O Operators">. | |
| 4243 | 2729 | |
| 4244 | 2730 | =end original |
| 4245 | 2731 | |
| 4246 | 引数を省略した | |
| 2732 | 引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。 | |
| 4247 | ||
| 2733 | 空の括弧をつけた C<eof()> は大きく異なります。 | |
| 4248 | 空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。 | |
| 4249 | 2734 | これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で |
| 4250 | 2735 | アクセスされる擬似ファイルを示すために用いられます。 |
| 4251 | 2736 | 通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、 |
| 4252 | C<< <> >> を使う前に | |
| 2737 | C<< <> >> を使う前に C<eof()> を使うと、 | |
| 4253 | 入力が正常か確認するために | |
| 2738 | 入力が正常か確認するために C<@ARGV> がテストされます。 | |
| 4254 | 同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、 | |
| 4255 | 他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし | |
| 4256 | L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます; | |
| 4257 | L<perlop/"I/O Operators"> を参照してください。 | |
| 4258 | 2739 | |
| 4259 | 2740 | =begin original |
| 4260 | 2741 | |
| 4261 | In a C<< while (<>) >> loop, | |
| 2742 | In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to | |
| 4262 | ||
| 2743 | detect the end of each file, C<eof()> will only detect the end of the | |
| 4263 | ||
| 2744 | last file. Examples: | |
| 4264 | only. Examples: | |
| 4265 | 2745 | |
| 4266 | 2746 | =end original |
| 4267 | 2747 | |
| 4268 | 2748 | C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、 |
| 4269 | ||
| 2749 | C<eof> か C<eof(ARGV)> を用います。 | |
| 4270 | ||
| 2750 | C<eof()> は最後のファイルの終わりのみを調べます。 | |
| 4271 | 2751 | 例: |
| 4272 | 2752 | |
| 4273 | 2753 | # reset line numbering on each input file |
| 4274 | 2754 | while (<>) { |
| 4275 | ||
| 2755 | next if /^\s*#/; # skip comments | |
| 4276 | ||
| 2756 | print "$.\t$_"; | |
| 4277 | 2757 | } continue { |
| 4278 | ||
| 2758 | close ARGV if eof; # Not eof()! | |
| 4279 | 2759 | } |
| 4280 | 2760 | |
| 4281 | 2761 | # insert dashes just before last line of last file |
| 4282 | 2762 | while (<>) { |
| 4283 | ||
| 2763 | if (eof()) { # check for end of current file | |
| 4284 | ||
| 2764 | print "--------------\n"; | |
| 4285 | | |
| 2765 | close(ARGV); # close or last; is needed if we | |
| 4286 | | |
| 2766 | # are reading from the terminal | |
| 4287 | ||
| 2767 | } | |
| 2768 | print; | |
| 4288 | 2769 | } |
| 4289 | 2770 | |
| 4290 | 2771 | =begin original |
| 4291 | 2772 | |
| 4292 | Practical hint: you almost never need to use | |
| 2773 | Practical hint: you almost never need to use C<eof> in Perl, because the | |
| 4293 | in | |
| 2774 | input operators typically return C<undef> when they run out of data, or if | |
| 4294 | ||
| 2775 | there was an error. | |
| 4295 | 2776 | |
| 4296 | 2777 | =end original |
| 4297 | 2778 | |
| 4298 | 現実的なヒント: Perl で | |
| 2779 | 現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません。 | |
| 4299 | ||
| 2780 | 基本的には、 | |
| 4300 | ||
| 2781 | データがなくなったときやエラーがあったときに、入力演算子が | |
| 4301 | ||
| 2782 | C<undef> を返してくれるからです。 | |
| 4302 | 2783 | |
| 4303 | 2784 | =item eval EXPR |
| 4304 | X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute> | |
| 4305 | X<error, handling> X<exception, handling> | |
| 4306 | 2785 | |
| 4307 | 2786 | =item eval BLOCK |
| 4308 | 2787 | |
| 4309 | =item eval | |
| 4310 | ||
| 4311 | =for Pod::Functions catch exceptions or compile and run code | |
| 4312 | ||
| 4313 | 2788 | =begin original |
| 4314 | 2789 | |
| 4315 | ||
| 2790 | In the first form, the return value of EXPR is parsed and executed as if it | |
| 4316 | ||
| 2791 | were a little Perl program. The value of the expression (which is itself | |
| 2792 | determined within scalar context) is first parsed, and if there weren't any | |
| 2793 | errors, executed in the lexical context of the current Perl program, so | |
| 2794 | that any variable settings or subroutine and format definitions remain | |
| 2795 | afterwards. Note that the value is parsed every time the eval executes. | |
| 2796 | If EXPR is omitted, evaluates C<$_>. This form is typically used to | |
| 2797 | delay parsing and subsequent execution of the text of EXPR until run time. | |
| 4317 | 2798 | |
| 4318 | 2799 | =end original |
| 4319 | 2800 | |
| 4320 | ||
| 2801 | 第一の形式では、EXPR の返り値が Perl のプログラムであるかのように | |
| 4321 | ||
| 2802 | 解析され、実行されます。 | |
| 4322 | ||
| 2803 | 式の値(それ自身スカラコンテキストの中で決定される)はまずパースされ、 | |
| 2804 | エラーがなければ | |
| 2805 | Perl プログラムのレキシカルコンテキストの中で実行されますので、変数の設定、 | |
| 2806 | サブルーチンやフォーマットの定義は、その後も残っています。 | |
| 2807 | 返される値は eval が実行されるごとにパースされます。 | |
| 2808 | サブルーチン同様に、最後に評価した式の値か、return 文の値です。 | |
| 2809 | EXPR を省略すると、C<$_> を評価します。 | |
| 2810 | この形は主に EXPR のテキストのパースと実行を実行時にまで | |
| 2811 | 遅延させるのに用います。 | |
| 4323 | 2812 | |
| 4324 | 2813 | =begin original |
| 4325 | 2814 | |
| 4326 | ||
| 2815 | In the second form, the code within the BLOCK is parsed only once--at the | |
| 4327 | ||
| 2816 | same time the code surrounding the eval itself was parsed--and executed | |
| 4328 | th | |
| 2817 | within the context of the current Perl program. This form is typically | |
| 4329 | ||
| 2818 | used to trap exceptions more efficiently than the first (see below), while | |
| 4330 | ||
| 2819 | also providing the benefit of checking the code within BLOCK at compile | |
| 4331 | ||
| 2820 | time. | |
| 4332 | of the current Perl program. This form is typically used to delay | |
| 4333 | parsing and subsequent execution of the text of EXPR until run time. | |
| 4334 | Note that the value is parsed every time the C<eval> executes. | |
| 4335 | 2821 | |
| 4336 | 2822 | =end original |
| 4337 | 2823 | |
| 4338 | ||
| 2824 | 第二の形式では、BLOCK 内部のコードは一度だけパースされ--コードを | |
| 4339 | ||
| 2825 | 囲む eval 自身がパースされるのと同じ時点です--現在の Perl プログラムの | |
| 4340 | ||
| 2826 | コンテキストで実行されます。 | |
| 4341 | ||
| 2827 | この形式は典型的には第一の形式より効率的に例外をトラップします(後述)。 | |
| 4342 | ||
| 2828 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 | |
| 4343 | 式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、 | |
| 4344 | エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして | |
| 4345 | 実行されます。 | |
| 4346 | この形は主に EXPR のテキストのパースと実行を実行時にまで | |
| 4347 | 遅延させるのに用います。 | |
| 4348 | 返される値は C<eval> が実行されるごとにパースされることに注意してください。 | |
| 4349 | 2829 | |
| 4350 | 2830 | =begin original |
| 4351 | 2831 | |
| 4352 | The | |
| 2832 | The final semicolon, if any, may be omitted from the value of EXPR or within | |
| 4353 | ||
| 2833 | the BLOCK. | |
| 4354 | time the code surrounding the C<eval> itself was parsed) and executed | |
| 4355 | within the context of the current Perl program. This form is typically | |
| 4356 | used to trap exceptions more efficiently than the first, while also | |
| 4357 | providing the benefit of checking the code within BLOCK at compile time. | |
| 4358 | BLOCK is parsed and compiled just once. Since errors are trapped, it | |
| 4359 | often is used to check if a given feature is available. | |
| 4360 | 2834 | |
| 4361 | 2835 | =end original |
| 4362 | 2836 | |
| 4363 | ||
| 2837 | 最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から省くことができます。 | |
| 4364 | これは文字列 eval ほど一般的ではありませんが、 | |
| 4365 | BLOCK 内部のコードは一度だけパースされ (コードを | |
| 4366 | 囲む C<eval> 自身がパースされるのと同じ時点です) 現在の | |
| 4367 | Perl プログラムのコンテキストで実行されます。 | |
| 4368 | この形式は典型的には第一の形式より効率的に例外をトラップします; | |
| 4369 | また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。 | |
| 4370 | BLOCK は一度だけパース及びコンパイルされます。 | |
| 4371 | エラーはトラップされてるので、しばしば与えられた機能が利用可能かを | |
| 4372 | チェックするために使われます。 | |
| 4373 | 2838 | |
| 4374 | 2839 | =begin original |
| 4375 | 2840 | |
| 4376 | 2841 | In both forms, the value returned is the value of the last expression |
| 4377 | evaluated inside the mini-program; a return statement may also | |
| 2842 | evaluated inside the mini-program; a return statement may be also used, just | |
| 4378 | 2843 | as with subroutines. The expression providing the return value is evaluated |
| 4379 | in void, scalar, or list context, depending on the context of the | |
| 2844 | in void, scalar, or list context, depending on the context of the eval itself. | |
| 4380 | ||
| 2845 | See L</wantarray> for more on how the evaluation context can be determined. | |
| 4381 | on how the evaluation context can be determined. | |
| 4382 | 2846 | |
| 4383 | 2847 | =end original |
| 4384 | 2848 | |
| 4385 | 2849 | どちらの形式でも、返される値はミニプログラムの内部で最後に評価された |
| 4386 | 表現の値です; サブルーチンと同様、return | |
| 2850 | 表現の値です; サブルーチンと同様、return ステートメントも使えます。 | |
| 4387 | 返り値として提供される表現は、 | |
| 2851 | 返り値として提供される表現は、eval 自身のコンテキストに依存して | |
| 4388 | ||
| 2852 | 無効・スカラ・リストのいずれかのコンテキストで評価されます。 | |
| 4389 | 評価コンテキストの決定方法についての詳細は L< | |
| 2853 | 評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。 | |
| 4390 | 参照してください。 | |
| 4391 | 2854 | |
| 4392 | 2855 | =begin original |
| 4393 | 2856 | |
| 4394 | If there is a syntax error or runtime error, or a | |
| 2857 | If there is a syntax error or runtime error, or a C<die> statement is | |
| 4395 | ||
| 2858 | executed, an undefined value is returned by C<eval>, and C<$@> is set to the | |
| 4396 | ||
| 2859 | error message. If there was no error, C<$@> is guaranteed to be a null | |
| 4397 | ||
| 2860 | string. Beware that using C<eval> neither silences perl from printing | |
| 4398 | ||
| 2861 | warnings to STDERR, nor does it stuff the text of warning messages into C<$@>. | |
| 4399 | ||
| 2862 | To do either of those, you have to use the C<$SIG{__WARN__}> facility. See | |
| 4400 | ||
| 2863 | L</warn> and L<perlvar>. | |
| 4401 | operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can | |
| 4402 | bypass the setting of L<C<$@>|perlvar/$@>. Beware that using | |
| 4403 | C<eval> neither silences Perl from printing warnings to | |
| 4404 | STDERR, nor does it stuff the text of warning messages into | |
| 4405 | L<C<$@>|perlvar/$@>. To do either of those, you have to use the | |
| 4406 | L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside | |
| 4407 | the BLOCK or EXPR using S<C<no warnings 'all'>>. See | |
| 4408 | L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>. | |
| 4409 | 2864 | |
| 4410 | 2865 | =end original |
| 4411 | 2866 | |
| 4412 | 構文エラーや実行エラーが発生するか、 | |
| 2867 | 構文エラーや実行エラーが発生するか、C<die> 文が実行されると、 | |
| 4413 | C<eval> | |
| 2868 | C<eval> の値として未定義値が返され、C<$@> にエラーメッセージが設定されます。 | |
| 4414 | ||
| 2869 | エラーがなければ、C<$@> は、空文字列であることが保証されます。 | |
| 4415 | L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。 | |
| 4416 | (5.16 以前では、バグによって、リストコンテキストで構文エラーの時には | |
| 4417 | L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には | |
| 4418 | 返していませんでした。) | |
| 4419 | エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。 | |
| 4420 | L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は | |
| 4421 | L<C<$@>|perlvar/$@> の設定を回避できます。 | |
| 4422 | 2870 | C<eval> を、STDERR に警告メッセージを表示させない目的や、 |
| 4423 | 警告メッセージを | |
| 2871 | 警告メッセージを C<$@> に格納する目的では使わないでください。 | |
| 4424 | そのような用途では、 | |
| 2872 | そのような用途では、C<$SIG{__WARN__}> 機能を使わなければなりません。 | |
| 4425 | ||
| 2873 | L</warn> と L<perlvar> を参照してください。 | |
| 4426 | オフにする必要があります。 | |
| 4427 | L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。 | |
| 4428 | 2874 | |
| 4429 | 2875 | =begin original |
| 4430 | 2876 | |
| 4431 | Note that, because C<eval> traps otherwise-fatal errors, | |
| 2877 | Note that, because C<eval> traps otherwise-fatal errors, it is useful for | |
| 4432 | ||
| 2878 | determining whether a particular feature (such as C<socket> or C<symlink>) | |
| 4433 | ||
| 2879 | is implemented. It is also Perl's exception trapping mechanism, where | |
| 4434 | ||
| 2880 | the die operator is used to raise exceptions. | |
| 4435 | Perl's exception-trapping mechanism, where the L<C<die>|/die LIST> | |
| 4436 | operator is used to raise exceptions. | |
| 4437 | 2881 | |
| 4438 | 2882 | =end original |
| 4439 | 2883 | |
| 4440 | C<eval> は、致命的エラーとなるようなものを | |
| 2884 | C<eval> は、致命的エラーとなるようなものをトラップすることができますから、 | |
| 4441 | ||
| 2885 | (C<socket> や C<symlink> といった) 特定の機能が実装されているかを、 | |
| 4442 | (L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や | |
| 4443 | L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が | |
| 4444 | 実装されているかを、 | |
| 4445 | 2886 | 調べるために使うことができることに注意してください。 |
| 4446 | ||
| 2887 | die 演算子が例外を発生させるものとすれば、 | |
| 4447 | Perl の例外捕捉機能と捉えることもできます。 | |
| 2888 | これはまた、Perl の例外捕捉機能と捉えることもできます。 | |
| 4448 | 2889 | |
| 4449 | 2890 | =begin original |
| 4450 | 2891 | |
| 4451 | Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before | |
| 4452 | restoration | |
| 4453 | of localized variables, which means that for your code to run on older | |
| 4454 | versions, a temporary is required if you want to mask some, but not all | |
| 4455 | errors: | |
| 4456 | ||
| 4457 | =end original | |
| 4458 | ||
| 4459 | Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の | |
| 4460 | 復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの | |
| 4461 | エラーをマスクしたい場合には一時変数が必要です: | |
| 4462 | ||
| 4463 | # alter $@ on nefarious repugnancy only | |
| 4464 | { | |
| 4465 | my $e; | |
| 4466 | { | |
| 4467 | local $@; # protect existing $@ | |
| 4468 | eval { test_repugnancy() }; | |
| 4469 | # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only | |
| 4470 | $@ =~ /nefarious/ and $e = $@; | |
| 4471 | } | |
| 4472 | die $e if defined $e | |
| 4473 | } | |
| 4474 | ||
| 4475 | =begin original | |
| 4476 | ||
| 4477 | There are some different considerations for each form: | |
| 4478 | ||
| 4479 | =end original | |
| 4480 | ||
| 4481 | それぞれの型式について、異なった考慮事項があります: | |
| 4482 | ||
| 4483 | =over 4 | |
| 4484 | ||
| 4485 | =item String eval | |
| 4486 | ||
| 4487 | (文字列 eval) | |
| 4488 | ||
| 4489 | =begin original | |
| 4490 | ||
| 4491 | Since the return value of EXPR is executed as a block within the lexical | |
| 4492 | context of the current Perl program, any outer lexical variables are | |
| 4493 | visible to it, and any package variable settings or subroutine and | |
| 4494 | format definitions remain afterwards. | |
| 4495 | ||
| 4496 | =end original | |
| 4497 | ||
| 4498 | EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で | |
| 4499 | 実行されるので、外側のレキシカルスコープはそこから見え、 | |
| 4500 | パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。 | |
| 4501 | ||
| 4502 | =over 4 | |
| 4503 | ||
| 4504 | =item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 4505 | ||
| 4506 | =begin original | |
| 4507 | ||
| 4508 | If this feature is enabled (which is the default under a C<use 5.16> or | |
| 4509 | higher declaration), EXPR is considered to be | |
| 4510 | in the same encoding as the surrounding program. Thus if | |
| 4511 | S<L<C<use utf8>|utf8>> is in effect, the string will be treated as being | |
| 4512 | UTF-8 encoded. Otherwise, the string is considered to be a sequence of | |
| 4513 | independent bytes. Bytes that correspond to ASCII-range code points | |
| 4514 | will have their normal meanings for operators in the string. The | |
| 4515 | treatment of the other bytes depends on if the | |
| 4516 | L<C<'unicode_strings"> feature|feature/The 'unicode_strings' feature> is | |
| 4517 | in effect. | |
| 4518 | ||
| 4519 | =end original | |
| 4520 | ||
| 4521 | この機能が有効の場合(これは C<use 5.16> またはそれ以上が | |
| 4522 | 宣言されている場合はデフォルトです)、 | |
| 4523 | EXPR は周りのプログラムと同じエンコーディングであるとして扱われます。 | |
| 4524 | 従って、S<L<C<use utf8>|utf8>> が有効の場合、 | |
| 4525 | 文字列は UTF-8 エンコードされているものとして扱われます。 | |
| 4526 | さもなければ、この文字列は個々のバイト列として扱われます。 | |
| 4527 | ASCII の範囲の符号位置に対応するバイトは、 | |
| 4528 | 文字列の操作に関して通常の意味を持ちます。 | |
| 4529 | その他のバイトの扱いは、 | |
| 4530 | <C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か | |
| 4531 | どうかに依存します。 | |
| 4532 | ||
| 4533 | =begin original | |
| 4534 | ||
| 4535 | In a plain C<eval> without an EXPR argument, being in S<C<use utf8>> or | |
| 4536 | not is irrelevant; the UTF-8ness of C<$_> itself determines the | |
| 4537 | behavior. | |
| 4538 | ||
| 4539 | =end original | |
| 4540 | ||
| 4541 | EXPR 引数のない単なる C<eval> の場合、S<C<use utf8>> の有無は無関係です; | |
| 4542 | C<$_> 自身の UTF-8 性が振る舞いを決定します。 | |
| 4543 | ||
| 4544 | =begin original | |
| 4545 | ||
| 4546 | Any S<C<use utf8>> or S<C<no utf8>> declarations within the string have | |
| 4547 | no effect, and source filters are forbidden. (C<unicode_strings>, | |
| 4548 | however, can appear within the string.) See also the | |
| 4549 | L<C<evalbytes>|/evalbytes EXPR> operator, which works properly with | |
| 4550 | source filters. | |
| 4551 | ||
| 4552 | =end original | |
| 4553 | ||
| 4554 | 文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効で、ソースフィルタは | |
| 4555 | 禁止されます。 | |
| 4556 | (しかし、C<unicode_strings> は文字列の中に現れます。) | |
| 4557 | ソースフィルタが適切に動作する | |
| 4558 | L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。 | |
| 4559 | ||
| 4560 | =begin original | |
| 4561 | ||
| 4562 | Variables defined outside the C<eval> and used inside it retain their | |
| 4563 | original UTF-8ness. Everything inside the string follows the normal | |
| 4564 | rules for a Perl program with the given state of S<C<use utf8>>. | |
| 4565 | ||
| 4566 | =end original | |
| 4567 | ||
| 4568 | Variables defined outside the | |
| 4569 | C<eval> の外側で定義され、内側で使われた変数は、 | |
| 4570 | 元の UTF-8 性を維持します。 | |
| 4571 | 内側の文字列は、S<C<use utf8>> の状態によって Perl プログラムに適用される | |
| 4572 | 通常の規則に従います。 | |
| 4573 | ||
| 4574 | =item Outside the C<"unicode_eval"> feature | |
| 4575 | ||
| 4576 | =begin original | |
| 4577 | ||
| 4578 | In this case, the behavior is problematic and is not so easily | |
| 4579 | described. Here are two bugs that cannot easily be fixed without | |
| 4580 | breaking existing programs: | |
| 4581 | ||
| 4582 | =end original | |
| 4583 | ||
| 4584 | この場合、振る舞いには問題があり、それほど簡単には説明できません。 | |
| 4585 | 既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります: | |
| 4586 | ||
| 4587 | =over 4 | |
| 4588 | ||
| 4589 | =item * | |
| 4590 | ||
| 4591 | =begin original | |
| 4592 | ||
| 4593 | It can lose track of whether something should be encoded as UTF-8 or | |
| 4594 | not. | |
| 4595 | ||
| 4596 | =end original | |
| 4597 | ||
| 4598 | あるものが UTF-8 でエンコードされているかどうかを見失うことがあります。 | |
| 4599 | ||
| 4600 | =item * | |
| 4601 | ||
| 4602 | =begin original | |
| 4603 | ||
| 4604 | Source filters activated within C<eval> leak out into whichever file | |
| 4605 | scope is currently being compiled. To give an example with the CPAN module | |
| 4606 | L<Semi::Semicolons>: | |
| 4607 | ||
| 4608 | =end original | |
| 4609 | ||
| 4610 | C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで | |
| 4611 | コンパイルされているかをリークさせます。 | |
| 4612 | CPAN モジュール L<Semi::Semicolons> を使った例は: | |
| 4613 | ||
| 4614 | BEGIN { eval "use Semi::Semicolons; # not filtered" } | |
| 4615 | # filtered here! | |
| 4616 | ||
| 4617 | =begin original | |
| 4618 | ||
| 4619 | L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would | |
| 4620 | expect: | |
| 4621 | ||
| 4622 | =end original | |
| 4623 | ||
| 4624 | L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように | |
| 4625 | これを修正します: | |
| 4626 | ||
| 4627 | use feature "evalbytes"; | |
| 4628 | BEGIN { evalbytes "use Semi::Semicolons; # filtered" } | |
| 4629 | # not filtered | |
| 4630 | ||
| 4631 | =back | |
| 4632 | ||
| 4633 | =back | |
| 4634 | ||
| 4635 | =begin original | |
| 4636 | ||
| 4637 | Problems can arise if the string expands a scalar containing a floating | |
| 4638 | point number. That scalar can expand to letters, such as C<"NaN"> or | |
| 4639 | C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the | |
| 4640 | decimal point character may be something other than a dot (such as a | |
| 4641 | comma). None of these are likely to parse as you are likely expecting. | |
| 4642 | ||
| 4643 | =end original | |
| 4644 | ||
| 4645 | 文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。 | |
| 4646 | そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に | |
| 4647 | 展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、 | |
| 4648 | 小数点文字は (カンマのような) ドット以外の文字かもしれません。 | |
| 4649 | これらはどれもあなたがおそらく予測しているようにはパースされません。 | |
| 4650 | ||
| 4651 | =begin original | |
| 4652 | ||
| 4653 | You should be especially careful to remember what's being looked at | |
| 4654 | when: | |
| 4655 | ||
| 4656 | =end original | |
| 4657 | ||
| 4658 | 以下のような場合に、何が調べられるかに特に注意しておくことが必要です: | |
| 4659 | ||
| 4660 | eval $x; # CASE 1 | |
| 4661 | eval "$x"; # CASE 2 | |
| 4662 | ||
| 4663 | eval '$x'; # CASE 3 | |
| 4664 | eval { $x }; # CASE 4 | |
| 4665 | ||
| 4666 | eval "\$$x++"; # CASE 5 | |
| 4667 | $$x++; # CASE 6 | |
| 4668 | ||
| 4669 | =begin original | |
| 4670 | ||
| 4671 | Cases 1 and 2 above behave identically: they run the code contained in | |
| 4672 | the variable $x. (Although case 2 has misleading double quotes making | |
| 4673 | the reader wonder what else might be happening (nothing is).) Cases 3 | |
| 4674 | and 4 likewise behave in the same way: they run the code C<'$x'>, which | |
| 4675 | does nothing but return the value of $x. (Case 4 is preferred for | |
| 4676 | purely visual reasons, but it also has the advantage of compiling at | |
| 4677 | compile-time instead of at run-time.) Case 5 is a place where | |
| 4678 | normally you I<would> like to use double quotes, except that in this | |
| 4679 | particular situation, you can just use symbolic references instead, as | |
| 4680 | in case 6. | |
| 4681 | ||
| 4682 | =end original | |
| 4683 | ||
| 4684 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の | |
| 4685 | コードを実行します。 | |
| 4686 | (ただし、CASE 2 では、必要のないダブルクォートによって、 | |
| 4687 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) | |
| 4688 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に | |
| 4689 | 何もしない C<$x> というコードを実行します | |
| 4690 | (純粋に見た目の問題で、CASE 4 が好まれますが、 | |
| 4691 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 | |
| 4692 | CASE 5 の場合は、通常ダブルクォートを使用 I<します>; | |
| 4693 | この状況を除けば、CASE 6 のように、単に | |
| 4694 | シンボリックリファレンスを使えば良いでしょう。 | |
| 4695 | ||
| 4696 | =begin original | |
| 4697 | ||
| 4698 | An C<eval ''> executed within a subroutine defined | |
| 4699 | in the C<DB> package doesn't see the usual | |
| 4700 | surrounding lexical scope, but rather the scope of the first non-DB piece | |
| 4701 | of code that called it. You don't normally need to worry about this unless | |
| 4702 | you are writing a Perl debugger. | |
| 4703 | ||
| 4704 | =end original | |
| 4705 | ||
| 4706 | C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の | |
| 4707 | レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の | |
| 4708 | スコープになります。 | |
| 4709 | Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は | |
| 4710 | ありません。 | |
| 4711 | ||
| 4712 | =begin original | |
| 4713 | ||
| 4714 | The final semicolon, if any, may be omitted from the value of EXPR. | |
| 4715 | ||
| 4716 | =end original | |
| 4717 | ||
| 4718 | 最後のセミコロンは、もしあれば、EXPR の値から省くことができます。 | |
| 4719 | ||
| 4720 | =item Block eval | |
| 4721 | ||
| 4722 | =begin original | |
| 4723 | ||
| 4724 | 2892 | If the code to be executed doesn't vary, you may use the eval-BLOCK |
| 4725 | 2893 | form to trap run-time errors without incurring the penalty of |
| 4726 | recompiling each time. The error, if any, is still returned in | |
| 2894 | recompiling each time. The error, if any, is still returned in C<$@>. | |
| 4727 | L<C<$@>|perlvar/$@>. | |
| 4728 | 2895 | Examples: |
| 4729 | 2896 | |
| 4730 | 2897 | =end original |
| 4731 | 2898 | |
| 4732 | 2899 | 実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、 |
| 4733 | 2900 | 実行時エラーのトラップを行なうために、 |
| 4734 | 2901 | eval-BLOCK 形式を使うことができます。 |
| 4735 | エラーがあれば、やはり | |
| 2902 | エラーがあれば、やはり $@ に返されます。 | |
| 4736 | 2903 | 例: |
| 4737 | 2904 | |
| 4738 | 2905 | # make divide-by-zero nonfatal |
| 4739 | 2906 | eval { $answer = $a / $b; }; warn $@ if $@; |
| 4740 | 2907 | |
| 4741 | 2908 | # same thing, but less efficient |
| 4742 | 2909 | eval '$answer = $a / $b'; warn $@ if $@; |
| 4743 | 2910 | |
| 4744 | 2911 | # a compile-time error |
| 4745 | eval { $answer = }; | |
| 2912 | eval { $answer = }; # WRONG | |
| 4746 | 2913 | |
| 4747 | 2914 | # a run-time error |
| 4748 | eval '$answer ='; | |
| 2915 | eval '$answer ='; # sets $@ | |
| 4749 | 2916 | |
| 4750 | 2917 | =begin original |
| 4751 | 2918 | |
| 4752 | ||
| 2919 | Due to the current arguably broken state of C<__DIE__> hooks, when using | |
| 4753 | the | |
| 2920 | the C<eval{}> form as an exception trap in libraries, you may wish not | |
| 4754 | ||
| 2921 | to trigger any C<__DIE__> hooks that user code may have installed. | |
| 4755 | L<perlrun>. | |
| 4756 | ||
| 4757 | =end original | |
| 4758 | ||
| 4759 | XS モジュールのロード中のエラーをトラップしたいなら、 | |
| 4760 | (Perl バージョンの違いのような) バイナリインターフェースに関する問題に | |
| 4761 | ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない | |
| 4762 | C<eval> でも致命的エラーになるかもしれません。 | |
| 4763 | L<perlrun> を参照してください。 | |
| 4764 | ||
| 4765 | =begin original | |
| 4766 | ||
| 4767 | Using the C<eval {}> form as an exception trap in libraries does have some | |
| 4768 | issues. Due to the current arguably broken state of C<__DIE__> hooks, you | |
| 4769 | may wish not to trigger any C<__DIE__> hooks that user code may have installed. | |
| 4770 | 2922 | You can use the C<local $SIG{__DIE__}> construct for this purpose, |
| 4771 | as this example | |
| 2923 | as shown in this example: | |
| 4772 | 2924 | |
| 4773 | 2925 | =end original |
| 4774 | 2926 | |
| 4775 | C<eval{}> 形式をライブラリの例外を | |
| 2927 | C<eval{}> 形式をライブラリの例外を補足するために使うとき、 | |
| 4776 | 問題があります。 | |
| 4777 | 2928 | 現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、 |
| 4778 | 2929 | ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。 |
| 4779 | 2930 | この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。 |
| 4780 | 2931 | |
| 4781 | # a private exception trap for divide-by-zero | |
| 2932 | # a very private exception trap for divide-by-zero | |
| 4782 | 2933 | eval { local $SIG{'__DIE__'}; $answer = $a / $b; }; |
| 4783 | 2934 | warn $@ if $@; |
| 4784 | 2935 | |
| 4785 | 2936 | =begin original |
| 4786 | 2937 | |
| 4787 | 2938 | This is especially significant, given that C<__DIE__> hooks can call |
| 4788 | ||
| 2939 | C<die> again, which has the effect of changing their error messages: | |
| 4789 | messages: | |
| 4790 | 2940 | |
| 4791 | 2941 | =end original |
| 4792 | 2942 | |
| 4793 | これは特に顕著です | |
| 2943 | これは特に顕著です。与えられた C<__DIE__> フックは C<die> をもう一度 | |
| 4794 | ||
| 2944 | 呼び出すことができ、これによってエラーメッセージを変える効果があります: | |
| 4795 | 効果があります: | |
| 4796 | 2945 | |
| 4797 | 2946 | # __DIE__ hooks may modify error messages |
| 4798 | 2947 | { |
| 4799 | 2948 | local $SIG{'__DIE__'} = |
| 4800 | 2949 | sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x }; |
| 4801 | 2950 | eval { die "foo lives here" }; |
| 4802 | 2951 | print $@ if $@; # prints "bar lives here" |
| 4803 | 2952 | } |
| 4804 | 2953 | |
| 4805 | 2954 | =begin original |
| 4806 | 2955 | |
| 4807 | 2956 | Because this promotes action at a distance, this counterintuitive behavior |
| 4808 | 2957 | may be fixed in a future release. |
| 4809 | 2958 | |
| 4810 | 2959 | =end original |
| 4811 | 2960 | |
| 4812 | 2961 | これは距離の離れた行動であるため、この直感的でない振る舞いは |
| 4813 | 2962 | 将来のリリースでは修正されるかもしれません。 |
| 4814 | 2963 | |
| 4815 | 2964 | =begin original |
| 4816 | 2965 | |
| 4817 | C<eval | |
| 2966 | With an C<eval>, you should be especially careful to remember what's | |
| 4818 | ||
| 2967 | being looked at when: | |
| 4819 | L<C<redo>|/redo LABEL> cannot be used to leave or restart the block. | |
| 4820 | 2968 | |
| 4821 | 2969 | =end original |
| 4822 | 2970 | |
| 4823 | C<eval | |
| 2971 | C<eval> では、以下のような場合に、 | |
| 4824 | ||
| 2972 | 何が調べられるかに特に注意しておくことが必要です: | |
| 4825 | ブロックから離れたり再実行したりはできません。 | |
| 4826 | 2973 | |
| 4827 | ||
| 2974 | eval $x; # CASE 1 | |
| 2975 | eval "$x"; # CASE 2 | |
| 4828 | 2976 | |
| 4829 | ||
| 2977 | eval '$x'; # CASE 3 | |
| 2978 | eval { $x }; # CASE 4 | |
| 4830 | 2979 | |
| 4831 | ||
| 2980 | eval "\$$x++"; # CASE 5 | |
| 2981 | $$x++; # CASE 6 | |
| 4832 | 2982 | |
| 4833 | 最後のセミコロンは、もしあれば、BLOCK の中から削除されます。 | |
| 4834 | ||
| 4835 | =back | |
| 4836 | ||
| 4837 | =item evalbytes EXPR | |
| 4838 | X<evalbytes> | |
| 4839 | ||
| 4840 | =item evalbytes | |
| 4841 | ||
| 4842 | =for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream | |
| 4843 | ||
| 4844 | 2983 | =begin original |
| 4845 | 2984 | |
| 4846 | ||
| 2985 | Cases 1 and 2 above behave identically: they run the code contained in | |
| 4847 | al | |
| 2986 | the variable $x. (Although case 2 has misleading double quotes making | |
| 4848 | a | |
| 2987 | the reader wonder what else might be happening (nothing is).) Cases 3 | |
| 2988 | and 4 likewise behave in the same way: they run the code C<'$x'>, which | |
| 2989 | does nothing but return the value of $x. (Case 4 is preferred for | |
| 2990 | purely visual reasons, but it also has the advantage of compiling at | |
| 2991 | compile-time instead of at run-time.) Case 5 is a place where | |
| 2992 | normally you I<would> like to use double quotes, except that in this | |
| 2993 | particular situation, you can just use symbolic references instead, as | |
| 2994 | in case 6. | |
| 4849 | 2995 | |
| 4850 | 2996 | =end original |
| 4851 | 2997 | |
| 4852 | ||
| 2998 | 上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の | |
| 4853 | ||
| 2999 | コードを実行します。 | |
| 4854 | ||
| 3000 | (ただし、CASE 2 では、必要のないダブルクォートによって、 | |
| 3001 | 読む人が何が起こるか混乱することでしょう (何も起こりませんが)。) | |
| 3002 | 同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に | |
| 3003 | 何もしない C<$x> というコードを実行します | |
| 3004 | (純粋に見た目の問題で、CASE 4 が好まれますが、 | |
| 3005 | 実行時でなくコンパイル時にコンパイルされるという利点もあります)。 | |
| 3006 | CASE 5 の場合は、通常ダブルクォートを使用します。 | |
| 3007 | この状況を除けば、CASE 6 のように、単に | |
| 3008 | シンボリックリファレンスを使えば良いでしょう。 | |
| 4855 | 3009 | |
| 4856 | 3010 | =begin original |
| 4857 | 3011 | |
| 4858 | ||
| 3012 | C<eval BLOCK> does I<not> count as a loop, so the loop control statements | |
| 4859 | ||
| 3013 | C<next>, C<last>, or C<redo> cannot be used to leave or restart the block. | |
| 4860 | work from, downgraded to non-UTF-8. If this is not possible | |
| 4861 | (because one or more characters in it require UTF-8), the C<evalbytes> | |
| 4862 | will fail with the error stored in C<$@>. | |
| 4863 | 3014 | |
| 4864 | 3015 | =end original |
| 4865 | 3016 | |
| 4866 | ||
| 3017 | C<eval BLOCK> はループとして I<扱われません>。 | |
| 4867 | ||
| 3018 | 従って、C<next>, C<last>, C<redo> といったループ制御文でブロックから離れたり | |
| 4868 | ||
| 3019 | 再実行したりはできません。 | |
| 4869 | (UTF-8 が必要な文字があるために) これが不可能な場合、 | |
| 4870 | C<evalbytes> は失敗し、エラーは C<$@> に保管されます。 | |
| 4871 | 3020 | |
| 4872 | =begin original | |
| 4873 | ||
| 4874 | Bytes that correspond to ASCII-range code points will have their normal | |
| 4875 | meanings for operators in the string. The treatment of the other bytes | |
| 4876 | depends on if the L<C<'unicode_strings"> feature|feature/The | |
| 4877 | 'unicode_strings' feature> is in effect. | |
| 4878 | ||
| 4879 | =end original | |
| 4880 | ||
| 4881 | ASCII の範囲の符号位置に対応するバイトは、 | |
| 4882 | 文字列の操作に関して通常の意味を持ちます。 | |
| 4883 | その他のバイトの扱いは、 | |
| 4884 | <C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か | |
| 4885 | どうかに依存します。 | |
| 4886 | ||
| 4887 | =begin original | |
| 4888 | ||
| 4889 | Of course, variables that are UTF-8 and are referred to in the string | |
| 4890 | retain that: | |
| 4891 | ||
| 4892 | =end original | |
| 4893 | ||
| 4894 | もちろん、UTF-8 で文字列の中で参照されている変数はそのままです: | |
| 4895 | ||
| 4896 | my $a = "\x{100}"; | |
| 4897 | evalbytes 'print ord $a, "\n"'; | |
| 4898 | ||
| 4899 | =begin original | |
| 4900 | ||
| 4901 | prints | |
| 4902 | ||
| 4903 | =end original | |
| 4904 | ||
| 4905 | というのは、次を表示し、 | |
| 4906 | ||
| 4907 | 256 | |
| 4908 | ||
| 4909 | =begin original | |
| 4910 | ||
| 4911 | and C<$@> is empty. | |
| 4912 | ||
| 4913 | =end original | |
| 4914 | ||
| 4915 | C<$@> は空になります。 | |
| 4916 | ||
| 4917 | =begin original | |
| 4918 | ||
| 4919 | Source filters activated within the evaluated code apply to the code | |
| 4920 | itself. | |
| 4921 | ||
| 4922 | =end original | |
| 4923 | ||
| 4924 | eval されたコード内で有効になったソースフィルタはコード自体に適用されます。 | |
| 4925 | ||
| 4926 | =begin original | |
| 4927 | ||
| 4928 | L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To | |
| 4929 | access it, you must say C<CORE::evalbytes>, but you can omit the | |
| 4930 | C<CORE::> if the | |
| 4931 | L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features> | |
| 4932 | is enabled. This is enabled automatically with a C<use v5.16> (or | |
| 4933 | higher) declaration in the current scope. | |
| 4934 | ||
| 4935 | =end original | |
| 4936 | ||
| 4937 | L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。 | |
| 4938 | これにアクセスするには C<CORE::evalbytes> とする必要がありますが、 | |
| 4939 | L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が | |
| 4940 | 有効なら C<CORE::> を省略できます。 | |
| 4941 | これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると | |
| 4942 | 自動的に有効になります。 | |
| 4943 | ||
| 4944 | 3021 | =item exec LIST |
| 4945 | X<exec> X<execute> | |
| 4946 | 3022 | |
| 4947 | 3023 | =item exec PROGRAM LIST |
| 4948 | 3024 | |
| 4949 | =for Pod::Functions abandon this program to run another | |
| 4950 | ||
| 4951 | 3025 | =begin original |
| 4952 | 3026 | |
| 4953 | The | |
| 3027 | The C<exec> function executes a system command I<and never returns>-- | |
| 4954 | ||
| 3028 | use C<system> instead of C<exec> if you want it to return. It fails and | |
| 4955 | if you want it to return. It fails and | |
| 4956 | 3029 | returns false only if the command does not exist I<and> it is executed |
| 4957 | 3030 | directly instead of via your system's command shell (see below). |
| 4958 | 3031 | |
| 4959 | 3032 | =end original |
| 4960 | 3033 | |
| 4961 | ||
| 3034 | C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>。 | |
| 4962 | 戻って欲しい場合には、 | |
| 3035 | 戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。 | |
| 4963 | L<C<system>|/system LIST> 関数を使ってください。 | |
| 4964 | 3036 | コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく |
| 4965 | 3037 | 直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。 |
| 4966 | 3038 | |
| 4967 | 3039 | =begin original |
| 4968 | 3040 | |
| 4969 | Since it's a common mistake to use | |
| 3041 | Since it's a common mistake to use C<exec> instead of C<system>, Perl | |
| 4970 | ||
| 3042 | warns you if there is a following statement which isn't C<die>, C<warn>, | |
| 4971 | ||
| 3043 | or C<exit> (if C<-w> is set - but you always do that). If you | |
| 4972 | ||
| 3044 | I<really> want to follow an C<exec> with some other statement, you | |
| 4973 | ||
| 3045 | can use one of these styles to avoid the warning: | |
| 4974 | I<really> want to follow an L<C<exec>|/exec LIST> with some other | |
| 4975 | statement, you can use one of these styles to avoid the warning: | |
| 4976 | 3046 | |
| 4977 | 3047 | =end original |
| 4978 | 3048 | |
| 4979 | ||
| 3049 | C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、 | |
| 4980 | ||
| 3050 | 引き続く文が C<die>, C<warn>, C<exit>(C<-w> がセットされている場合 - | |
| 4981 | ||
| 3051 | でもいつもセットしてますよね) 以外の場合、Perl は警告を出します。 | |
| 4982 | ||
| 3052 | もし I<本当に> C<exec> の後に他の文を書きたい場合、 | |
| 4983 | ||
| 3053 | 以下のどちらかのスタイルを使うことで警告を回避できます: | |
| 4984 | もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の | |
| 4985 | どちらかのスタイルを使うことで警告を回避できます: | |
| 4986 | 3054 | |
| 4987 | 3055 | exec ('foo') or print STDERR "couldn't exec foo: $!"; |
| 4988 | 3056 | { exec ('foo') }; print STDERR "couldn't exec foo: $!"; |
| 4989 | 3057 | |
| 4990 | 3058 | =begin original |
| 4991 | 3059 | |
| 4992 | If there is more than one argument in LIST, | |
| 3060 | If there is more than one argument in LIST, or if LIST is an array | |
| 4993 | ||
| 3061 | with more than one value, calls execvp(3) with the arguments in LIST. | |
| 4994 | ||
| 3062 | If there is only one scalar argument or an array with one element in it, | |
| 4995 | argument is | |
| 3063 | the argument is checked for shell metacharacters, and if there are any, | |
| 4996 | ||
| 3064 | the entire argument is passed to the system's command shell for parsing | |
| 4997 | th | |
| 3065 | (this is C</bin/sh -c> on Unix platforms, but varies on other platforms). | |
| 4998 | ||
| 3066 | If there are no shell metacharacters in the argument, it is split into | |
| 3067 | words and passed directly to C<execvp>, which is more efficient. | |
| 3068 | Examples: | |
| 4999 | 3069 | |
| 5000 | 3070 | =end original |
| 5001 | 3071 | |
| 5002 | LIST に複数の引数がある場合 | |
| 3072 | LIST に複数の引数がある場合か、LIST が複数の値を持つ | |
| 5003 | 呼び出します。 | |
| 3073 | 配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。 | |
| 5004 | ||
| 3074 | 1 つのスカラ引数のみまたは要素が 1 つの配列の場合には、その引数から | |
| 5005 | もしメタ文字があれば、 | |
| 3075 | シェルのメタ文字をチェックし、もし、メタ文字があれば、 | |
| 3076 | 引数全体をシステムのコマンドシェル(これはUnix では | |
| 5006 | 3077 | C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。 |
| 5007 | ||
| 3078 | もし、メタキャラクタがなければ、その引数を単語に分け、 | |
| 5008 | ||
| 3079 | より効率的な C<execvp> に直接渡します。 | |
| 5009 | 3080 | 例: |
| 5010 | 3081 | |
| 5011 | 3082 | exec '/bin/echo', 'Your arguments are: ', @ARGV; |
| 5012 | 3083 | exec "sort $outfile | uniq"; |
| 5013 | 3084 | |
| 5014 | 3085 | =begin original |
| 5015 | 3086 | |
| 5016 | 3087 | If you don't really want to execute the first argument, but want to lie |
| 5017 | 3088 | to the program you are executing about its own name, you can specify |
| 5018 | 3089 | the program you actually want to run as an "indirect object" (without a |
| 5019 | comma) in front of the LIST | |
| 3090 | comma) in front of the LIST. (This always forces interpretation of the | |
| 5020 | ||
| 3091 | LIST as a multivalued list, even if there is only a single scalar in | |
| 5021 | ||
| 3092 | the list.) Example: | |
| 5022 | 3093 | |
| 5023 | 3094 | =end original |
| 5024 | 3095 | |
| 5025 | 第一引数に指定するものを本当に実行したいが、実行する | |
| 3096 | 第一引数に指定するものを本当に実行したいが、実行する | |
| 5026 | 名前を教えたい場合には、 | |
| 3097 | プログラムに対して別の名前を教えたい場合には、LISTの前に、 | |
| 5027 | 「間接オブジェクト」(コンマなし) として実際に | |
| 3098 | 「間接オブジェクト」(コンマなし) として、実際に | |
| 5028 | 指定することができます。 | |
| 3099 | 実行したいプログラムを指定することができます。 | |
| 5029 | (これによって、LIST に単一のスカラしかなくても、複数 | |
| 3100 | (これによって、LIST に単一のスカラしかなくても、複数 | |
| 5030 | LIST の解釈を行ないます。) | |
| 3101 | 値のリストであるように、LIST の解釈を行ないます。) | |
| 5031 | 3102 | 例: |
| 5032 | 3103 | |
| 5033 | | |
| 3104 | $shell = '/bin/csh'; | |
| 5034 | exec $shell '-sh'; | |
| 3105 | exec $shell '-sh'; # pretend it's a login shell | |
| 5035 | 3106 | |
| 5036 | 3107 | =begin original |
| 5037 | 3108 | |
| 5038 | 3109 | or, more directly, |
| 5039 | 3110 | |
| 5040 | 3111 | =end original |
| 5041 | 3112 | |
| 5042 | 3113 | あるいは、より直接的に、 |
| 5043 | 3114 | |
| 5044 | exec {'/bin/csh'} '-sh'; | |
| 3115 | exec {'/bin/csh'} '-sh'; # pretend it's a login shell | |
| 5045 | 3116 | |
| 5046 | 3117 | =begin original |
| 5047 | 3118 | |
| 5048 | When the arguments get executed via the system shell, results | |
| 3119 | When the arguments get executed via the system shell, results will | |
| 5049 | subject to its quirks and capabilities. See L<perlop/"`STRING`"> | |
| 3120 | be subject to its quirks and capabilities. See L<perlop/"`STRING`"> | |
| 5050 | 3121 | for details. |
| 5051 | 3122 | |
| 5052 | 3123 | =end original |
| 5053 | 3124 | |
| 5054 | 3125 | 引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって |
| 5055 | 3126 | 変わります。 |
| 5056 | 3127 | 詳細については L<perlop/"`STRING`"> を参照してください。 |
| 5057 | 3128 | |
| 5058 | 3129 | =begin original |
| 5059 | 3130 | |
| 5060 | Using an indirect object with | |
| 3131 | Using an indirect object with C<exec> or C<system> is also more | |
| 5061 | ||
| 3132 | secure. This usage (which also works fine with system()) forces | |
| 5062 | works fine with L<C<system>|/system LIST>) forces | |
| 5063 | 3133 | interpretation of the arguments as a multivalued list, even if the |
| 5064 | 3134 | list had just one argument. That way you're safe from the shell |
| 5065 | 3135 | expanding wildcards or splitting up words with whitespace in them. |
| 5066 | 3136 | |
| 5067 | 3137 | =end original |
| 5068 | 3138 | |
| 5069 | ||
| 3139 | C<exec> や C<system> で間接オブジェクトを使うのもより安全です。 | |
| 5070 | ||
| 3140 | この使い方(system() でも同様にうまく動きます)は、たとえ引数が一つだけの | |
| 5071 | ||
| 3141 | 場合も、複数の値を持つリストとして引数を解釈することを強制します。 | |
| 5072 | 引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを | |
| 5073 | 強制します。 | |
| 5074 | 3142 | この方法で、シェルによるワイルドカード展開や、空白による単語の分割から |
| 5075 | 3143 | 守られます。 |
| 5076 | 3144 | |
| 5077 | | |
| 3145 | @args = ( "echo surprise" ); | |
| 5078 | 3146 | |
| 5079 | 3147 | exec @args; # subject to shell escapes |
| 5080 | 3148 | # if @args == 1 |
| 5081 | 3149 | exec { $args[0] } @args; # safe even with one-arg list |
| 5082 | 3150 | |
| 5083 | 3151 | =begin original |
| 5084 | 3152 | |
| 5085 | 3153 | The first version, the one without the indirect object, ran the I<echo> |
| 5086 | program, passing it C<"surprise"> an argument. The second version | |
| 3154 | program, passing it C<"surprise"> an argument. The second version | |
| 5087 | it tried to run a program | |
| 3155 | didn't--it tried to run a program literally called I<"echo surprise">, | |
| 5088 | ||
| 3156 | didn't find it, and set C<$?> to a non-zero value indicating failure. | |
| 5089 | 3157 | |
| 5090 | 3158 | =end original |
| 5091 | 3159 | |
| 5092 | 3160 | 間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、 |
| 5093 | 3161 | C<"surprise"> が引数として渡されます。 |
| 5094 | 二つ目のバージョンでは違います | |
| 3162 | 二つ目のバージョンでは違います -- 文字通り I<"echo surprise"> という名前の | |
| 5095 | 3163 | プログラムを実行しようとして、見つからないので、失敗したことを示すために |
| 5096 | ||
| 3164 | C<$?> に非 0 がセットされます。 | |
| 5097 | 3165 | |
| 5098 | 3166 | =begin original |
| 5099 | 3167 | |
| 5100 | ||
| 3168 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
| 5101 | ||
| 3169 | output before the exec, but this may not be supported on some platforms | |
| 5102 | e | |
| 3170 | (see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH | |
| 3171 | in English) or call the C<autoflush()> method of C<IO::Handle> on any | |
| 3172 | open handles in order to avoid lost output. | |
| 5103 | 3173 | |
| 5104 | 3174 | =end original |
| 5105 | 3175 | |
| 5106 | Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを | |
| 5107 | 使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が | |
| 5108 | あっても、最初の spawn が失敗したときにシェルに | |
| 5109 | フォールバックすることがあります。 | |
| 5110 | ||
| 5111 | =begin original | |
| 5112 | ||
| 5113 | Perl attempts to flush all files opened for output before the exec, | |
| 5114 | but this may not be supported on some platforms (see L<perlport>). | |
| 5115 | To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>> | |
| 5116 | (C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of | |
| 5117 | L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost | |
| 5118 | output. | |
| 5119 | ||
| 5120 | =end original | |
| 5121 | ||
| 5122 | 3176 | v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを |
| 5123 | 3177 | フラッシュしようとしますが、これに対応していないプラットフォームもあります |
| 5124 | 3178 | (L<perlport> を参照してください)。 |
| 5125 | 3179 | 安全のためには、出力が重複するのを避けるために、全てのオープンしている |
| 5126 | ハンドルに対して | |
| 3180 | ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、 | |
| 5127 | ||
| 3181 | C<IO::Handle> モジュールの C<autoflush()> メソッドをを呼ぶ必要が | |
| 5128 | ||
| 3182 | あるかもしれません。 | |
| 5129 | 呼ぶ必要があるかもしれません。 | |
| 5130 | 3183 | |
| 5131 | 3184 | =begin original |
| 5132 | 3185 | |
| 5133 | Note that | |
| 3186 | Note that C<exec> will not call your C<END> blocks, nor will it call | |
| 5134 | ||
| 3187 | any C<DESTROY> methods in your objects. | |
| 5135 | 3188 | |
| 5136 | 3189 | =end original |
| 5137 | 3190 | |
| 5138 | ||
| 3191 | C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを | |
| 5139 | ||
| 3192 | 呼び出さないことに注意してください。 | |
| 5140 | 3193 | |
| 5141 | =begin original | |
| 5142 | ||
| 5143 | Portability issues: L<perlport/exec>. | |
| 5144 | ||
| 5145 | =end original | |
| 5146 | ||
| 5147 | 移植性の問題: L<perlport/exec>。 | |
| 5148 | ||
| 5149 | 3194 | =item exists EXPR |
| 5150 | X<exists> X<autovivification> | |
| 5151 | 3195 | |
| 5152 | =for Pod::Functions test whether a hash key is present | |
| 5153 | ||
| 5154 | 3196 | =begin original |
| 5155 | 3197 | |
| 5156 | Given an expression that specifies a | |
| 3198 | Given an expression that specifies a hash element or array element, | |
| 5157 | specified element in the hash | |
| 3199 | returns true if the specified element in the hash or array has ever | |
| 5158 | corresponding value is undefined. | |
| 3200 | been initialized, even if the corresponding value is undefined. The | |
| 3201 | element is not autovivified if it doesn't exist. | |
| 5159 | 3202 | |
| 5160 | 3203 | =end original |
| 5161 | 3204 | |
| 5162 | ハッシュ要素を示す表現が与えられ | |
| 3205 | ハッシュ要素か配列要素を示す表現が与えられ、 | |
| 5163 | た | |
| 3206 | 指定された要素が、ハッシュか配列に存在すれば、 | |
| 3207 | たとえ対応する value が未定義でも真を返します。 | |
| 3208 | 要素が存在しなかった場合は自動活性化されません。 | |
| 5164 | 3209 | |
| 5165 | print "Exists\n" | |
| 3210 | print "Exists\n" if exists $hash{$key}; | |
| 5166 | print "Defined\n" | |
| 3211 | print "Defined\n" if defined $hash{$key}; | |
| 5167 | 3212 | print "True\n" if $hash{$key}; |
| 5168 | 3213 | |
| 5169 | ||
| 3214 | print "Exists\n" if exists $array[$index]; | |
| 3215 | print "Defined\n" if defined $array[$index]; | |
| 5171 | exists may also be called on array elements, but its behavior is much less | |
| 5172 | obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on | |
| 5173 | arrays. | |
| 5174 | ||
| 5175 | =end original | |
| 5176 | ||
| 5177 | exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに | |
| 5178 | 不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く | |
| 5179 | 結びついています。 | |
| 5180 | ||
| 5181 | =begin original | |
| 5182 | ||
| 5183 | B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is | |
| 5184 | strongly discouraged. The | |
| 5185 | notion of deleting or checking the existence of Perl array elements is not | |
| 5186 | conceptually coherent, and can lead to surprising behavior. | |
| 5187 | ||
| 5188 | =end original | |
| 5189 | ||
| 5190 | B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く | |
| 5191 | 非推奨です。 | |
| 5192 | Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、 | |
| 5193 | 驚くべき振る舞いを引き起こすことがあります。 | |
| 5194 | ||
| 5195 | print "Exists\n" if exists $array[$index]; | |
| 5196 | print "Defined\n" if defined $array[$index]; | |
| 5197 | 3216 | print "True\n" if $array[$index]; |
| 5198 | 3217 | |
| 5199 | 3218 | =begin original |
| 5200 | 3219 | |
| 5201 | A hash or array element can be true only if it's defined and defined | |
| 3220 | A hash or array element can be true only if it's defined, and defined if | |
| 5202 | 3221 | it exists, but the reverse doesn't necessarily hold true. |
| 5203 | 3222 | |
| 5204 | 3223 | =end original |
| 5205 | 3224 | |
| 5206 | 3225 | ハッシュまたは配列要素は、定義されているときにのみ真となり、 |
| 5207 | 3226 | 存在しているときにのみ定義されますが、逆は必ずしも真ではありません。 |
| 5208 | 3227 | |
| 5209 | 3228 | =begin original |
| 5210 | 3229 | |
| 5211 | 3230 | Given an expression that specifies the name of a subroutine, |
| 5212 | 3231 | returns true if the specified subroutine has ever been declared, even |
| 5213 | 3232 | if it is undefined. Mentioning a subroutine name for exists or defined |
| 5214 | does not count as declaring it. Note that a subroutine | |
| 3233 | does not count as declaring it. Note that a subroutine which does not | |
| 5215 | 3234 | exist may still be callable: its package may have an C<AUTOLOAD> |
| 5216 | 3235 | method that makes it spring into existence the first time that it is |
| 5217 | called | |
| 3236 | called -- see L<perlsub>. | |
| 5218 | 3237 | |
| 5219 | 3238 | =end original |
| 5220 | 3239 | |
| 5221 | 3240 | 引数としてサブルーチンの名前が指定された場合、 |
| 5222 | 3241 | 指定されたサブルーチンが宣言されていれば(たとえ未定義でも) |
| 5223 | 3242 | 真を返します。 |
| 5224 | 3243 | exists や defined のために言及されているサブルーチン名は |
| 5225 | 3244 | 宣言としてのカウントに入りません。 |
| 5226 | 3245 | 存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください: |
| 5227 | 3246 | パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に |
| 5228 | 存在を作り出すかもしれません | |
| 3247 | 存在を作り出すかもしれません -- L<perlsub> を参照してください。 | |
| 5229 | 3248 | |
| 5230 | print "Exists\n" | |
| 3249 | print "Exists\n" if exists &subroutine; | |
| 5231 | print "Defined\n" if defined &subroutine; | |
| 3250 | print "Defined\n" if defined &subroutine; | |
| 5232 | 3251 | |
| 5233 | 3252 | =begin original |
| 5234 | 3253 | |
| 5235 | 3254 | Note that the EXPR can be arbitrarily complicated as long as the final |
| 5236 | 3255 | operation is a hash or array key lookup or subroutine name: |
| 5237 | 3256 | |
| 5238 | 3257 | =end original |
| 5239 | 3258 | |
| 5240 | 最終的な操作がハッシュや配列の key による検索または | |
| 3259 | 最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、 | |
| 5241 | ||
| 3260 | EXPR には任意の複雑な式を置くことができます: | |
| 5242 | 3261 | |
| 5243 | if (exists $ref->{A}->{B}->{$key}) | |
| 3262 | if (exists $ref->{A}->{B}->{$key}) { } | |
| 5244 | if (exists $hash{A}{B}{$key}) | |
| 3263 | if (exists $hash{A}{B}{$key}) { } | |
| 5245 | 3264 | |
| 5246 | if (exists $ref->{A}->{B}->[$ix]) | |
| 3265 | if (exists $ref->{A}->{B}->[$ix]) { } | |
| 5247 | if (exists $hash{A}{B}[$ix]) | |
| 3266 | if (exists $hash{A}{B}[$ix]) { } | |
| 5248 | 3267 | |
| 5249 | 3268 | if (exists &{$ref->{A}{B}{$key}}) { } |
| 5250 | 3269 | |
| 5251 | 3270 | =begin original |
| 5252 | 3271 | |
| 5253 | Although the | |
| 3272 | Although the deepest nested array or hash will not spring into existence | |
| 5254 | ||
| 3273 | just because its existence was tested, any intervening ones will. | |
| 5255 | 3274 | Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring |
| 5256 | into existence due to the existence test for the | |
| 3275 | into existence due to the existence test for the $key element above. | |
| 5257 | This happens anywhere the arrow operator is used, including even | |
| 3276 | This happens anywhere the arrow operator is used, including even: | |
| 5258 | 3277 | |
| 5259 | 3278 | =end original |
| 5260 | 3279 | |
| 5261 | ||
| 3280 | ネストした配列やハッシュの一番深い部分は、その存在をテストしただけでは | |
| 5262 | 3281 | 存在するようにはなりませんが、途中のものは存在するようになります。 |
| 5263 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の | |
| 3282 | 従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の | |
| 5264 | 3283 | 存在をテストしたことによって存在するようになります。 |
| 5265 | 3284 | これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも |
| 5266 | 3285 | 起こります。 |
| 5267 | 3286 | |
| 5268 | 3287 | undef $ref; |
| 5269 | if (exists $ref->{"Some key"}) | |
| 3288 | if (exists $ref->{"Some key"}) { } | |
| 5270 | print $ref; # prints HASH(0x80d3d5c) | |
| 3289 | print $ref; # prints HASH(0x80d3d5c) | |
| 5271 | 3290 | |
| 5272 | 3291 | =begin original |
| 5273 | 3292 | |
| 5274 | ||
| 3293 | This surprising autovivification in what does not at first--or even | |
| 5275 | to | |
| 3294 | second--glance appear to be an lvalue context may be fixed in a future | |
| 3295 | release. | |
| 5276 | 3296 | |
| 5277 | 3297 | =end original |
| 5278 | 3298 | |
| 5279 | ||
| 3299 | 一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの | |
| 5280 | ||
| 3300 | 自動有効化は将来のリリースでは修正されるでしょう。 | |
| 5281 | 3301 | |
| 5282 | ||
| 3302 | =begin original | |
| 5283 | exists &sub(); # Error | |
| 5284 | 3303 | |
| 5285 | ||
| 3304 | See L<perlref/"Pseudo-hashes: Using an array as a hash"> for specifics | |
| 5286 | ||
| 3305 | on how exists() acts when used on a pseudo-hash. | |
| 5287 | 3306 | |
| 5288 | = | |
| 3307 | =end original | |
| 5289 | 3308 | |
| 5290 | ||
| 3309 | 擬似ハッシュに用いた場合に exists() がどのように振舞うかの仕様については | |
| 3310 | L<perlref/"Pseudo-hashes: Using an array as a hash"> を参照してください。 | |
| 5291 | 3311 | |
| 5292 | 3312 | =begin original |
| 5293 | 3313 | |
| 3314 | Use of a subroutine call, rather than a subroutine name, as an argument | |
| 3315 | to exists() is an error. | |
| 3316 | ||
| 3317 | =end original | |
| 3318 | ||
| 3319 | exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、 | |
| 3320 | エラーになります。 | |
| 3321 | ||
| 3322 | exists ⊂ # OK | |
| 3323 | exists &sub(); # Error | |
| 3324 | ||
| 3325 | =item exit EXPR | |
| 3326 | ||
| 3327 | =begin original | |
| 3328 | ||
| 5294 | 3329 | Evaluates EXPR and exits immediately with that value. Example: |
| 5295 | 3330 | |
| 5296 | 3331 | =end original |
| 5297 | 3332 | |
| 5298 | 3333 | EXPR を評価し、即座にその値を持って終了します。 |
| 5299 | 3334 | 例: |
| 5300 | 3335 | |
| 5301 | | |
| 3336 | $ans = <STDIN>; | |
| 5302 | 3337 | exit 0 if $ans =~ /^[Xx]/; |
| 5303 | 3338 | |
| 5304 | 3339 | =begin original |
| 5305 | 3340 | |
| 5306 | See also | |
| 3341 | See also C<die>. If EXPR is omitted, exits with C<0> status. The only | |
| 5307 | status. The only | |
| 5308 | 3342 | universally recognized values for EXPR are C<0> for success and C<1> |
| 5309 | 3343 | for error; other values are subject to interpretation depending on the |
| 5310 | 3344 | environment in which the Perl program is running. For example, exiting |
| 5311 | 3345 | 69 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause |
| 5312 | 3346 | the mailer to return the item undelivered, but that's not true everywhere. |
| 5313 | 3347 | |
| 5314 | 3348 | =end original |
| 5315 | 3349 | |
| 5316 | ||
| 3350 | C<die> も参照してください。 | |
| 5317 | 3351 | EXPR が省略された場合には、ステータスを C<0> として終了します。 |
| 5318 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> が | |
| 3352 | EXPR の値として広く利用可能なのは C<0> が成功で C<1> がエラーということだけです。 | |
| 5319 | ||
| 3353 | その他の値は、 Perl が実行される環境によって異なる解釈がされる | |
| 5320 | ||
| 3354 | 可能性があります。 | |
| 5321 | 3355 | 例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると |
| 5322 | 3356 | メーラーはアイテムを配達せずに差し戻しますが、 |
| 5323 | 3357 | これはいつでも真ではありません。 |
| 5324 | 3358 | |
| 5325 | 3359 | =begin original |
| 5326 | 3360 | |
| 5327 | Don't use | |
| 3361 | Don't use C<exit> to abort a subroutine if there's any chance that | |
| 5328 | ||
| 3362 | someone might want to trap whatever error happened. Use C<die> instead, | |
| 5329 | ||
| 3363 | which can be trapped by an C<eval>. | |
| 5330 | L<C<eval>|/eval EXPR>. | |
| 5331 | 3364 | |
| 5332 | 3365 | =end original |
| 5333 | 3366 | |
| 5334 | 3367 | 誰かが発生したエラーをトラップしようと考えている可能性がある場合は、 |
| 5335 | サブルーチンの中断に | |
| 3368 | サブルーチンの中断に C<exit> を使わないでください。 | |
| 5336 | 代わりに | |
| 3369 | 代わりに C<eval> でトラップできる C<die> を使ってください。 | |
| 5337 | 使ってください。 | |
| 5338 | 3370 | |
| 5339 | 3371 | =begin original |
| 5340 | 3372 | |
| 5341 | The | |
| 3373 | The exit() function does not always exit immediately. It calls any | |
| 5342 | ||
| 3374 | defined C<END> routines first, but these C<END> routines may not | |
| 5343 | ||
| 3375 | themselves abort the exit. Likewise any object destructors that need to | |
| 5344 | ||
| 3376 | be called are called before the real exit. If this is a problem, you | |
| 5345 | ||
| 3377 | can call C<POSIX:_exit($status)> to avoid END and destructor processing. | |
| 5346 | ||
| 3378 | See L<perlmod> for details. | |
| 5347 | L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor | |
| 5348 | processing. See L<perlmod> for details. | |
| 5349 | 3379 | |
| 5350 | 3380 | =end original |
| 5351 | 3381 | |
| 5352 | ||
| 3382 | exit() 関数は常に直ちに終了するわけではありません。 | |
| 5353 | まず、定義されている | |
| 3383 | まず、定義されている END ルーチンを呼び出しますが、 | |
| 5354 | 3384 | C<END> ルーチン自身は exit を止められません。 |
| 5355 | 3385 | 同様に、呼び出す必要のあるオブジェクトデストラクタは |
| 5356 | 3386 | すべて、実際の終了前に呼び出されます。 |
| 5357 | ||
| 3387 | これが問題になる場合は、END やデストラクタが実行されることを | |
| 5358 | ||
| 3388 | 防ぐために C<POSIX:_exit($status)> を呼び出してください。 | |
| 5359 | これが問題になる場合は、C<END> やデストラクタが実行されることを | |
| 5360 | 防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。 | |
| 5361 | 3389 | 詳しくは L<perlmod> を参照してください。 |
| 5362 | 3390 | |
| 5363 | =begin original | |
| 5364 | ||
| 5365 | Portability issues: L<perlport/exit>. | |
| 5366 | ||
| 5367 | =end original | |
| 5368 | ||
| 5369 | 移植性の問題: L<perlport/exit>。 | |
| 5370 | ||
| 5371 | 3391 | =item exp EXPR |
| 5372 | X<exp> X<exponential> X<antilog> X<antilogarithm> X<e> | |
| 5373 | 3392 | |
| 5374 | 3393 | =item exp |
| 5375 | 3394 | |
| 5376 | =for Pod::Functions raise I<e> to a power | |
| 5377 | ||
| 5378 | 3395 | =begin original |
| 5379 | 3396 | |
| 5380 | Returns I<e> (the natural logarithm base) to the power of EXPR. | |
| 3397 | Returns I<e> (the natural logarithm base) to the power of EXPR. | |
| 5381 | 3398 | If EXPR is omitted, gives C<exp($_)>. |
| 5382 | 3399 | |
| 5383 | 3400 | =end original |
| 5384 | 3401 | |
| 5385 | I<e> (自然対数の底) の EXPR 乗を返します。 | |
| 3402 | I<e> (自然対数の底) の EXPR 乗を返します。 | |
| 5386 | 3403 | EXPR を省略した場合には、C<exp($_)> を返します。 |
| 5387 | 3404 | |
| 5388 | =item fc EXPR | |
| 5389 | X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold> | |
| 5390 | ||
| 5391 | =item fc | |
| 5392 | ||
| 5393 | =for Pod::Functions +fc return casefolded version of a string | |
| 5394 | ||
| 5395 | =begin original | |
| 5396 | ||
| 5397 | Returns the casefolded version of EXPR. This is the internal function | |
| 5398 | implementing the C<\F> escape in double-quoted strings. | |
| 5399 | ||
| 5400 | =end original | |
| 5401 | ||
| 5402 | EXPR の畳み込み版を返します。 | |
| 5403 | これは、ダブルクォート文字列における、C<\F> エスケープを | |
| 5404 | 実装する内部関数です。 | |
| 5405 | ||
| 5406 | =begin original | |
| 5407 | ||
| 5408 | Casefolding is the process of mapping strings to a form where case | |
| 5409 | differences are erased; comparing two strings in their casefolded | |
| 5410 | form is effectively a way of asking if two strings are equal, | |
| 5411 | regardless of case. | |
| 5412 | ||
| 5413 | =end original | |
| 5414 | ||
| 5415 | 畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です; | |
| 5416 | 畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に | |
| 5417 | 関わらず等しいかどうかを比較する効率的な方法です。 | |
| 5418 | ||
| 5419 | =begin original | |
| 5420 | ||
| 5421 | Roughly, if you ever found yourself writing this | |
| 5422 | ||
| 5423 | =end original | |
| 5424 | ||
| 5425 | おおよそ、自分自身で以下のように書いていたとしても | |
| 5426 | ||
| 5427 | lc($this) eq lc($that) # Wrong! | |
| 5428 | # or | |
| 5429 | uc($this) eq uc($that) # Also wrong! | |
| 5430 | # or | |
| 5431 | $this =~ /^\Q$that\E\z/i # Right! | |
| 5432 | ||
| 5433 | =begin original | |
| 5434 | ||
| 5435 | Now you can write | |
| 5436 | ||
| 5437 | =end original | |
| 5438 | ||
| 5439 | 今では以下のように書けます | |
| 5440 | ||
| 5441 | fc($this) eq fc($that) | |
| 5442 | ||
| 5443 | =begin original | |
| 5444 | ||
| 5445 | And get the correct results. | |
| 5446 | ||
| 5447 | =end original | |
| 5448 | ||
| 5449 | そして正しい結果を得られます。 | |
| 5450 | ||
| 5451 | =begin original | |
| 5452 | ||
| 5453 | Perl only implements the full form of casefolding, but you can access | |
| 5454 | the simple folds using L<Unicode::UCD/B<casefold()>> and | |
| 5455 | L<Unicode::UCD/B<prop_invmap()>>. | |
| 5456 | For further information on casefolding, refer to | |
| 5457 | the Unicode Standard, specifically sections 3.13 C<Default Case Operations>, | |
| 5458 | 4.2 C<Case-Normative>, and 5.18 C<Case Mappings>, | |
| 5459 | available at L<http://www.unicode.org/versions/latest/>, as well as the | |
| 5460 | Case Charts available at L<http://www.unicode.org/charts/case/>. | |
| 5461 | ||
| 5462 | =end original | |
| 5463 | ||
| 5464 | Perl は完全な形式の畳み込みのみを実装していますが、 | |
| 5465 | L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って | |
| 5466 | 単純なたたみ込みにアクセスできます。 | |
| 5467 | 畳み込みに関するさらなる情報については、 | |
| 5468 | L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に | |
| 5469 | 3.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18 | |
| 5470 | C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で | |
| 5471 | 利用可能なケース表を参照してください。 | |
| 5472 | ||
| 5473 | =begin original | |
| 5474 | ||
| 5475 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 5476 | ||
| 5477 | =end original | |
| 5478 | ||
| 5479 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 5480 | ||
| 5481 | =begin original | |
| 5482 | ||
| 5483 | This function behaves the same way under various pragmas, such as within | |
| 5484 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>, | |
| 5485 | as L<C<lc>|/lc EXPR> does, with the single exception of | |
| 5486 | L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the | |
| 5487 | scope of L<S<C<use locale>>|locale>. The foldcase of this character | |
| 5488 | would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR> | |
| 5489 | section, case | |
| 5490 | changes that cross the 255/256 boundary are problematic under locales, | |
| 5491 | and are hence prohibited. Therefore, this function under locale returns | |
| 5492 | instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER | |
| 5493 | LONG S>. Since that character itself folds to C<"s">, the string of two | |
| 5494 | of them together should be equivalent to a single U+1E9E when foldcased. | |
| 5495 | ||
| 5496 | =end original | |
| 5497 | ||
| 5498 | この関数は、 | |
| 5499 | L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature> | |
| 5500 | のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に | |
| 5501 | 振る舞います; | |
| 5502 | 但し、L<S<C<use locale>>|locale> のスコープ内での | |
| 5503 | I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。 | |
| 5504 | この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で | |
| 5505 | 説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は | |
| 5506 | 問題があるので、禁止されています。 | |
| 5507 | 従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である | |
| 5508 | C<"\x{17F}\x{17F}"> を返します。 | |
| 5509 | この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は | |
| 5510 | 畳み込まれた場合は単一の U+1E9E と等価になります。 | |
| 5511 | ||
| 5512 | =begin original | |
| 5513 | ||
| 5514 | While the Unicode Standard defines two additional forms of casefolding, | |
| 5515 | one for Turkic languages and one that never maps one character into multiple | |
| 5516 | characters, these are not provided by the Perl core. However, the CPAN module | |
| 5517 | L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation. | |
| 5518 | ||
| 5519 | =end original | |
| 5520 | ||
| 5521 | Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して | |
| 5522 | 一つの文字が複数の文字にマッピングされないもの、を定義していますが、 | |
| 5523 | これらは Perl コアでは提供されません。 | |
| 5524 | しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を | |
| 5525 | 提供しています。 | |
| 5526 | ||
| 5527 | =begin original | |
| 5528 | ||
| 5529 | L<C<fc>|/fc EXPR> is available only if the | |
| 5530 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is | |
| 5531 | prefixed with C<CORE::>. The | |
| 5532 | L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically | |
| 5533 | with a C<use v5.16> (or higher) declaration in the current scope. | |
| 5534 | ||
| 5535 | =end original | |
| 5536 | ||
| 5537 | L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か | |
| 5538 | C<CORE::> が前置されたときにのみ利用可能です。 | |
| 5539 | L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで | |
| 5540 | C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 5541 | ||
| 5542 | 3405 | =item fcntl FILEHANDLE,FUNCTION,SCALAR |
| 5543 | X<fcntl> | |
| 5544 | 3406 | |
| 5545 | =for Pod::Functions file control system call | |
| 5546 | ||
| 5547 | 3407 | =begin original |
| 5548 | 3408 | |
| 5549 | Implements the | |
| 3409 | Implements the fcntl(2) function. You'll probably have to say | |
| 5550 | 3410 | |
| 5551 | =end original | |
| 5552 | ||
| 5553 | L<fcntl(2)> 関数を実装します。 | |
| 5554 | 正しい定数定義を得るために、まず | |
| 5555 | ||
| 5556 | 3411 | use Fcntl; |
| 5557 | 3412 | |
| 5558 | =begin original | |
| 5559 | ||
| 5560 | 3413 | first to get the correct constant definitions. Argument processing and |
| 5561 | value return | |
| 3414 | value return works just like C<ioctl> below. | |
| 5562 | F | |
| 3415 | For example: | |
| 5563 | 3416 | |
| 5564 | 3417 | =end original |
| 5565 | 3418 | |
| 3419 | fcntl(2) 関数を実装します。 | |
| 3420 | 正しい定数定義を得るために、まず、 | |
| 3421 | ||
| 3422 | use Fcntl; | |
| 3423 | ||
| 5566 | 3424 | と書くことが必要でしょう。 |
| 5567 | 引数の処理と返り値については、下記の | |
| 3425 | 引数の処理と返り値については、下記の C<ioctl> と同様に動作します。 | |
| 5568 | ||
| 3426 | 例: | |
| 5569 | 例えば: | |
| 5570 | 3427 | |
| 5571 | 3428 | use Fcntl; |
| 5572 | | |
| 3429 | fcntl($filehandle, F_GETFL, $packed_return_buffer) | |
| 5573 | ||
| 3430 | or die "can't fcntl F_GETFL: $!"; | |
| 5574 | 3431 | |
| 5575 | 3432 | =begin original |
| 5576 | 3433 | |
| 5577 | You don't have to check for | |
| 3434 | You don't have to check for C<defined> on the return from C<fnctl>. | |
| 5578 | ||
| 3435 | Like C<ioctl>, it maps a C<0> return from the system call into | |
| 5579 | ||
| 3436 | C<"0 but true"> in Perl. This string is true in boolean context and C<0> | |
| 5580 | ||
| 3437 | in numeric context. It is also exempt from the normal B<-w> warnings | |
| 5581 | ||
| 3438 | on improper numeric conversions. | |
| 5582 | the normal | |
| 5583 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 5584 | L<warnings> on improper numeric conversions. | |
| 5585 | 3439 | |
| 5586 | 3440 | =end original |
| 5587 | 3441 | |
| 5588 | ||
| 3442 | C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。 | |
| 5589 | ||
| 3443 | C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合は | |
| 5590 | ||
| 3444 | C<"0 だが真"> を返します。 | |
| 5591 | システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。 | |
| 5592 | 3445 | この文字列は真偽値コンテキストでは真となり、 |
| 5593 | 3446 | 数値コンテキストでは C<0> になります。 |
| 5594 | これはまた、不適切な数値変換に関する通常の | |
| 3447 | これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。 | |
| 5595 | L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s> | |
| 5596 | L<warnings> を回避します。 | |
| 5597 | 3448 | |
| 5598 | 3449 | =begin original |
| 5599 | 3450 | |
| 5600 | Note that | |
| 3451 | Note that C<fcntl> will produce a fatal error if used on a machine that | |
| 5601 | ||
| 3452 | doesn't implement fcntl(2). See the Fcntl module or your fcntl(2) | |
| 5602 | ||
| 3453 | manpage to learn what functions are available on your system. | |
| 5603 | are available on your system. | |
| 5604 | 3454 | |
| 5605 | 3455 | =end original |
| 5606 | 3456 | |
| 5607 | ||
| 3457 | fcntl(2) が実装されていないマシンでは、C<fcntl>は致命的エラーを | |
| 5608 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を | |
| 5609 | 3458 | 引き起こすことに注意してください。 |
| 5610 | システムでどの関数が利用可能かについては | |
| 3459 | システムでどの関数が利用可能かについては Fcntl モジュールや | |
| 5611 | ||
| 3460 | fcntl(2) man ページを参照してください。 | |
| 5612 | 3461 | |
| 5613 | =begin original | |
| 5614 | ||
| 5615 | Here's an example of setting a filehandle named C<$REMOTE> to be | |
| 5616 | non-blocking at the system level. You'll have to negotiate | |
| 5617 | L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though. | |
| 5618 | ||
| 5619 | =end original | |
| 5620 | ||
| 5621 | これは C<$REMOTE> というファイルハンドルをシステムレベルで | |
| 5622 | 非ブロックモードにセットする例です。 | |
| 5623 | ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。 | |
| 5624 | ||
| 5625 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | |
| 5626 | ||
| 5627 | my $flags = fcntl($REMOTE, F_GETFL, 0) | |
| 5628 | or die "Can't get flags for the socket: $!\n"; | |
| 5629 | ||
| 5630 | fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK) | |
| 5631 | or die "Can't set flags for the socket: $!\n"; | |
| 5632 | ||
| 5633 | =begin original | |
| 5634 | ||
| 5635 | Portability issues: L<perlport/fcntl>. | |
| 5636 | ||
| 5637 | =end original | |
| 5638 | ||
| 5639 | 移植性の問題: L<perlport/fcntl>。 | |
| 5640 | ||
| 5641 | =item __FILE__ | |
| 5642 | X<__FILE__> | |
| 5643 | ||
| 5644 | =for Pod::Functions the name of the current source file | |
| 5645 | ||
| 5646 | =begin original | |
| 5647 | ||
| 5648 | A special token that returns the name of the file in which it occurs. | |
| 5649 | ||
| 5650 | =end original | |
| 5651 | ||
| 5652 | これが書いてあるファイルの名前を返す特殊トークン。 | |
| 5653 | ||
| 5654 | 3462 | =item fileno FILEHANDLE |
| 5655 | X<fileno> | |
| 5656 | 3463 | |
| 5657 | =item fileno DIRHANDLE | |
| 5658 | ||
| 5659 | =for Pod::Functions return file descriptor from filehandle | |
| 5660 | ||
| 5661 | 3464 | =begin original |
| 5662 | 3465 | |
| 5663 | Returns the file descriptor for a filehandle or di | |
| 3466 | Returns the file descriptor for a filehandle, or undefined if the | |
| 5664 | ||
| 3467 | filehandle is not open. This is mainly useful for constructing | |
| 5665 | ||
| 3468 | bitmaps for C<select> and low-level POSIX tty-handling operations. | |
| 5666 | level, as can happen with filehandles connected to memory objects via | |
| 5667 | L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third | |
| 5668 | argument, -1 is returned. | |
| 5669 | ||
| 5670 | =end original | |
| 5671 | ||
| 5672 | ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します; | |
| 5673 | ファイルハンドルがオープンしていない場合は未定義値を返します。 | |
| 5674 | OS レベルで実際のファイル記述子がない(L<C<open>|/open FILEHANDLE,EXPR> の | |
| 5675 | 第 3 引数にリファレンスを | |
| 5676 | 指定してファイルハンドルがメモリオブジェクトと結びつけられたときに | |
| 5677 | 起こります)場合、-1 が返されます。 | |
| 5678 | ||
| 5679 | =begin original | |
| 5680 | ||
| 5681 | This is mainly useful for constructing bitmaps for | |
| 5682 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX | |
| 5683 | tty-handling operations. | |
| 5684 | 3469 | If FILEHANDLE is an expression, the value is taken as an indirect |
| 5685 | 3470 | filehandle, generally its name. |
| 5686 | 3471 | |
| 5687 | 3472 | =end original |
| 5688 | 3473 | |
| 5689 | ||
| 3474 | ファイルハンドルに対するファイル記述子を返します。 | |
| 5690 | ||
| 3475 | ファイルハンドルがオープンしていない場合は未定義値を返します。 | |
| 3476 | これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを | |
| 3477 | 構成するときに便利です。 | |
| 5691 | 3478 | FILEHANDLE が式であれば、 |
| 5692 | 3479 | その値が間接ファイルハンドル(普通は名前)として使われます。 |
| 5693 | 3480 | |
| 5694 | 3481 | =begin original |
| 5695 | 3482 | |
| 5696 | You can use this to find out whether two handles refer to the | |
| 3483 | You can use this to find out whether two handles refer to the | |
| 5697 | 3484 | same underlying descriptor: |
| 5698 | 3485 | |
| 5699 | 3486 | =end original |
| 5700 | 3487 | |
| 5701 | これを、二つのハンドルが同じ | |
| 3488 | これを、二つのハンドルが同じ記述子を参照しているかどうかを | |
| 5702 | 使えます: | |
| 3489 | 調べるのに使えます: | |
| 5703 | 3490 | |
| 5704 | if (fileno( | |
| 3491 | if (fileno(THIS) == fileno(THAT)) { | |
| 5705 | ||
| 3492 | print "THIS and THAT are dups\n"; | |
| 5706 | } | |
| 3493 | } | |
| 5707 | print "\$this and \$that have different " . | |
| 5708 | "underlying file descriptors\n"; | |
| 5709 | } else { | |
| 5710 | print "At least one of \$this and \$that does " . | |
| 5711 | "not have a real file descriptor\n"; | |
| 5712 | } | |
| 5713 | 3494 | |
| 5714 | =begin original | |
| 5715 | ||
| 5716 | The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle | |
| 5717 | depends on the operating system. On a system with L<dirfd(3)> or | |
| 5718 | similar, L<C<fileno>|/fileno FILEHANDLE> on a directory | |
| 5719 | handle returns the underlying file descriptor associated with the | |
| 5720 | handle; on systems with no such support, it returns the undefined value, | |
| 5721 | and sets L<C<$!>|perlvar/$!> (errno). | |
| 5722 | ||
| 5723 | =end original | |
| 5724 | ||
| 5725 | ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは | |
| 5726 | オペレーティングシステムに依存します。 | |
| 5727 | L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する | |
| 5728 | L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる | |
| 5729 | ファイル記述子を返します; | |
| 5730 | そのような対応がないシステムでは、未定義値を返し、 | |
| 5731 | L<C<$!>|perlvar/$!> (errno) を設定します。 | |
| 5732 | ||
| 5733 | 3495 | =item flock FILEHANDLE,OPERATION |
| 5734 | X<flock> X<lock> X<locking> | |
| 5735 | 3496 | |
| 5736 | =for Pod::Functions lock an entire file with an advisory lock | |
| 5737 | ||
| 5738 | 3497 | =begin original |
| 5739 | 3498 | |
| 5740 | Calls | |
| 3499 | Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true | |
| 5741 | 3500 | for success, false on failure. Produces a fatal error if used on a |
| 5742 | machine that doesn't implement | |
| 3501 | machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3). | |
| 5743 | ||
| 3502 | C<flock> is Perl's portable file locking interface, although it locks | |
| 5744 | ||
| 3503 | only entire files, not records. | |
| 5745 | records. | |
| 5746 | 3504 | |
| 5747 | 3505 | =end original |
| 5748 | 3506 | |
| 5749 | FILEHANDLE に対して | |
| 3507 | FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。 | |
| 5750 | 3508 | 成功時には真を、失敗時には偽を返します。 |
| 5751 | ||
| 3509 | flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない | |
| 5752 | 3510 | マシンで使うと、致命的エラーが発生します。 |
| 5753 | ||
| 3511 | C<flock> は Perl の移植性のあるファイルロックインターフェースです。 | |
| 5754 | ファイルロックインターフェースです; | |
| 5755 | 3512 | しかしレコードではなく、ファイル全体のみをロックします。 |
| 5756 | 3513 | |
| 5757 | 3514 | =begin original |
| 5758 | 3515 | |
| 5759 | Two potentially non-obvious but traditional | |
| 3516 | Two potentially non-obvious but traditional C<flock> semantics are | |
| 5760 | FILEHANDLE,OPERATION> semantics are | |
| 5761 | 3517 | that it waits indefinitely until the lock is granted, and that its locks |
| 5762 | ||
| 3518 | B<merely advisory>. Such discretionary locks are more flexible, but offer | |
| 5763 | ||
| 3519 | fewer guarantees. This means that files locked with C<flock> may be | |
| 5764 | ||
| 3520 | modified by programs that do not also use C<flock>. See L<perlport>, | |
| 5765 | ||
| 3521 | your port's specific documentation, or your system-specific local manpages | |
| 5766 | your port's specific documentation, and your system-specific local manpages | |
| 5767 | 3522 | for details. It's best to assume traditional behavior if you're writing |
| 5768 | 3523 | portable programs. (But if you're not, you should as always feel perfectly |
| 5769 | 3524 | free to write for your own system's idiosyncrasies (sometimes called |
| 5770 | 3525 | "features"). Slavish adherence to portability concerns shouldn't get |
| 5771 | 3526 | in the way of your getting your job done.) |
| 5772 | 3527 | |
| 5773 | 3528 | =end original |
| 5774 | 3529 | |
| 5775 | 明白ではないものの、伝統的な | |
| 3530 | 明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで | |
| 5776 | 動作としては、ロックが得られるまで | |
| 5777 | 3531 | 無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。 |
| 5778 | 3532 | このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。 |
| 5779 | これは、 | |
| 3533 | これは、C<flock> でロックされたファイルは C<flock> を使わない | |
| 5780 | ||
| 3534 | プログラムによって書き換えられるかもしれないことを意味します。 | |
| 5781 | 書き換えるかもしれないことを意味します。 | |
| 5782 | 3535 | 詳細については、L<perlport>、システム固有のドキュメント、システム固有の |
| 5783 | 3536 | ローカルの man ページを参照してください。 |
| 5784 | 3537 | 移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが |
| 5785 | 3538 | ベストです。 |
| 5786 | 3539 | (しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば |
| 5787 | 3540 | 「仕様」と呼ばれます)に合わせて書くことも完全に自由です。 |
| 5788 | 3541 | 盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは |
| 5789 | 3542 | ありません。) |
| 5790 | 3543 | |
| 5791 | 3544 | =begin original |
| 5792 | 3545 | |
| 5793 | 3546 | OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with |
| 5794 | 3547 | LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but |
| 5795 | you can use the symbolic names if you import them from the | |
| 3548 | you can use the symbolic names if you import them from the Fcntl module, | |
| 5796 | either individually, or as a group using the | |
| 3549 | either individually, or as a group using the ':flock' tag. LOCK_SH | |
| 5797 | 3550 | requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN |
| 5798 | 3551 | releases a previously requested lock. If LOCK_NB is bitwise-or'ed with |
| 5799 | LOCK_SH or LOCK_EX | |
| 3552 | LOCK_SH or LOCK_EX then C<flock> will return immediately rather than blocking | |
| 5800 | ||
| 3553 | waiting for the lock (check the return status to see if you got it). | |
| 5801 | status to see if you got it. | |
| 5802 | 3554 | |
| 5803 | 3555 | =end original |
| 5804 | 3556 | |
| 5805 | 3557 | OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と |
| 5806 | 3558 | 組み合わされることもあります。 |
| 5807 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、 | |
| 3559 | これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、Fcntl モジュールから | |
| 5808 | シンボル名を独立してインポートするか、 | |
| 3560 | シンボル名を独立してインポートするか、 ':flock' タグを使うグループとして、 | |
| 5809 | 3561 | シンボル名をを使うことができます。 |
| 5810 | 3562 | LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は |
| 5811 | 3563 | 前回要求したロックを開放します。 |
| 5812 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、 | |
| 3564 | LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は | |
| 5813 | ||
| 3565 | ロックを取得するまで待つのではなく、すぐに返ります(ロックが取得できたか | |
| 5814 | ||
| 3566 | どうかは返り値を調べます)。 | |
| 5815 | ロックが取得できたかどうかは返り値を調べます。 | |
| 5816 | 3567 | |
| 5817 | 3568 | =begin original |
| 5818 | 3569 | |
| 5819 | 3570 | To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE |
| 5820 | 3571 | before locking or unlocking it. |
| 5821 | 3572 | |
| 5822 | 3573 | =end original |
| 5823 | 3574 | |
| 5824 | 3575 | 不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に |
| 5825 | 3576 | FILEHANDLE をフラッシュします。 |
| 5826 | 3577 | |
| 5827 | 3578 | =begin original |
| 5828 | 3579 | |
| 5829 | Note that the emulation built with | |
| 3580 | Note that the emulation built with lockf(3) doesn't provide shared | |
| 5830 | 3581 | locks, and it requires that FILEHANDLE be open with write intent. These |
| 5831 | are the semantics that | |
| 3582 | are the semantics that lockf(3) implements. Most if not all systems | |
| 5832 | implement | |
| 3583 | implement lockf(3) in terms of fcntl(2) locking, though, so the | |
| 5833 | 3584 | differing semantics shouldn't bite too many people. |
| 5834 | 3585 | |
| 5835 | 3586 | =end original |
| 5836 | 3587 | |
| 5837 | ||
| 3588 | lockf(3) で作成されたエミュレーションは共有ロックを提供せず、 | |
| 5838 | 3589 | FILEHANDLE が書き込みモードで開いていることを必要とすることに |
| 5839 | 3590 | 注意してください。 |
| 5840 | これは | |
| 3591 | これは lockf(3) が実装している動作です。 | |
| 5841 | しかし、全てではないにしてもほとんどのシステムでは | |
| 3592 | しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って | |
| 5842 | ||
| 3593 | lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは | |
| 5843 | 3594 | ないはずです。 |
| 5844 | 3595 | |
| 5845 | 3596 | =begin original |
| 5846 | 3597 | |
| 5847 | Note that | |
| 3598 | Note also that some versions of C<flock> cannot lock things over the | |
| 5848 | ||
| 3599 | network; you would need to use the more system-specific C<fcntl> for | |
| 5849 | ||
| 3600 | that. If you like you can force Perl to ignore your system's flock(2) | |
| 3601 | function, and so provide its own fcntl(2)-based emulation, by passing | |
| 5851 | =end original | |
| 5852 | ||
| 5853 | L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには | |
| 5854 | FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには | |
| 5855 | 書き込みで開いている必要があることに注意してください。 | |
| 5856 | ||
| 5857 | =begin original | |
| 5858 | ||
| 5859 | Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION> | |
| 5860 | cannot lock things over the network; you would need to use the more | |
| 5861 | system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for | |
| 5862 | that. If you like you can force Perl to ignore your system's L<flock(2)> | |
| 5863 | function, and so provide its own L<fcntl(2)>-based emulation, by passing | |
| 5864 | 3602 | the switch C<-Ud_flock> to the F<Configure> program when you configure |
| 5865 | ||
| 3603 | perl. | |
| 5866 | 3604 | |
| 5867 | 3605 | =end original |
| 5868 | 3606 | |
| 5869 | ネットワーク越しにはロックできない | |
| 3607 | ネットワーク越しにはロックできない C<flock> もあることに注意してください; | |
| 5870 | ||
| 3608 | このためには、よりシステム依存な C<fcntl> を使う必要があります。 | |
| 5871 | ||
| 3609 | Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの | |
| 5872 | ||
| 3610 | エミュレーションを使う場合は、perl を設定するときに F<Configure> | |
| 5873 | ||
| 3611 | プログラムに C<-Ud_flock> オプションを渡してください。 | |
| 5874 | エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに | |
| 5875 | F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。 | |
| 5876 | 3612 | |
| 5877 | 3613 | =begin original |
| 5878 | 3614 | |
| 5879 | 3615 | Here's a mailbox appender for BSD systems. |
| 5880 | 3616 | |
| 5881 | 3617 | =end original |
| 5882 | 3618 | |
| 5883 | 3619 | BSD システムでのメールボックスへの追加処理の例を示します。 |
| 5884 | 3620 | |
| 5885 | # import LOCK_* | |
| 3621 | use Fcntl ':flock'; # import LOCK_* constants | |
| 5886 | use Fcntl qw(:flock SEEK_END); | |
| 5887 | 3622 | |
| 5888 | 3623 | sub lock { |
| 5889 | ||
| 3624 | flock(MBOX,LOCK_EX); | |
| 5890 | | |
| 3625 | # and, in case someone appended | |
| 5891 | ||
| 3626 | # while we were waiting... | |
| 5892 | ||
| 3627 | seek(MBOX, 0, 2); | |
| 5893 | seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n"; | |
| 5894 | 3628 | } |
| 5895 | 3629 | |
| 5896 | 3630 | sub unlock { |
| 5897 | ||
| 3631 | flock(MBOX,LOCK_UN); | |
| 5898 | flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n"; | |
| 5899 | 3632 | } |
| 5900 | 3633 | |
| 5901 | open( | |
| 3634 | open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}") | |
| 5902 | ||
| 3635 | or die "Can't open mailbox: $!"; | |
| 5903 | 3636 | |
| 5904 | lock( | |
| 3637 | lock(); | |
| 5905 | print | |
| 3638 | print MBOX $msg,"\n\n"; | |
| 5906 | unlock( | |
| 3639 | unlock(); | |
| 5907 | 3640 | |
| 5908 | 3641 | =begin original |
| 5909 | 3642 | |
| 5910 | On systems that support a real | |
| 3643 | On systems that support a real flock(), locks are inherited across fork() | |
| 5911 | ||
| 3644 | calls, whereas those that must resort to the more capricious fcntl() | |
| 5912 | ||
| 3645 | function lose the locks, making it harder to write servers. | |
| 5913 | harder to write servers. | |
| 5914 | 3646 | |
| 5915 | 3647 | =end original |
| 5916 | 3648 | |
| 5917 | 真の | |
| 3649 | 真の flock() に対応しているシステムではロックは fork() を通して | |
| 5918 | 継承されるのに対して、より不安定な | |
| 3650 | 継承されるのに対して、より不安定な fcntl() に頼らなければならない場合、 | |
| 5919 | サーバを書くのは | |
| 3651 | サーバを書くのはより難しくなります。 | |
| 5920 | 3652 | |
| 5921 | 3653 | =begin original |
| 5922 | 3654 | |
| 5923 | See also L<DB_File> for other | |
| 3655 | See also L<DB_File> for other flock() examples. | |
| 5924 | examples. | |
| 5925 | 3656 | |
| 5926 | 3657 | =end original |
| 5927 | 3658 | |
| 5928 | その他の | |
| 3659 | その他の flock() の例としては L<DB_File> も参照してください。 | |
| 5929 | 参照してください。 | |
| 5930 | 3660 | |
| 5931 | =begin original | |
| 5932 | ||
| 5933 | Portability issues: L<perlport/flock>. | |
| 5934 | ||
| 5935 | =end original | |
| 5936 | ||
| 5937 | 移植性の問題: L<perlport/flock>。 | |
| 5938 | ||
| 5939 | 3661 | =item fork |
| 5940 | X<fork> X<child> X<parent> | |
| 5941 | 3662 | |
| 5942 | =for Pod::Functions create a new process just like this one | |
| 5943 | ||
| 5944 | 3663 | =begin original |
| 5945 | 3664 | |
| 5946 | Does a | |
| 3665 | Does a fork(2) system call to create a new process running the | |
| 5947 | 3666 | same program at the same point. It returns the child pid to the |
| 5948 | parent process, C<0> to the child process, or | |
| 3667 | parent process, C<0> to the child process, or C<undef> if the fork is | |
| 5949 | the fork is | |
| 5950 | 3668 | unsuccessful. File descriptors (and sometimes locks on those descriptors) |
| 5951 | 3669 | are shared, while everything else is copied. On most systems supporting |
| 5952 | ||
| 3670 | fork(), great care has gone into making it extremely efficient (for | |
| 5953 | 3671 | example, using copy-on-write technology on data pages), making it the |
| 5954 | 3672 | dominant paradigm for multitasking over the last few decades. |
| 5955 | 3673 | |
| 5956 | 3674 | =end original |
| 5957 | 3675 | |
| 5958 | 3676 | 同じプログラムの同じ地点から開始する新しいプロセスを作成するために |
| 5959 | システムコール | |
| 3677 | システムコール fork(2) を行ないます。 | |
| 5960 | 3678 | 親プロセスには、チャイルドプロセスの pid を、 |
| 5961 | 3679 | チャイルドプロセスに C<0> を返しますが、 |
| 5962 | fork に失敗したときには、 | |
| 3680 | fork に失敗したときには、C<undef>を返します。 | |
| 5963 | 3681 | ファイル記述子(および記述子に関連するロック)は共有され、 |
| 5964 | 3682 | その他の全てはコピーされます。 |
| 5965 | ||
| 3683 | fork() に対応するほとんどのシステムでは、 | |
| 5966 | 3684 | これを極めて効率的にするために多大な努力が払われてきました |
| 5967 | (例えば、データページへの copy-on-write テクノロジーなどです) | |
| 3685 | (例えば、データページへの copy-on-write テクノロジーなどです)。 | |
| 5968 | 3686 | これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。 |
| 5969 | 3687 | |
| 5970 | 3688 | =begin original |
| 5971 | 3689 | |
| 5972 | Perl attempt | |
| 3690 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
| 5973 | child process, but this may not be supported | |
| 3691 | output before forking the child process, but this may not be supported | |
| 5974 | L<perlport>). To be safe, you may need to set | |
| 3692 | on some platforms (see L<perlport>). To be safe, you may need to set | |
| 5975 | ||
| 3693 | C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of | |
| 5976 | ||
| 3694 | C<IO::Handle> on any open handles in order to avoid duplicate output. | |
| 5977 | any open handles to avoid duplicate output. | |
| 5978 | 3695 | |
| 5979 | 3696 | =end original |
| 5980 | 3697 | |
| 5981 | 3698 | v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての |
| 5982 | 3699 | ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも |
| 5983 | 3700 | あります(L<perlport> を参照してください)。 |
| 5984 | 3701 | 安全のためには、出力が重複するのを避けるために、 |
| 5985 | 全てのオープンしているハンドルに対して | |
| 3702 | 全てのオープンしているハンドルに対して C<$|> (English モジュールでは | |
| 5986 | ||
| 3703 | $AUTOFLUSH) を設定するか、 | |
| 5987 | ||
| 3704 | C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が | |
| 5988 | ||
| 3705 | あるかもしれません。 | |
| 5989 | 3706 | |
| 5990 | 3707 | =begin original |
| 5991 | 3708 | |
| 5992 | If you | |
| 3709 | If you C<fork> without ever waiting on your children, you will | |
| 5993 | 3710 | accumulate zombies. On some systems, you can avoid this by setting |
| 5994 | ||
| 3711 | C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of | |
| 5995 | ||
| 3712 | forking and reaping moribund children. | |
| 5996 | 3713 | |
| 5997 | 3714 | =end original |
| 5998 | 3715 | |
| 5999 | チャイルドプロセスの終了を待たずに、 | |
| 3716 | チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、 | |
| 6000 | 3717 | ゾンビをためこむことになります。 |
| 6001 | ||
| 3718 | C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。 | |
| 6002 | 回避できるシステムもあります。 | |
| 6003 | 3719 | fork と消滅しかけている子プロセスを回収するための更なる例については |
| 6004 | 3720 | L<perlipc> も参照してください。 |
| 6005 | 3721 | |
| 6006 | 3722 | =begin original |
| 6007 | 3723 | |
| 6008 | 3724 | Note that if your forked child inherits system file descriptors like |
| 6009 | 3725 | STDIN and STDOUT that are actually connected by a pipe or socket, even |
| 6010 | 3726 | if you exit, then the remote server (such as, say, a CGI script or a |
| 6011 | 3727 | backgrounded job launched from a remote shell) won't think you're done. |
| 6012 | 3728 | You should reopen those to F</dev/null> if it's any issue. |
| 6013 | 3729 | |
| 6014 | 3730 | =end original |
| 6015 | 3731 | |
| 6016 | 3732 | fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を |
| 6017 | 3733 | 継承する場合、(CGI スクリプトやリモートシェルといった |
| 6018 | 3734 | バックグラウンドジョブのような)リモートサーバは考え通りに |
| 6019 | 3735 | 動かないであろうことに注意してください。 |
| 6020 | 3736 | このような場合ではこれらを F</dev/null> として再オープンするべきです。 |
| 6021 | 3737 | |
| 6022 | =begin original | |
| 6023 | ||
| 6024 | On some platforms such as Windows, where the L<fork(2)> system call is | |
| 6025 | not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl | |
| 6026 | interpreter. The emulation is designed, at the level of the Perl | |
| 6027 | program, to be as compatible as possible with the "Unix" L<fork(2)>. | |
| 6028 | However it has limitations that have to be considered in code intended | |
| 6029 | to be portable. See L<perlfork> for more details. | |
| 6030 | ||
| 6031 | =end original | |
| 6032 | ||
| 6033 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
| 6034 | L<C<fork>|/fork> を Perl インタプリタでエミュレートします。 | |
| 6035 | エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と | |
| 6036 | 互換性があるように設計されています。 | |
| 6037 | しかしコードが移植性があると考えられるように制限があります。 | |
| 6038 | さらなる詳細については L<perlfork> を参照してください。 | |
| 6039 | ||
| 6040 | =begin original | |
| 6041 | ||
| 6042 | Portability issues: L<perlport/fork>. | |
| 6043 | ||
| 6044 | =end original | |
| 6045 | ||
| 6046 | 移植性の問題: L<perlport/fork>。 | |
| 6047 | ||
| 6048 | 3738 | =item format |
| 6049 | X<format> | |
| 6050 | 3739 | |
| 6051 | =for Pod::Functions declare a picture format with use by the write() function | |
| 6052 | ||
| 6053 | 3740 | =begin original |
| 6054 | 3741 | |
| 6055 | Declare a picture format for use by the | |
| 3742 | Declare a picture format for use by the C<write> function. For | |
| 6056 | ||
| 3743 | example: | |
| 6057 | 3744 | |
| 6058 | 3745 | =end original |
| 6059 | 3746 | |
| 6060 | ||
| 3747 | C<write> 関数で使うピクチャーフォーマットを宣言します。 | |
| 6061 | 例 | |
| 3748 | 例: | |
| 6062 | 3749 | |
| 6063 | 3750 | format Something = |
| 6064 | ||
| 3751 | Test: @<<<<<<<< @||||| @>>>>> | |
| 6065 | ||
| 3752 | $str, $%, '$' . int($num) | |
| 6066 | 3753 | . |
| 6067 | 3754 | |
| 6068 | 3755 | $str = "widget"; |
| 6069 | 3756 | $num = $cost/$quantity; |
| 6070 | 3757 | $~ = 'Something'; |
| 6071 | 3758 | write; |
| 6072 | 3759 | |
| 6073 | 3760 | =begin original |
| 6074 | 3761 | |
| 6075 | 3762 | See L<perlform> for many details and examples. |
| 6076 | 3763 | |
| 6077 | 3764 | =end original |
| 6078 | 3765 | |
| 6079 | 詳細と例については L<perlform> を参照して | |
| 3766 | 詳細と例については L<perlform> を参照して下さい。 | |
| 6080 | 3767 | |
| 6081 | 3768 | =item formline PICTURE,LIST |
| 6082 | X<formline> | |
| 6083 | 3769 | |
| 6084 | =for Pod::Functions internal function used for formats | |
| 6085 | ||
| 6086 | 3770 | =begin original |
| 6087 | 3771 | |
| 6088 | This is an internal function used by | |
| 3772 | This is an internal function used by C<format>s, though you may call it, | |
| 6089 | ||
| 3773 | too. It formats (see L<perlform>) a list of values according to the | |
| 6090 | ||
| 3774 | contents of PICTURE, placing the output into the format output | |
| 6091 | ||
| 3775 | accumulator, C<$^A> (or C<$ACCUMULATOR> in English). | |
| 6092 | ||
| 3776 | Eventually, when a C<write> is done, the contents of | |
| 6093 | ||
| 3777 | C<$^A> are written to some filehandle, but you could also read C<$^A> | |
| 6094 | ||
| 3778 | yourself and then set C<$^A> back to C<"">. Note that a format typically | |
| 6095 | ||
| 3779 | does one C<formline> per line of form, but the C<formline> function itself | |
| 6096 | one | |
| 3780 | doesn't care how many newlines are embedded in the PICTURE. This means | |
| 6097 | ||
| 3781 | that the C<~> and C<~~> tokens will treat the entire PICTURE as a single line. | |
| 6098 | ma | |
| 3782 | You may therefore need to use multiple formlines to implement a single | |
| 6099 | ||
| 3783 | record format, just like the format compiler. | |
| 6100 | therefore need to use multiple formlines to implement a single record | |
| 6101 | format, just like the L<C<format>|/format> compiler. | |
| 6102 | 3784 | |
| 6103 | 3785 | =end original |
| 6104 | 3786 | |
| 6105 | これは、 | |
| 3787 | これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。 | |
| 6106 | ||
| 3788 | これは、PICTURE の内容にしたがって、 | |
| 6107 | ||
| 3789 | LIST の値を整形し (perlform manpage を参照してください)、 | |
| 6108 | ||
| 3790 | 結果をフォーマット出力アキュムレータ | |
| 6109 | ||
| 3791 | C<$^A>(English モジュールでは C<$ACCUMULATOR>) に納めます。 | |
| 6110 | 最終的に、 | |
| 3792 | 最終的に、C<write> が実行されると、C<$^A> の中身が、 | |
| 6111 | ||
| 3793 | 何らかのファイルハンドルに書き出されますが、自分で C<$^A> を読んで、 | |
| 6112 | ||
| 3794 | C<$^A> の内容を C<""> に戻してもかまいません。 | |
| 6113 | C< | |
| 3795 | format は通常、1 行ごとに C<formline> を行ないますが、 | |
| 6114 | ||
| 3796 | C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、 | |
| 6115 | ||
| 3797 | 関係がありません。 | |
| 6116 | いくつの改行が入っているかは、関係がありません。 | |
| 6117 | 3798 | これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。 |
| 6118 | 3799 | 従って、1 レコードフォーマットを実装するためには |
| 6119 | ||
| 3800 | フォーマットコンパイラのような複数 formline を使う必要があります。 | |
| 6120 | 3801 | |
| 6121 | 3802 | =begin original |
| 6122 | 3803 | |
| 6123 | 3804 | Be careful if you put double quotes around the picture, because an C<@> |
| 6124 | 3805 | character may be taken to mean the beginning of an array name. |
| 6125 | ||
| 3806 | C<formline> always returns true. See L<perlform> for other examples. | |
| 6126 | L<perlform> for other examples. | |
| 6127 | 3807 | |
| 6128 | 3808 | =end original |
| 6129 | 3809 | |
| 6130 | 3810 | ダブルクォートで PICTURE を囲む場合には、C<@> という文字が |
| 6131 | 3811 | 配列名の始まりと解釈されますので、注意してください。 |
| 6132 | ||
| 3812 | C<formline> は常に真を返します。 | |
| 6133 | 3813 | その他の例については L<perlform> を参照してください。 |
| 6134 | 3814 | |
| 6135 | =begin original | |
| 6136 | ||
| 6137 | If you are trying to use this instead of L<C<write>|/write FILEHANDLE> | |
| 6138 | to capture the output, you may find it easier to open a filehandle to a | |
| 6139 | scalar (C<< open my $fh, ">", \$output >>) and write to that instead. | |
| 6140 | ||
| 6141 | =end original | |
| 6142 | ||
| 6143 | 出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを | |
| 6144 | 使おうとした場合、スカラにファイルハンドルを開いて | |
| 6145 | (C<< open my $fh, ">", \$output >>)、 | |
| 6146 | 代わりにここに出力する方が簡単であることに気付くでしょう。 | |
| 6147 | ||
| 6148 | 3815 | =item getc FILEHANDLE |
| 6149 | X<getc> X<getchar> X<character> X<file, read> | |
| 6150 | 3816 | |
| 6151 | 3817 | =item getc |
| 6152 | 3818 | |
| 6153 | =for Pod::Functions get the next character from the filehandle | |
| 6154 | ||
| 6155 | 3819 | =begin original |
| 6156 | 3820 | |
| 6157 | 3821 | Returns the next character from the input file attached to FILEHANDLE, |
| 6158 | or the undefined value at end of file or if there was an error | |
| 3822 | or the undefined value at end of file, or if there was an error. | |
| 6159 | ||
| 3823 | If FILEHANDLE is omitted, reads from STDIN. This is not particularly | |
| 6160 | ||
| 3824 | efficient. However, it cannot be used by itself to fetch single | |
| 6161 | ||
| 3825 | characters without waiting for the user to hit enter. For that, try | |
| 6162 | ||
| 3826 | something more like: | |
| 6163 | to hit enter. For that, try something more like: | |
| 6164 | 3827 | |
| 6165 | 3828 | =end original |
| 6166 | 3829 | |
| 6167 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します | |
| 3830 | FILEHANDLE につながれている入力ファイルから、次の一文字を返します。 | |
| 6168 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します | |
| 3831 | ファイルの最後、またはエラーが発生した場合は、未定義値を返します。 | |
| 6169 | (後者の場合は L<C<$!>|perlvar/$!> がセットされます)。 | |
| 6170 | 3832 | FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。 |
| 6171 | 3833 | これは特に効率的ではありません。 |
| 6172 | 3834 | しかし、これはユーザーがリターンキーを押すのを待つことなく |
| 6173 | 3835 | 一文字を読み込む用途には使えません。 |
| 6174 | 3836 | そのような場合には、以下のようなものを試して見てください: |
| 6175 | 3837 | |
| 6176 | 3838 | if ($BSD_STYLE) { |
| 6177 | ||
| 3839 | system "stty cbreak </dev/tty >/dev/tty 2>&1"; | |
| 6178 | 3840 | } |
| 6179 | 3841 | else { |
| 6180 | ||
| 3842 | system "stty", '-icanon', 'eol', "\001"; | |
| 6181 | 3843 | } |
| 6182 | 3844 | |
| 6183 | | |
| 3845 | $key = getc(STDIN); | |
| 6184 | 3846 | |
| 6185 | 3847 | if ($BSD_STYLE) { |
| 6186 | ||
| 3848 | system "stty -cbreak </dev/tty >/dev/tty 2>&1"; | |
| 6187 | 3849 | } |
| 6188 | 3850 | else { |
| 6189 | ||
| 3851 | system "stty", 'icanon', 'eol', '^@'; # ASCII null | |
| 6190 | 3852 | } |
| 6191 | 3853 | print "\n"; |
| 6192 | 3854 | |
| 6193 | 3855 | =begin original |
| 6194 | 3856 | |
| 6195 | Determination of whether | |
| 3857 | Determination of whether $BSD_STYLE should be set | |
| 6196 | exercise to the reader. | |
| 3858 | is left as an exercise to the reader. | |
| 6197 | 3859 | |
| 6198 | 3860 | =end original |
| 6199 | 3861 | |
| 6200 | ||
| 3862 | $BSD_STYLE をセットするべきかどうかを決定する方法については | |
| 6201 | 3863 | 読者への宿題として残しておきます。 |
| 6202 | 3864 | |
| 6203 | 3865 | =begin original |
| 6204 | 3866 | |
| 6205 | The | |
| 3867 | The C<POSIX::getattr> function can do this more portably on | |
| 6206 | ||
| 3868 | systems purporting POSIX compliance. See also the C<Term::ReadKey> | |
| 6207 | ||
| 3869 | module from your nearest CPAN site; details on CPAN can be found on | |
| 3870 | L<perlmodlib/CPAN>. | |
| 6208 | 3871 | |
| 6209 | 3872 | =end original |
| 6210 | 3873 | |
| 6211 | ||
| 3874 | C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムで | |
| 6212 | これをより移植性のある形で行います。 | |
| 3875 | これをより移植性のある形で行います。お近くの CPAN サイトから | |
| 6213 | C | |
| 3876 | C<Term::ReadKey> モジュールも参照して下さい; CPAN に関する詳細は | |
| 6214 | ||
| 3877 | L<perlmodlib/CPAN> にあります。 | |
| 6215 | 3878 | |
| 6216 | 3879 | =item getlogin |
| 6217 | X<getlogin> X<login> | |
| 6218 | 3880 | |
| 6219 | =for Pod::Functions return who logged in at this tty | |
| 6220 | ||
| 6221 | 3881 | =begin original |
| 6222 | 3882 | |
| 6223 | ||
| 3883 | Implements the C library function of the same name, which on most | |
| 6224 | systems returns the current login from F</etc/utmp>, if any. If | |
| 3884 | systems returns the current login from F</etc/utmp>, if any. If null, | |
| 6225 | ||
| 3885 | use C<getpwuid>. | |
| 6226 | 3886 | |
| 6227 | 3887 | =end original |
| 6228 | 3888 | |
| 6229 | ||
| 3889 | 同じ名前の C ライブラリ関数の実装です。 | |
| 6230 | 多くのシステムでは、もしあれば、 | |
| 3890 | 多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。 | |
| 6231 | ||
| 3891 | ヌルであれば、getpwuid() を使ってください。 | |
| 6232 | 使ってください。 | |
| 6233 | 3892 | |
| 6234 | | |
| 3893 | $login = getlogin || getpwuid($<) || "Kilroy"; | |
| 6235 | 3894 | |
| 6236 | 3895 | =begin original |
| 6237 | 3896 | |
| 6238 | Do not consider | |
| 3897 | Do not consider C<getlogin> for authentication: it is not as | |
| 6239 | ||
| 3898 | secure as C<getpwuid>. | |
| 6240 | 3899 | |
| 6241 | 3900 | =end original |
| 6242 | 3901 | |
| 6243 | ||
| 3902 | C<getlogin> を認証に使ってはいけません。 | |
| 6244 | ||
| 3903 | これは C<getpwuid> のように安全ではありません。 | |
| 6245 | 3904 | |
| 6246 | =begin original | |
| 6247 | ||
| 6248 | Portability issues: L<perlport/getlogin>. | |
| 6249 | ||
| 6250 | =end original | |
| 6251 | ||
| 6252 | 移植性の問題: L<perlport/getlogin>。 | |
| 6253 | ||
| 6254 | 3905 | =item getpeername SOCKET |
| 6255 | X<getpeername> X<peer> | |
| 6256 | 3906 | |
| 6257 | =for Pod::Functions find the other end of a socket connection | |
| 6258 | ||
| 6259 | 3907 | =begin original |
| 6260 | 3908 | |
| 6261 | Returns the packed sockaddr address of | |
| 3909 | Returns the packed sockaddr address of other end of the SOCKET connection. | |
| 6262 | connection. | |
| 6263 | 3910 | |
| 6264 | 3911 | =end original |
| 6265 | 3912 | |
| 6266 | 3913 | SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。 |
| 6267 | 3914 | |
| 6268 | 3915 | use Socket; |
| 6269 | | |
| 3916 | $hersockaddr = getpeername(SOCK); | |
| 6270 | | |
| 3917 | ($port, $iaddr) = sockaddr_in($hersockaddr); | |
| 6271 | | |
| 3918 | $herhostname = gethostbyaddr($iaddr, AF_INET); | |
| 6272 | | |
| 3919 | $herstraddr = inet_ntoa($iaddr); | |
| 6273 | 3920 | |
| 6274 | 3921 | =item getpgrp PID |
| 6275 | X<getpgrp> X<group> | |
| 6276 | 3922 | |
| 6277 | =for Pod::Functions get process group | |
| 6278 | ||
| 6279 | 3923 | =begin original |
| 6280 | 3924 | |
| 6281 | 3925 | Returns the current process group for the specified PID. Use |
| 6282 | 3926 | a PID of C<0> to get the current process group for the |
| 6283 | 3927 | current process. Will raise an exception if used on a machine that |
| 6284 | doesn't implement | |
| 3928 | doesn't implement getpgrp(2). If PID is omitted, returns process | |
| 6285 | group of | |
| 3929 | group of current process. Note that the POSIX version of C<getpgrp> | |
| 6286 | ||
| 3930 | does not accept a PID argument, so only C<PID==0> is truly portable. | |
| 6287 | C<PID==0> is truly portable. | |
| 6288 | 3931 | |
| 6289 | 3932 | =end original |
| 6290 | 3933 | |
| 6291 | 3934 | 指定された PID の現在のプロセスグループを返します。 |
| 6292 | 3935 | PID に C<0> を与えるとカレントプロセスの指定となります。 |
| 6293 | ||
| 3936 | getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。 | |
| 6294 | 3937 | PID を省略するとカレントプロセスのプロセスグループを返します。 |
| 6295 | POSIX 版の | |
| 3938 | POSIX 版の C<getpgrp> は PID 引数を受け付けないので、 | |
| 6296 | 3939 | C<PID==0> のみが完全に移植性があります。 |
| 6297 | 3940 | |
| 6298 | =begin original | |
| 6299 | ||
| 6300 | Portability issues: L<perlport/getpgrp>. | |
| 6301 | ||
| 6302 | =end original | |
| 6303 | ||
| 6304 | 移植性の問題: L<perlport/getpgrp>。 | |
| 6305 | ||
| 6306 | 3941 | =item getppid |
| 6307 | X<getppid> X<parent> X<pid> | |
| 6308 | 3942 | |
| 6309 | =for Pod::Functions get parent process ID | |
| 6310 | ||
| 6311 | 3943 | =begin original |
| 6312 | 3944 | |
| 6313 | 3945 | Returns the process id of the parent process. |
| 6314 | 3946 | |
| 6315 | 3947 | =end original |
| 6316 | 3948 | |
| 6317 | 3949 | 親プロセスのプロセス id を返します。 |
| 6318 | 3950 | |
| 6319 | =begin original | |
| 6320 | ||
| 6321 | Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work | |
| 6322 | around non-POSIX thread semantics the minority of Linux systems (and | |
| 6323 | Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation | |
| 6324 | has since been removed. See the documentation for L<$$|perlvar/$$> for | |
| 6325 | details. | |
| 6326 | ||
| 6327 | =end original | |
| 6328 | ||
| 6329 | Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は | |
| 6330 | LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな | |
| 6331 | Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。 | |
| 6332 | このエミュレーションは削除されました; | |
| 6333 | 詳しくは L<$$|perlvar/$$> の文書を参照してください。 | |
| 6334 | ||
| 6335 | =begin original | |
| 6336 | ||
| 6337 | Portability issues: L<perlport/getppid>. | |
| 6338 | ||
| 6339 | =end original | |
| 6340 | ||
| 6341 | 移植性の問題: L<perlport/getppid>。 | |
| 6342 | ||
| 6343 | 3951 | =item getpriority WHICH,WHO |
| 6344 | X<getpriority> X<priority> X<nice> | |
| 6345 | 3952 | |
| 6346 | =for Pod::Functions get current nice value | |
| 6347 | ||
| 6348 | 3953 | =begin original |
| 6349 | 3954 | |
| 6350 | 3955 | Returns the current priority for a process, a process group, or a user. |
| 6351 | 3956 | (See L<getpriority(2)>.) Will raise a fatal exception if used on a |
| 6352 | machine that doesn't implement | |
| 3957 | machine that doesn't implement getpriority(2). | |
| 6353 | 3958 | |
| 6354 | 3959 | =end original |
| 6355 | 3960 | |
| 6356 | 3961 | プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。 |
| 6357 | 3962 | (L<getpriority(2)> を参照してください。) |
| 6358 | ||
| 3963 | getpriority(2) を実装していない | |
| 6359 | マシンで実行した場合には、 | |
| 3964 | マシンで実行した場合には、例外が発生します。 | |
| 6360 | 3965 | |
| 6361 | =begin original | |
| 6362 | ||
| 6363 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
| 6364 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
| 6365 | ||
| 6366 | =end original | |
| 6367 | ||
| 6368 | C<WHICH> は L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
| 6369 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
| 6370 | ||
| 6371 | =begin original | |
| 6372 | ||
| 6373 | Portability issues: L<perlport/getpriority>. | |
| 6374 | ||
| 6375 | =end original | |
| 6376 | ||
| 6377 | 移植性の問題: L<perlport/getpriority>。 | |
| 6378 | ||
| 6379 | 3966 | =item getpwnam NAME |
| 6380 | X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname> | |
| 6381 | X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr> | |
| 6382 | X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent> | |
| 6383 | X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent> | |
| 6384 | X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent> | |
| 6385 | X<endnetent> X<endprotoent> X<endservent> | |
| 6386 | 3967 | |
| 6387 | =for Pod::Functions get passwd record given user login name | |
| 6388 | ||
| 6389 | 3968 | =item getgrnam NAME |
| 6390 | 3969 | |
| 6391 | =for Pod::Functions get group record given group name | |
| 6392 | ||
| 6393 | 3970 | =item gethostbyname NAME |
| 6394 | 3971 | |
| 6395 | =for Pod::Functions get host record given name | |
| 6396 | ||
| 6397 | 3972 | =item getnetbyname NAME |
| 6398 | 3973 | |
| 6399 | =for Pod::Functions get networks record given name | |
| 6400 | ||
| 6401 | 3974 | =item getprotobyname NAME |
| 6402 | 3975 | |
| 6403 | =for Pod::Functions get protocol record given name | |
| 6404 | ||
| 6405 | 3976 | =item getpwuid UID |
| 6406 | 3977 | |
| 6407 | =for Pod::Functions get passwd record given user ID | |
| 6408 | ||
| 6409 | 3978 | =item getgrgid GID |
| 6410 | 3979 | |
| 6411 | =for Pod::Functions get group record given group user ID | |
| 6412 | ||
| 6413 | 3980 | =item getservbyname NAME,PROTO |
| 6414 | 3981 | |
| 6415 | =for Pod::Functions get services record given its name | |
| 6416 | ||
| 6417 | 3982 | =item gethostbyaddr ADDR,ADDRTYPE |
| 6418 | 3983 | |
| 6419 | =for Pod::Functions get host record given its address | |
| 6420 | ||
| 6421 | 3984 | =item getnetbyaddr ADDR,ADDRTYPE |
| 6422 | 3985 | |
| 6423 | =for Pod::Functions get network record given its address | |
| 6424 | ||
| 6425 | 3986 | =item getprotobynumber NUMBER |
| 6426 | 3987 | |
| 6427 | =for Pod::Functions get protocol record numeric protocol | |
| 6428 | ||
| 6429 | 3988 | =item getservbyport PORT,PROTO |
| 6430 | 3989 | |
| 6431 | =for Pod::Functions get services record given numeric port | |
| 6432 | ||
| 6433 | 3990 | =item getpwent |
| 6434 | 3991 | |
| 6435 | =for Pod::Functions get next passwd record | |
| 6436 | ||
| 6437 | 3992 | =item getgrent |
| 6438 | 3993 | |
| 6439 | =for Pod::Functions get next group record | |
| 6440 | ||
| 6441 | 3994 | =item gethostent |
| 6442 | 3995 | |
| 6443 | =for Pod::Functions get next hosts record | |
| 6444 | ||
| 6445 | 3996 | =item getnetent |
| 6446 | 3997 | |
| 6447 | =for Pod::Functions get next networks record | |
| 6448 | ||
| 6449 | 3998 | =item getprotoent |
| 6450 | 3999 | |
| 6451 | =for Pod::Functions get next protocols record | |
| 6452 | ||
| 6453 | 4000 | =item getservent |
| 6454 | 4001 | |
| 6455 | =for Pod::Functions get next services record | |
| 6456 | ||
| 6457 | 4002 | =item setpwent |
| 6458 | 4003 | |
| 6459 | =for Pod::Functions prepare passwd file for use | |
| 6460 | ||
| 6461 | 4004 | =item setgrent |
| 6462 | 4005 | |
| 6463 | =for Pod::Functions prepare group file for use | |
| 6464 | ||
| 6465 | 4006 | =item sethostent STAYOPEN |
| 6466 | 4007 | |
| 6467 | =for Pod::Functions prepare hosts file for use | |
| 6468 | ||
| 6469 | 4008 | =item setnetent STAYOPEN |
| 6470 | 4009 | |
| 6471 | =for Pod::Functions prepare networks file for use | |
| 6472 | ||
| 6473 | 4010 | =item setprotoent STAYOPEN |
| 6474 | 4011 | |
| 6475 | =for Pod::Functions prepare protocols file for use | |
| 6476 | ||
| 6477 | 4012 | =item setservent STAYOPEN |
| 6478 | 4013 | |
| 6479 | =for Pod::Functions prepare services file for use | |
| 6480 | ||
| 6481 | 4014 | =item endpwent |
| 6482 | 4015 | |
| 6483 | =for Pod::Functions be done using passwd file | |
| 6484 | ||
| 6485 | 4016 | =item endgrent |
| 6486 | 4017 | |
| 6487 | =for Pod::Functions be done using group file | |
| 6488 | ||
| 6489 | 4018 | =item endhostent |
| 6490 | 4019 | |
| 6491 | =for Pod::Functions be done using hosts file | |
| 6492 | ||
| 6493 | 4020 | =item endnetent |
| 6494 | 4021 | |
| 6495 | =for Pod::Functions be done using networks file | |
| 6496 | ||
| 6497 | 4022 | =item endprotoent |
| 6498 | 4023 | |
| 6499 | =for Pod::Functions be done using protocols file | |
| 6500 | ||
| 6501 | 4024 | =item endservent |
| 6502 | 4025 | |
| 6503 | =for Pod::Functions be done using services file | |
| 6504 | ||
| 6505 | 4026 | =begin original |
| 6506 | 4027 | |
| 6507 | These routines | |
| 4028 | These routines perform the same functions as their counterparts in the | |
| 6508 | system | |
| 4029 | system library. In list context, the return values from the | |
| 6509 | 4030 | various get routines are as follows: |
| 6510 | 4031 | |
| 6511 | 4032 | =end original |
| 6512 | 4033 | |
| 6513 | これらのルーチンは、システム | |
| 4034 | これらのルーチンは、システムライブラリの同名の関数を実行します。 | |
| 6514 | 4035 | リストコンテキストでは、さまざまな |
| 6515 | 4036 | get ルーチンからの返り値は、次のようになります: |
| 6516 | 4037 | |
| 6517 | | |
| 4038 | ($name,$passwd,$uid,$gid, | |
| 6518 | | |
| 4039 | $quota,$comment,$gcos,$dir,$shell,$expire) = getpw* | |
| 6519 | | |
| 4040 | ($name,$passwd,$gid,$members) = getgr* | |
| 6520 | | |
| 4041 | ($name,$aliases,$addrtype,$length,@addrs) = gethost* | |
| 6521 | | |
| 4042 | ($name,$aliases,$addrtype,$net) = getnet* | |
| 6522 | | |
| 4043 | ($name,$aliases,$proto) = getproto* | |
| 6523 | | |
| 4044 | ($name,$aliases,$port,$proto) = getserv* | |
| 6524 | $comment, $gcos, $dir, $shell, $expire ) = getpw* | |
| 6525 | # 5 6 7 8 9 | |
| 6526 | 4045 | |
| 6527 | 4046 | =begin original |
| 6528 | 4047 | |
| 6529 | (If the entry doesn't exist | |
| 4048 | (If the entry doesn't exist you get a null list.) | |
| 6530 | value.) | |
| 6531 | 4049 | |
| 6532 | 4050 | =end original |
| 6533 | 4051 | |
| 6534 | (エントリが存在しなければ、返 | |
| 4052 | (エントリが存在しなければ、空リストが返されます。) | |
| 6535 | 4053 | |
| 6536 | 4054 | =begin original |
| 6537 | 4055 | |
| 6538 | 4056 | The exact meaning of the $gcos field varies but it usually contains |
| 6539 | 4057 | the real name of the user (as opposed to the login name) and other |
| 6540 | 4058 | information pertaining to the user. Beware, however, that in many |
| 6541 | 4059 | system users are able to change this information and therefore it |
| 6542 | 4060 | cannot be trusted and therefore the $gcos is tainted (see |
| 6543 | 4061 | L<perlsec>). The $passwd and $shell, user's encrypted password and |
| 6544 | login shell, are also tainted, | |
| 4062 | login shell, are also tainted, because of the same reason. | |
| 6545 | 4063 | |
| 6546 | 4064 | =end original |
| 6547 | 4065 | |
| 6548 | 4066 | $gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく) |
| 6549 | 4067 | ユーザーの実際の名前とユーザーに付随する情報を含みます。 |
| 6550 | 4068 | 但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は |
| 6551 | 4069 | 信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。 |
| 6552 | 4070 | ユーザーの暗号化されたパスワードとログインシェルである $passwd と |
| 6553 | 4071 | $shell も、同様の理由で汚染されます。 |
| 6554 | 4072 | |
| 6555 | 4073 | =begin original |
| 6556 | 4074 | |
| 6557 | 4075 | In scalar context, you get the name, unless the function was a |
| 6558 | 4076 | lookup by name, in which case you get the other thing, whatever it is. |
| 6559 | 4077 | (If the entry doesn't exist you get the undefined value.) For example: |
| 6560 | 4078 | |
| 6561 | 4079 | =end original |
| 6562 | 4080 | |
| 6563 | 4081 | スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、 |
| 6564 | 4082 | name を返し、NAME で検索するものは、何か別のものを返します。 |
| 6565 | 4083 | (エントリが存在しなければ、未定義値が返ります。) |
| 6566 | 例 | |
| 4084 | 例: | |
| 6567 | 4085 | |
| 6568 | | |
| 4086 | $uid = getpwnam($name); | |
| 6569 | | |
| 4087 | $name = getpwuid($num); | |
| 6570 | | |
| 4088 | $name = getpwent(); | |
| 6571 | | |
| 4089 | $gid = getgrnam($name); | |
| 6572 | | |
| 4090 | $name = getgrgid($num; | |
| 6573 | | |
| 4091 | $name = getgrent(); | |
| 6574 | <#del> etc. | |
| 4092 | #etc. | |
| 6575 | 4093 | |
| 6576 | 4094 | =begin original |
| 6577 | 4095 | |
| 6578 | 4096 | In I<getpw*()> the fields $quota, $comment, and $expire are special |
| 6579 | in that they are unsupported | |
| 4097 | cases in the sense that in many systems they are unsupported. If the | |
| 6580 | 4098 | $quota is unsupported, it is an empty scalar. If it is supported, it |
| 6581 | 4099 | usually encodes the disk quota. If the $comment field is unsupported, |
| 6582 | 4100 | it is an empty scalar. If it is supported it usually encodes some |
| 6583 | 4101 | administrative comment about the user. In some systems the $quota |
| 6584 | 4102 | field may be $change or $age, fields that have to do with password |
| 6585 | 4103 | aging. In some systems the $comment field may be $class. The $expire |
| 6586 | 4104 | field, if present, encodes the expiration period of the account or the |
| 6587 | 4105 | password. For the availability and the exact meaning of these fields |
| 6588 | in your system, please consult | |
| 4106 | in your system, please consult your getpwnam(3) documentation and your | |
| 6589 | 4107 | F<pwd.h> file. You can also find out from within Perl what your |
| 6590 | 4108 | $quota and $comment fields mean and whether you have the $expire field |
| 6591 | by using the | |
| 4109 | by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>, | |
| 6592 | 4110 | C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password |
| 6593 | files are supported | |
| 4111 | files are only supported if your vendor has implemented them in the | |
| 6594 | 4112 | intuitive fashion that calling the regular C library routines gets the |
| 6595 | 4113 | shadow versions if you're running under privilege or if there exists |
| 6596 | the | |
| 4114 | the shadow(3) functions as found in System V ( this includes Solaris | |
| 6597 | and Linux | |
| 4115 | and Linux.) Those systems which implement a proprietary shadow password | |
| 6598 | 4116 | facility are unlikely to be supported. |
| 6599 | 4117 | |
| 6600 | 4118 | =end original |
| 6601 | 4119 | |
| 6602 | 4120 | I<getpw*()> では、$quota, $comment, $expire フィールドは、 |
| 6603 | 4121 | 多くのシステムでは対応していないので特別な処理がされます。 |
| 6604 | 4122 | $quota が非対応の場合、空のスカラになります。 |
| 6605 | 4123 | 対応している場合、通常はディスククォータの値が入ります。 |
| 6606 | 4124 | $comment フィールドが非対応の場合、空のスカラになります。 |
| 6607 | 4125 | 対応している場合、通常はユーザーに関する管理上のコメントが入ります。 |
| 6608 | 4126 | $quota フィールドはパスワードの寿命を示す $change や $age である |
| 6609 | 4127 | システムもあります。 |
| 6610 | 4128 | $comment フィールドは $class であるシステムもあります。 |
| 6611 | 4129 | $expire フィールドがある場合は、アカウントやパスワードが時間切れになる |
| 6612 | 4130 | 期間が入ります。 |
| 6613 | 4131 | 動作させるシステムでのこれらのフィールドの有効性と正確な意味については、 |
| 6614 | ||
| 4132 | getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。 | |
| 6615 | 4133 | $quota と $comment フィールドが何を意味しているかと、$expire フィールドが |
| 6616 | あるかどうかは、 | |
| 4134 | あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>, | |
| 6617 | C<d_pw | |
| 4135 | C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって | |
| 6618 | ||
| 4136 | Perl 自身で調べることも出来ます。 | |
| 6619 | 4137 | シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で |
| 6620 | 4138 | 呼び出すことでシャドウ版が取得できるか、System V にあるような |
| 6621 | (Solaris と Linux を含みます) | |
| 4139 | (Solaris と Linux を含みます) shadow(3) 関数があるといった、 | |
| 6622 | 4140 | 直感的な方法で実装されている場合にのみ対応されます。 |
| 6623 | 4141 | 独占的なシャドウパスワード機能を実装しているシステムでは、 |
| 6624 | 4142 | それに対応されることはないでしょう。 |
| 6625 | 4143 | |
| 6626 | 4144 | =begin original |
| 6627 | 4145 | |
| 6628 | The $members value returned by I<getgr*()> is a space | |
| 4146 | The $members value returned by I<getgr*()> is a space separated list of | |
| 6629 | 4147 | the login names of the members of the group. |
| 6630 | 4148 | |
| 6631 | 4149 | =end original |
| 6632 | 4150 | |
| 6633 | 4151 | I<getgr*()> によって返る値 $members は、グループのメンバの |
| 6634 | 4152 | ログイン名をスペースで区切ったものです。 |
| 6635 | 4153 | |
| 6636 | 4154 | =begin original |
| 6637 | 4155 | |
| 6638 | 4156 | For the I<gethost*()> functions, if the C<h_errno> variable is supported in |
| 6639 | C, it will be returned to you via | |
| 4157 | C, it will be returned to you via C<$?> if the function call fails. The | |
| 6640 | ||
| 4158 | C<@addrs> value returned by a successful call is a list of the raw | |
| 6641 | ||
| 4159 | addresses returned by the corresponding system library call. In the | |
| 6642 | address | |
| 4160 | Internet domain, each address is four bytes long and you can unpack it | |
| 6643 | Internet domain, each address is four bytes long; you can unpack it | |
| 6644 | 4161 | by saying something like: |
| 6645 | 4162 | |
| 4163 | ($a,$b,$c,$d) = unpack('C4',$addr[0]); | |
| 4164 | ||
| 6646 | 4165 | =end original |
| 6647 | 4166 | |
| 6648 | 4167 | I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、 |
| 6649 | 関数呼出が失敗したときに、 | |
| 4168 | 関数呼出が失敗したときに、C<$?> を通して、その値が返されます。 | |
| 6650 | 4169 | 成功時に返される C<@addrs> 値は、対応するシステムコールが返す、 |
| 6651 | 4170 | 生のアドレスのリストです。 |
| 6652 | インターネットドメインでは、個々のアドレスは、4 バイト長で | |
| 4171 | インターネットドメインでは、個々のアドレスは、4 バイト長で、 | |
| 6653 | 以下のようにして unpack することができます | |
| 4172 | 以下のようにして unpack することができます。 | |
| 6654 | 4173 | |
| 6655 | | |
| 4174 | ($a,$b,$c,$d) = unpack('C4',$addr[0]); | |
| 6656 | 4175 | |
| 6657 | 4176 | =begin original |
| 6658 | 4177 | |
| 6659 | 4178 | The Socket library makes this slightly easier: |
| 6660 | 4179 | |
| 6661 | 4180 | =end original |
| 6662 | 4181 | |
| 6663 | 4182 | Socket ライブラリを使うともう少し簡単になります。 |
| 6664 | 4183 | |
| 6665 | 4184 | use Socket; |
| 6666 | | |
| 4185 | $iaddr = inet_aton("127.1"); # or whatever address | |
| 6667 | | |
| 4186 | $name = gethostbyaddr($iaddr, AF_INET); | |
| 6668 | 4187 | |
| 6669 | 4188 | # or going the other way |
| 6670 | | |
| 4189 | $straddr = inet_ntoa($iaddr); | |
| 6671 | 4190 | |
| 6672 | 4191 | =begin original |
| 6673 | 4192 | |
| 6674 | In the opposite way, to resolve a hostname to the IP address | |
| 6675 | you can write this: | |
| 6676 | ||
| 6677 | =end original | |
| 6678 | ||
| 6679 | 逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます: | |
| 6680 | ||
| 6681 | use Socket; | |
| 6682 | my $packed_ip = gethostbyname("www.perl.org"); | |
| 6683 | my $ip_address; | |
| 6684 | if (defined $packed_ip) { | |
| 6685 | $ip_address = inet_ntoa($packed_ip); | |
| 6686 | } | |
| 6687 | ||
| 6688 | =begin original | |
| 6689 | ||
| 6690 | Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR | |
| 6691 | context and that its return value is checked for definedness. | |
| 6692 | ||
| 6693 | =end original | |
| 6694 | ||
| 6695 | L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで | |
| 6696 | 呼び出すようにして、返り値が定義されているかを必ずチェックしてください。 | |
| 6697 | ||
| 6698 | =begin original | |
| 6699 | ||
| 6700 | The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even | |
| 6701 | though it only takes one argument, has the precedence of a list | |
| 6702 | operator, so beware: | |
| 6703 | ||
| 6704 | =end original | |
| 6705 | ||
| 6706 | L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか | |
| 6707 | 取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って | |
| 6708 | 注意してください: | |
| 6709 | ||
| 6710 | getprotobynumber $number eq 'icmp' # WRONG | |
| 6711 | getprotobynumber($number eq 'icmp') # actually means this | |
| 6712 | getprotobynumber($number) eq 'icmp' # better this way | |
| 6713 | ||
| 6714 | =begin original | |
| 6715 | ||
| 6716 | 4193 | If you get tired of remembering which element of the return list |
| 6717 | contains which return value, by-name interfaces are provided | |
| 4194 | contains which return value, by-name interfaces are provided | |
| 6718 | modules: | |
| 4195 | in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>, | |
| 6719 | ||
| 4196 | C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>, | |
| 6720 | ||
| 4197 | and C<User::grent>. These override the normal built-ins, supplying | |
| 6721 | ||
| 4198 | versions that return objects with the appropriate names | |
| 6722 | ||
| 4199 | for each field. For example: | |
| 6723 | supplying versions that return objects with the appropriate names for | |
| 6724 | each field. For example: | |
| 6725 | 4200 | |
| 6726 | 4201 | =end original |
| 6727 | 4202 | |
| 6728 | 4203 | 返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、 |
| 6729 | 4204 | 名前ベースのインターフェースが標準モジュールで提供されています: |
| 6730 | ||
| 4205 | C<File::stat>, C<Net::hostent>, C<Net::netent>, | |
| 6731 | ||
| 4206 | C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>, | |
| 6732 | ||
| 4207 | C<User::grent> です。 | |
| 6733 | L<C<Time::localtime>|Time::localtime>, | |
| 6734 | L<C<User::grent>|User::grent> です。 | |
| 6735 | 4208 | これらは通常の組み込みを上書きし、 |
| 6736 | 4209 | それぞれのフィールドに適切な名前をつけたオブジェクトを返します。 |
| 6737 | 例 | |
| 4210 | 例: | |
| 6738 | 4211 | |
| 6739 | 4212 | use File::stat; |
| 6740 | 4213 | use User::pwent; |
| 6741 | | |
| 4214 | $is_his = (stat($filename)->uid == pwent($whoever)->uid); | |
| 6742 | 4215 | |
| 6743 | 4216 | =begin original |
| 6744 | 4217 | |
| 6745 | Even though it looks | |
| 4218 | Even though it looks like they're the same method calls (uid), | |
| 6746 | they aren't, because a C<File::stat> object is different from | |
| 4219 | they aren't, because a C<File::stat> object is different from | |
| 6747 | 4220 | a C<User::pwent> object. |
| 6748 | 4221 | |
| 6749 | 4222 | =end original |
| 6750 | 4223 | |
| 6751 | 同じメソッド(uid)を呼び出しているように見えますが、違います | |
| 4224 | 同じメソッド(uid)を呼び出しているように見えますが、違います。 | |
| 6752 | 4225 | なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは |
| 6753 | 4226 | 異なるからです。 |
| 6754 | 4227 | |
| 6755 | =begin original | |
| 6756 | ||
| 6757 | Many of these functions are not safe in a multi-threaded environment | |
| 6758 | where more than one thread can be using them. In particular, functions | |
| 6759 | like C<getpwent()> iterate per-process and not per-thread, so if two | |
| 6760 | threads are simultaneously iterating, neither will get all the records. | |
| 6761 | ||
| 6762 | =end original | |
| 6763 | ||
| 6764 | これらの関数の多くは、複数のスレッドがこれらを使うような | |
| 6765 | マルチスレッド環境では安全ではありません。 | |
| 6766 | 特に、 | |
| 6767 | C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で | |
| 6768 | 反復するので、二つのスレッドが同時に反復すると、 | |
| 6769 | どちらも全てのレコードを得られません。 | |
| 6770 | ||
| 6771 | =begin original | |
| 6772 | ||
| 6773 | Some systems have thread-safe versions of some of the functions, such as | |
| 6774 | C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and | |
| 6775 | invisibly substitutes the thread-safe version, without notice. This | |
| 6776 | means that code that safely runs on some systems can fail on others that | |
| 6777 | lack the thread-safe versions. | |
| 6778 | ||
| 6779 | =end original | |
| 6780 | ||
| 6781 | 一部のシステムは、 | |
| 6782 | C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について | |
| 6783 | スレッドセーフ版を持っています。 | |
| 6784 | その場合、Perl は自動的かつ目に見えないように、通知なしで | |
| 6785 | スレッドセーフ版に置き換えます。 | |
| 6786 | つまり、一部のシステムで安全に実行できるコードが | |
| 6787 | スレッドセーフ版のないその他のシステムでは失敗することがあるということです。 | |
| 6788 | ||
| 6789 | =begin original | |
| 6790 | ||
| 6791 | Portability issues: L<perlport/getpwnam> to L<perlport/endservent>. | |
| 6792 | ||
| 6793 | =end original | |
| 6794 | ||
| 6795 | 移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。 | |
| 6796 | ||
| 6797 | 4228 | =item getsockname SOCKET |
| 6798 | X<getsockname> | |
| 6799 | 4229 | |
| 6800 | =for Pod::Functions retrieve the sockaddr for a given socket | |
| 6801 | ||
| 6802 | 4230 | =begin original |
| 6803 | 4231 | |
| 6804 | 4232 | Returns the packed sockaddr address of this end of the SOCKET connection, |
| 6805 | 4233 | in case you don't know the address because you have several different |
| 6806 | 4234 | IPs that the connection might have come in on. |
| 6807 | 4235 | |
| 6808 | 4236 | =end original |
| 6809 | 4237 | |
| 6810 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します | |
| 4238 | SOCKET 接続のこちら側の pack された sockaddr アドレスを返します。 | |
| 6811 | 4239 | 複数の異なる IP から接続されるためにアドレスがわからない場合に使います。 |
| 6812 | 4240 | |
| 6813 | 4241 | use Socket; |
| 6814 | | |
| 4242 | $mysockaddr = getsockname(SOCK); | |
| 6815 | | |
| 4243 | ($port, $myaddr) = sockaddr_in($mysockaddr); | |
| 6816 | printf "Connect to %s [%s]\n", | |
| 4244 | printf "Connect to %s [%s]\n", | |
| 6817 | 4245 | scalar gethostbyaddr($myaddr, AF_INET), |
| 6818 | 4246 | inet_ntoa($myaddr); |
| 6819 | 4247 | |
| 6820 | 4248 | =item getsockopt SOCKET,LEVEL,OPTNAME |
| 6821 | X<getsockopt> | |
| 6822 | 4249 | |
| 6823 | =for Pod::Functions get socket options on a given socket | |
| 6824 | ||
| 6825 | 4250 | =begin original |
| 6826 | 4251 | |
| 6827 | ||
| 4252 | Returns the socket option requested, or undef if there is an error. | |
| 6828 | Options may exist at multiple protocol levels depending on the socket | |
| 6829 | type, but at least the uppermost socket level SOL_SOCKET (defined in the | |
| 6830 | L<C<Socket>|Socket> module) will exist. To query options at another | |
| 6831 | level the protocol number of the appropriate protocol controlling the | |
| 6832 | option should be supplied. For example, to indicate that an option is | |
| 6833 | to be interpreted by the TCP protocol, LEVEL should be set to the | |
| 6834 | protocol number of TCP, which you can get using | |
| 6835 | L<C<getprotobyname>|/getprotobyname NAME>. | |
| 6836 | 4253 | |
| 6837 | 4254 | =end original |
| 6838 | 4255 | |
| 6839 | ||
| 4256 | 要求されたソケットオプションを返し、 | |
| 6840 | ||
| 4257 | エラーの場合には undef を返します。 | |
| 6841 | オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも | |
| 6842 | ありますが、少なくとも最上位ソケットレベル SOL_SOCKET | |
| 6843 | (L<C<Socket>|Socket> モジュールで定義されています)は存在します。 | |
| 6844 | その他のレベルのオプションを問い合わせるには、そのオプションを制御する | |
| 6845 | 適切なプロトコルのプロトコル番号を指定します。 | |
| 6846 | 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 | |
| 6847 | LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の | |
| 6848 | プロトコル番号を設定します。 | |
| 6849 | 4258 | |
| 4259 | =item glob EXPR | |
| 4260 | ||
| 4261 | =item glob | |
| 4262 | ||
| 6850 | 4263 | =begin original |
| 6851 | 4264 | |
| 6852 | ||
| 4265 | Returns the value of EXPR with filename expansions such as the | |
| 6853 | ||
| 4266 | standard Unix shell F</bin/csh> would do. This is the internal function | |
| 6854 | ||
| 4267 | implementing the C<< <*.c> >> operator, but you can use it directly. | |
| 6855 | ||
| 4268 | If EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is | |
| 6856 | c | |
| 4269 | discussed in more detail in L<perlop/"I/O Operators">. | |
| 6857 | is a packed integer, which you can decode using | |
| 6858 | L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format. | |
| 6859 | 4270 | |
| 6860 | 4271 | =end original |
| 6861 | 4272 | |
| 6862 | ||
| 4273 | EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように、 | |
| 6863 | ||
| 4274 | ファイル名の展開を行なって返します。 | |
| 6864 | ||
| 4275 | これは、C<< <*.c> >> 演算子を実装する内部関数ですが、 | |
| 6865 | ||
| 4276 | 直接使用することもできます。 | |
| 6866 | ||
| 4277 | EXPR を省略すると、C<$_>が使われます。 | |
| 6867 | ||
| 4278 | C<< <*.c> >>演算子については | |
| 6868 | L< | |
| 4279 | L<perlop/"I/O Operators"> でより詳細に議論しています。 | |
| 6869 | (あるいは C<I>)フォーマットでデコードできる pack された整数です。 | |
| 6870 | 4280 | |
| 6871 | 4281 | =begin original |
| 6872 | 4282 | |
| 6873 | ||
| 4283 | Beginning with v5.6.0, this operator is implemented using the standard | |
| 4284 | C<File::Glob> extension. See L<File::Glob> for details. | |
| 6874 | 4285 | |
| 6875 | 4286 | =end original |
| 6876 | 4287 | |
| 6877 | ||
| 4288 | v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って | |
| 4289 | 実装されています。 | |
| 4290 | 詳細は L<File::Glob> を参照して下さい。 | |
| 6878 | 4291 | |
| 6879 | ||
| 4292 | =item gmtime EXPR | |
| 6880 | 4293 | |
| 6881 | defined(my $tcp = getprotobyname("tcp")) | |
| 6882 | or die "Could not determine the protocol number for tcp"; | |
| 6883 | # my $tcp = IPPROTO_TCP; # Alternative | |
| 6884 | my $packed = getsockopt($socket, $tcp, TCP_NODELAY) | |
| 6885 | or die "getsockopt TCP_NODELAY: $!"; | |
| 6886 | my $nodelay = unpack("I", $packed); | |
| 6887 | print "Nagle's algorithm is turned ", | |
| 6888 | $nodelay ? "off\n" : "on\n"; | |
| 6889 | ||
| 6890 | 4294 | =begin original |
| 6891 | 4295 | |
| 6892 | ||
| 4296 | Converts a time as returned by the time function to a 8-element list | |
| 4297 | with the time localized for the standard Greenwich time zone. | |
| 4298 | Typically used as follows: | |
| 6893 | 4299 | |
| 6894 | 4300 | =end original |
| 6895 | 4301 | |
| 6896 | ||
| 4302 | time 関数が返す時刻を、グリニッジタイムゾーンで測った時刻として、 | |
| 4303 | 8 要素のリストに変換します。 | |
| 4304 | 通常は、以下のようにして使用します: | |
| 6897 | 4305 | |
| 6898 | ||
| 4306 | # 0 1 2 3 4 5 6 7 | |
| 6899 | ||
| 4307 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = | |
| 4308 | gmtime(time); | |
| 6900 | 4309 | |
| 6901 | =item glob | |
| 6902 | ||
| 6903 | =for Pod::Functions expand filenames using wildcards | |
| 6904 | ||
| 6905 | 4310 | =begin original |
| 6906 | 4311 | |
| 6907 | ||
| 4312 | All list elements are numeric, and come straight out of the C `struct | |
| 6908 | t | |
| 4313 | tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the | |
| 6909 | sc | |
| 4314 | specified time. $mday is the day of the month, and $mon is the month | |
| 6910 | ||
| 4315 | itself, in the range C<0..11> with 0 indicating January and 11 | |
| 6911 | i | |
| 4316 | indicating December. $year is the number of years since 1900. That | |
| 6912 | ||
| 4317 | is, $year is C<123> in year 2023. $wday is the day of the week, with | |
| 6913 | ||
| 4318 | 0 indicating Sunday and 3 indicating Wednesday. $yday is the day of | |
| 4319 | the year, in the range C<0..364> (or C<0..365> in leap years.) | |
| 6914 | 4320 | |
| 6915 | 4321 | =end original |
| 6916 | 4322 | |
| 6917 | リスト | |
| 4323 | すべてのリスト要素は数値で、C の `struct tm' 構造体から | |
| 6918 | ||
| 4324 | 直接持ってきます。 | |
| 6919 | ||
| 4325 | $sec, $min, $hour は指定された時刻の秒、分、時です。 | |
| 6920 | ||
| 4326 | $mday は月の何日目か、$mon は月の値です。 | |
| 6921 | ||
| 4327 | 月の値は C<0..11> で、0 が 1 月、11 が 12 月です。 | |
| 6922 | ||
| 4328 | $year は 1900 年からの年数です。 | |
| 6923 | ||
| 4329 | つまり、$year が C<123> なら 2023 年です。 | |
| 6924 | ||
| 4330 | $wday は曜日で、0 が日曜日、3 が水曜日です。 | |
| 6925 | C< | |
| 4331 | $yday はその年の何日目かで、C<0..364> の値を取ります | |
| 6926 | ||
| 4332 | (うるう年は C<0..365> です)。 | |
| 6927 | 4333 | |
| 6928 | 4334 | =begin original |
| 6929 | 4335 | |
| 6930 | Note that | |
| 4336 | Note that the $year element is I<not> simply the last two digits of | |
| 6931 | t | |
| 4337 | the year. If you assume it is, then you create non-Y2K-compliant | |
| 6932 | ||
| 4338 | programs--and you wouldn't want to do that, would you? | |
| 6933 | matches all files with a F<.c> or F<.h> extension. The expression | |
| 6934 | C<glob(".* *")> matches all files in the current working directory. | |
| 6935 | If you want to glob filenames that might contain whitespace, you'll | |
| 6936 | have to use extra quotes around the spacey filename to protect it. | |
| 6937 | For example, to glob filenames that have an C<e> followed by a space | |
| 6938 | followed by an C<f>, use one of: | |
| 6939 | 4339 | |
| 6940 | 4340 | =end original |
| 6941 | 4341 | |
| 6942 | ||
| 4342 | $year 要素は単純に年の下 2 桁を返す I<のではない> ことに注意してください。 | |
| 6943 | ||
| 4343 | もしそう仮定してしまうと、Y2K 準拠でないプログラムを作ってしまいます-- | |
| 6944 | ||
| 4344 | そうはしたくないでしょう? | |
| 6945 | マッチングします。 | |
| 6946 | 式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに | |
| 6947 | マッチングします。 | |
| 6948 | 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために | |
| 6949 | 空白入りファイル名の周りに追加のクォートを使う必要があります。 | |
| 6950 | 例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには | |
| 6951 | 以下の一つを使います: | |
| 6952 | 4345 | |
| 6953 | my @spacies = <"*e f*">; | |
| 6954 | my @spacies = glob '"*e f*"'; | |
| 6955 | my @spacies = glob q("*e f*"); | |
| 6956 | ||
| 6957 | 4346 | =begin original |
| 6958 | 4347 | |
| 6959 | ||
| 4348 | The proper way to get a complete 4-digit year is simply: | |
| 6960 | 4349 | |
| 6961 | 4350 | =end original |
| 6962 | 4351 | |
| 6963 | ||
| 4352 | 完全な 4 桁の年を得る正しい方法は単純です: | |
| 6964 | 4353 | |
| 6965 | ||
| 4354 | $year += 1900; | |
| 6966 | my @spacies = glob qq("*${var}e f*"); | |
| 6967 | 4355 | |
| 6968 | 4356 | =begin original |
| 6969 | 4357 | |
| 6970 | ||
| 4358 | And to get the last two digits of the year (e.g., '01' in 2001) do: | |
| 6971 | L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many | |
| 6972 | strings are returned. For example, this produces nine strings, one for | |
| 6973 | each pairing of fruits and colors: | |
| 6974 | 4359 | |
| 6975 | 4360 | =end original |
| 6976 | 4361 | |
| 6977 | ||
| 4362 | そして年の下 2 桁(2001 年なら '01')を得るには次のようにします: | |
| 6978 | ワイルドカード文字列の場合、ファイル名とはマッチングせず、 | |
| 6979 | 可能性のある文字列が返されます。 | |
| 6980 | 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに | |
| 6981 | なります: | |
| 6982 | 4363 | |
| 6983 | ||
| 4364 | $year = sprintf("%02d", $year % 100); | |
| 6984 | 4365 | |
| 6985 | 4366 | =begin original |
| 6986 | 4367 | |
| 6987 | ||
| 4368 | If EXPR is omitted, C<gmtime()> uses the current time (C<gmtime(time)>). | |
| 6988 | See L<File::Glob> for details, including | |
| 6989 | L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace | |
| 6990 | as a pattern separator. | |
| 6991 | 4369 | |
| 6992 | 4370 | =end original |
| 6993 | 4371 | |
| 6994 | ||
| 4372 | EXPR が省略されると、C<gmtime()> は現在の時刻を使います (C<gmtime(time)>)。 | |
| 6995 | 実装されています。 | |
| 6996 | 空白をパターンのセパレータとして扱わない | |
| 6997 | L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた | |
| 6998 | 詳細は L<File::Glob> を参照してください。 | |
| 6999 | 4373 | |
| 7000 | 4374 | =begin original |
| 7001 | 4375 | |
| 7002 | I | |
| 4376 | In scalar context, C<gmtime()> returns the ctime(3) value: | |
| 7003 | loop, then it will be implicitly assigned to C<$_>. If either a C<glob> | |
| 7004 | expression or an explicit assignment of a C<glob> expression to a scalar | |
| 7005 | is used as a C<while>/C<for> condition, then the condition actually | |
| 7006 | tests for definedness of the expression's value, not for its regular | |
| 7007 | truth value. | |
| 7008 | 4377 | |
| 7009 | 4378 | =end original |
| 7010 | 4379 | |
| 7011 | C<g | |
| 4380 | スカラコンテキストでは、C<gmtime()> は ctime(3) の値を返します: | |
| 7012 | これは暗黙に C<$_> に代入されます。 | |
| 7013 | C<glob> 式または C<glob> 式からスカラへの明示的な代入が | |
| 7014 | C<while>/C<for> の条件部として使われた場合、 | |
| 7015 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 7016 | テストします。 | |
| 7017 | 4381 | |
| 7018 | ||
| 4382 | $now_string = gmtime; # e.g., "Thu Oct 13 04:54:34 1994" | |
| 7019 | 4383 | |
| 7020 | Portability issues: L<perlport/glob>. | |
| 7021 | ||
| 7022 | =end original | |
| 7023 | ||
| 7024 | 移植性の問題: L<perlport/glob>。 | |
| 7025 | ||
| 7026 | =item gmtime EXPR | |
| 7027 | X<gmtime> X<UTC> X<Greenwich> | |
| 7028 | ||
| 7029 | =item gmtime | |
| 7030 | ||
| 7031 | =for Pod::Functions convert UNIX time into record or string using Greenwich time | |
| 7032 | ||
| 7033 | 4384 | =begin original |
| 7034 | 4385 | |
| 7035 | ||
| 4386 | Also see the C<timegm> function provided by the C<Time::Local> module, | |
| 7036 | a | |
| 4387 | and the strftime(3) function available via the POSIX module. | |
| 7037 | 4388 | |
| 7038 | 4389 | =end original |
| 7039 | 4390 | |
| 7040 | ||
| 4391 | C<Time::Local> で提供されている C<timegm> 関数も参照して下さい。 | |
| 7041 | ||
| 4392 | また、POSIX モジュールで strftime(3) 関数が利用可能です。 | |
| 7042 | 4393 | |
| 7043 | 4394 | =begin original |
| 7044 | 4395 | |
| 7045 | ||
| 4396 | This scalar value is B<not> locale dependent (see L<perllocale>), but | |
| 7046 | ||
| 4397 | is instead a Perl builtin. Also see the C<Time::Local> module, and the | |
| 7047 | ||
| 4398 | strftime(3) and mktime(3) functions available via the POSIX module. To | |
| 4399 | get somewhat similar but locale dependent date strings, set up your | |
| 4400 | locale environment variables appropriately (please see L<perllocale>) | |
| 4401 | and try for example: | |
| 7048 | 4402 | |
| 7049 | 4403 | =end original |
| 7050 | 4404 | |
| 7051 | ||
| 4405 | このスカラ値はロケール依存 B<ではなく> (L<perllocale> を参照してください)、 | |
| 7052 | ||
| 4406 | Perl 組み込み機能です。 | |
| 7053 | ||
| 4407 | ロケール依存で似たような日付文字列を得るには、ロケール環境変数を | |
| 4408 | 適切に設定(L<perllocale> を参照してください)した上で、 | |
| 4409 | 以下の例を試してください: | |
| 7054 | 4410 | |
| 4411 | use POSIX qw(strftime); | |
| 4412 | $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; | |
| 4413 | ||
| 7055 | 4414 | =begin original |
| 7056 | 4415 | |
| 7057 | ||
| 4416 | Note that the C<%a> and C<%b> escapes, which represent the short forms | |
| 4417 | of the day of the week and the month of the year, may not necessarily | |
| 4418 | be three characters wide in all locales. | |
| 7058 | 4419 | |
| 7059 | 4420 | =end original |
| 7060 | 4421 | |
| 7061 | ||
| 4422 | C<%a> と C<%b>、つまり曜日と月の短い表現は全てのロケールで 3 文字であるとは | |
| 4423 | 限らないことに注意してください。 | |
| 7062 | 4424 | |
| 7063 | 4425 | =item goto LABEL |
| 7064 | X<goto> X<jump> X<jmp> | |
| 7065 | 4426 | |
| 7066 | 4427 | =item goto EXPR |
| 7067 | 4428 | |
| 7068 | 4429 | =item goto &NAME |
| 7069 | 4430 | |
| 7070 | =for Pod::Functions create spaghetti code | |
| 7071 | ||
| 7072 | 4431 | =begin original |
| 7073 | 4432 | |
| 7074 | The C<goto | |
| 4433 | The C<goto-LABEL> form finds the statement labeled with LABEL and resumes | |
| 7075 | ||
| 4434 | execution there. It may not be used to go into any construct that | |
| 7076 | subroutine | |
| 4435 | requires initialization, such as a subroutine or a C<foreach> loop. It | |
| 7077 | al | |
| 4436 | also can't be used to go into a construct that is optimized away, | |
| 7078 | ||
| 4437 | or to get out of a block or subroutine given to C<sort>. | |
| 7079 | ||
| 4438 | It can be used to go almost anywhere else within the dynamic scope, | |
| 7080 | n | |
| 4439 | including out of subroutines, but it's usually better to use some other | |
| 7081 | t | |
| 4440 | construct such as C<last> or C<die>. The author of Perl has never felt the | |
| 7082 | n | |
| 4441 | need to use this form of C<goto> (in Perl, that is--C is another matter). | |
| 7083 | most structured uses of L<C<goto>|/goto LABEL> in other languages.) | |
| 7084 | 4442 | |
| 7085 | 4443 | =end original |
| 7086 | 4444 | |
| 7087 | C<goto | |
| 4445 | C<goto-LABEL> の形式は、LABEL というラベルの付いた文を | |
| 7088 | 探して、そこへ実行を移すものです。 | |
| 4446 | 探して、そこへ実行を移すものです。 サブルーチンや | |
| 7089 | ||
| 4447 | C<foreach> ループなど、何らかの初期化が必要な構造の中に | |
| 7090 | ||
| 4448 | 入り込むことは許されません。 最適化によってなくなってしまう構造の中にも | |
| 4449 | goto することはできません。 | |
| 4450 | また、C<sort>で与えられたブロックやサブルーチンから外へ出ることもできません。 | |
| 7091 | 4451 | これ以外は、サブルーチンの外を含む、動的スコープ内の |
| 7092 | 4452 | ほとんどすべての場所へ行くために使用できますが、普通は、 |
| 7093 | ||
| 4453 | C<last> や C<die> といった別の構造を使った方が良いでしょう。 | |
| 7094 | ||
| 4454 | Perl の作者はこの形式の C<goto> を使う必要を感じたことは、 | |
| 7095 | Perl | |
| 4455 | 1 度もありません (Perl では。C は別のお話です)。 | |
| 7096 | 1 度もありません (Perl では; C は別のお話です)。 | |
| 7097 | (違いは、C にはループ制御と結びついた名前つきのループがないことです。 | |
| 7098 | Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の | |
| 7099 | 使用法を置き換えます。) | |
| 7100 | 4456 | |
| 7101 | 4457 | =begin original |
| 7102 | 4458 | |
| 7103 | The C<goto | |
| 4459 | The C<goto-EXPR> form expects a label name, whose scope will be resolved | |
| 7104 | ||
| 4460 | dynamically. This allows for computed C<goto>s per FORTRAN, but isn't | |
| 7105 | ||
| 4461 | necessarily recommended if you're optimizing for maintainability: | |
| 7106 | tail recursion via C<goto __SUB__>. | |
| 7107 | 4462 | |
| 7108 | 4463 | =end original |
| 7109 | 4464 | |
| 7110 | C<goto | |
| 4465 | C<goto-EXPR> の形式はラベル名を予測し、このスコープは動的に解決されます。 | |
| 7111 | ||
| 4466 | これにより FORTRAN のような算術 C<goto> が可能になりますが、 | |
| 7112 | コードリファレンスとして評価する場合、後述する C<goto &NAME> のように | |
| 7113 | 扱います。 | |
| 7114 | これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。 | |
| 7115 | ||
| 7116 | =begin original | |
| 7117 | ||
| 7118 | If the expression evaluates to a label name, its scope will be resolved | |
| 7119 | dynamically. This allows for computed L<C<goto>|/goto LABEL>s per | |
| 7120 | FORTRAN, but isn't necessarily recommended if you're optimizing for | |
| 7121 | maintainability: | |
| 7122 | ||
| 7123 | =end original | |
| 7124 | ||
| 7125 | 式がラベル名に評価される場合、このスコープは動的に解決されます。 | |
| 7126 | これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、 | |
| 7127 | 4467 | 保守性を重視するならお勧めしません。 |
| 7128 | 4468 | |
| 7129 | 4469 | goto ("FOO", "BAR", "GLARCH")[$i]; |
| 7130 | 4470 | |
| 7131 | 4471 | =begin original |
| 7132 | 4472 | |
| 7133 | ||
| 4473 | The C<goto-&NAME> form is quite different from the other forms of C<goto>. | |
| 7134 | ||
| 4474 | In fact, it isn't a goto in the normal sense at all, and doesn't have | |
| 7135 | ||
| 4475 | the stigma associated with other gotos. Instead, it | |
| 7136 | ||
| 4476 | substitutes a call to the named subroutine for the currently running | |
| 7137 | ||
| 4477 | subroutine. This is used by C<AUTOLOAD> subroutines that wish to load | |
| 4478 | another subroutine and then pretend that the other subroutine had been | |
| 4479 | called in the first place (except that any modifications to C<@_> | |
| 4480 | in the current subroutine are propagated to the other subroutine.) | |
| 4481 | After the C<goto>, not even C<caller> will be able to tell that this | |
| 4482 | routine was called first. | |
| 7138 | 4483 | |
| 7139 | 4484 | =end original |
| 7140 | 4485 | |
| 7141 | ||
| 4486 | C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり | |
| 7142 | 除外されます。 | |
| 7143 | これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。 | |
| 7144 | C<goto("NE")."XT"> は C<goto NEXT> と等価です。 | |
| 7145 | また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
| 7146 | ||
| 7147 | =begin original | |
| 7148 | ||
| 7149 | Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is | |
| 7150 | deprecated and will issue a warning. Even then, it may not be used to | |
| 7151 | go into any construct that requires initialization, such as a | |
| 7152 | subroutine, a C<foreach> loop, or a C<given> | |
| 7153 | block. In general, it may not be used to jump into the parameter | |
| 7154 | of a binary or list operator, but it may be used to jump into the | |
| 7155 | I<first> parameter of a binary operator. (The C<=> | |
| 7156 | assignment operator's "first" operand is its right-hand | |
| 7157 | operand.) It also can't be used to go into a | |
| 7158 | construct that is optimized away. | |
| 7159 | ||
| 7160 | =end original | |
| 7161 | ||
| 7162 | 構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは | |
| 7163 | 非推奨で、警告が発生します。 | |
| 7164 | それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、 | |
| 7165 | 初期化が必要な | |
| 7166 | 構造の中に入るために使うことは出来ません。 | |
| 7167 | 一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、 | |
| 7168 | 2 項演算子の I<最初の> 引数に飛び込むために使われていました。 | |
| 7169 | (C<=> 代入演算子の「最初の」オペランドはその右オペランドです。) | |
| 7170 | また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。 | |
| 7171 | ||
| 7172 | =begin original | |
| 7173 | ||
| 7174 | The C<goto &NAME> form is quite different from the other forms of | |
| 7175 | L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at | |
| 7176 | all, and doesn't have the stigma associated with other gotos. Instead, | |
| 7177 | it exits the current subroutine (losing any changes set by | |
| 7178 | L<C<local>|/local EXPR>) and immediately calls in its place the named | |
| 7179 | subroutine using the current value of L<C<@_>|perlvar/@_>. This is used | |
| 7180 | by C<AUTOLOAD> subroutines that wish to load another subroutine and then | |
| 7181 | pretend that the other subroutine had been called in the first place | |
| 7182 | (except that any modifications to L<C<@_>|perlvar/@_> in the current | |
| 7183 | subroutine are propagated to the other subroutine.) After the | |
| 7184 | L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able | |
| 7185 | to tell that this routine was called first. | |
| 7186 | ||
| 7187 | =end original | |
| 7188 | ||
| 7189 | C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり | |
| 7190 | 4487 | 異なったものです。 |
| 7191 | 4488 | 実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、 |
| 7192 | 4489 | 他の goto が持つ不名誉を持っていません。 |
| 7193 | ||
| 4490 | これは、実行中のサブルーチンを、NAME で指定されたサブルーチンの | |
| 7194 | ||
| 4491 | 呼び出しで置き換えます。 | |
| 7195 | 呼び出します。 | |
| 7196 | 4492 | これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、 |
| 7197 | 4493 | その別のサブルーチンが最初に呼ばれたようにするために使われます |
| 7198 | (ただし、現在のサブルーチンで | |
| 4494 | (ただし、現在のサブルーチンで C<@_> を修正した場合には、 | |
| 7199 | 4495 | その別のサブルーチンに伝えられます)。 |
| 7200 | ||
| 4496 | C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが | |
| 7201 | ||
| 4497 | 最初に呼び出されたと言うことができません。 | |
| 7202 | 4498 | |
| 7203 | 4499 | =begin original |
| 7204 | 4500 | |
| 7205 | 4501 | NAME needn't be the name of a subroutine; it can be a scalar variable |
| 7206 | containing a code reference or a block | |
| 4502 | containing a code reference, or a block which evaluates to a code | |
| 7207 | 4503 | reference. |
| 7208 | 4504 | |
| 7209 | 4505 | =end original |
| 7210 | 4506 | |
| 7211 | 4507 | NAME はサブルーチンの名前である必要はありません; コードリファレンスを |
| 7212 | 4508 | 含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。 |
| 7213 | 4509 | |
| 7214 | 4510 | =item grep BLOCK LIST |
| 7215 | X<grep> | |
| 7216 | 4511 | |
| 7217 | 4512 | =item grep EXPR,LIST |
| 7218 | 4513 | |
| 7219 | =for Pod::Functions locate elements in a list test true against a given criterion | |
| 7220 | ||
| 7221 | 4514 | =begin original |
| 7222 | 4515 | |
| 7223 | This is similar in spirit to, but not the same as, | |
| 4516 | This is similar in spirit to, but not the same as, grep(1) and its | |
| 7224 | 4517 | relatives. In particular, it is not limited to using regular expressions. |
| 7225 | 4518 | |
| 7226 | 4519 | =end original |
| 7227 | 4520 | |
| 7228 | これは | |
| 4521 | これは grep(1) とその親類と同じようなものですが、同じではありません。 | |
| 7229 | 4522 | 特に、正規表現の使用に制限されません。 |
| 7230 | 4523 | |
| 7231 | 4524 | =begin original |
| 7232 | 4525 | |
| 7233 | 4526 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
| 7234 | ||
| 4527 | C<$_> to each element) and returns the list value consisting of those | |
| 7235 | consisting of those | |
| 7236 | 4528 | elements for which the expression evaluated to true. In scalar |
| 7237 | 4529 | context, returns the number of times the expression was true. |
| 7238 | 4530 | |
| 7239 | 4531 | =end original |
| 7240 | 4532 | |
| 7241 | 4533 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
| 7242 | ( | |
| 4534 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
| 7243 | 4535 | その要素のうち、評価した式が真となったものからなるリスト値が返されます。 |
| 7244 | スカラコンテキストでは、式が真となった回数を返します。 | |
| 4536 | スカラコンテキストでは、式が真となった回数を返します。 例: | |
| 7245 | 4537 | |
| 7246 | | |
| 4538 | @foo = grep(!/^#/, @bar); # weed out comments | |
| 7247 | 4539 | |
| 7248 | 4540 | =begin original |
| 7249 | 4541 | |
| 7250 | 4542 | or equivalently, |
| 7251 | 4543 | |
| 7252 | 4544 | =end original |
| 7253 | 4545 | |
| 7254 | 4546 | あるいは等価な例として: |
| 7255 | 4547 | |
| 7256 | | |
| 4548 | @foo = grep {!/^#/} @bar; # weed out comments | |
| 7257 | 4549 | |
| 7258 | 4550 | =begin original |
| 7259 | 4551 | |
| 7260 | Note that | |
| 4552 | Note that C<$_> is an alias to the list value, so it can be used to | |
| 7261 | be used to | |
| 7262 | 4553 | modify the elements of the LIST. While this is useful and supported, |
| 7263 | 4554 | it can cause bizarre results if the elements of LIST are not variables. |
| 7264 | 4555 | Similarly, grep returns aliases into the original list, much as a for |
| 7265 | 4556 | loop's index variable aliases the list elements. That is, modifying an |
| 7266 | element of a list returned by grep (for example, in a C<foreach>, | |
| 4557 | element of a list returned by grep (for example, in a C<foreach>, C<map> | |
| 7267 | ||
| 4558 | or another C<grep>) actually modifies the element in the original list. | |
| 7268 | actually modifies the element in the original list. | |
| 7269 | 4559 | This is usually something to be avoided when writing clear code. |
| 7270 | 4560 | |
| 7271 | 4561 | =end original |
| 7272 | 4562 | |
| 7273 | ||
| 4563 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 7274 | 4564 | 変更するために使うことができます。 |
| 7275 | 4565 | これは、便利でサポートされていますが、 |
| 7276 | 4566 | LIST の要素が変数でないと、おかしな結果になります。 |
| 7277 | 同様に、grep は元のリストへのエイリアスを返します | |
| 4567 | 同様に、grep は元のリストへのエイリアスを返します。 | |
| 7278 | インデックス変数がリスト要素のエイリアスであるのと | |
| 4568 | for ループのインデックス変数がリスト要素のエイリアスであるのと | |
| 4569 | 同様です。 | |
| 7279 | 4570 | つまり、grep で返されたリストの要素を |
| 7280 | (C<foreach>, | |
| 4571 | (C<foreach>, C<map>, または他の C<grep> で)修正すると | |
| 7281 | ||
| 4572 | 元のリストの要素が変更されます。 | |
| 7282 | これはきれいなコードを書 | |
| 4573 | これはきれいなコードを書こうとする邪魔になることが多いです。 | |
| 7283 | 4574 | |
| 7284 | 4575 | =begin original |
| 7285 | 4576 | |
| 7286 | See also L< | |
| 4577 | See also L</map> for a list composed of the results of the BLOCK or EXPR. | |
| 7287 | the BLOCK or EXPR. | |
| 7288 | 4578 | |
| 7289 | 4579 | =end original |
| 7290 | 4580 | |
| 7291 | BLOCK や EXPR の結果をリストの形にしたい場合は L< | |
| 4581 | BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。 | |
| 7292 | 参照してください。 | |
| 7293 | 4582 | |
| 7294 | 4583 | =item hex EXPR |
| 7295 | X<hex> X<hexadecimal> | |
| 7296 | 4584 | |
| 7297 | 4585 | =item hex |
| 7298 | 4586 | |
| 7299 | =for Pod::Functions convert a hexadecimal string to a number | |
| 7300 | ||
| 7301 | 4587 | =begin original |
| 7302 | 4588 | |
| 7303 | Interprets EXPR as a hex string and returns the corresponding | |
| 4589 | Interprets EXPR as a hex string and returns the corresponding value. | |
| 7304 | ||
| 4590 | (To convert strings that might start with either 0, 0x, or 0b, see | |
| 4591 | L</oct>.) If EXPR is omitted, uses C<$_>. | |
| 7305 | 4592 | |
| 7306 | 4593 | =end original |
| 7307 | 4594 | |
| 7308 | EXPR を 16 進数の文字列と解釈して、対応する | |
| 4595 | EXPR を 16 進数の文字列と解釈して、対応する値を返します。 | |
| 7309 | ||
| 4596 | (0, 0x, 0b で始まる文字列の変換には、L</oct> を | |
| 4597 | 参照してください。) | |
| 4598 | EXPR が省略されると、C<$_> を使用します。 | |
| 7310 | 4599 | |
| 7311 | 4600 | print hex '0xAf'; # prints '175' |
| 7312 | 4601 | print hex 'aF'; # same |
| 7313 | $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/ | |
| 7314 | 4602 | |
| 7315 | 4603 | =begin original |
| 7316 | 4604 | |
| 7317 | ||
| 4605 | Hex strings may only represent integers. Strings that would cause | |
| 7318 | ||
| 4606 | integer overflow trigger a warning. | |
| 7319 | Any other character triggers a warning and causes the rest of the string | |
| 7320 | to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>). | |
| 7321 | Only integers can be represented, and integer overflow triggers a warning. | |
| 7322 | 4607 | |
| 7323 | 4608 | =end original |
| 7324 | 4609 | |
| 7325 | 16 進文字列は | |
| 4610 | 16 進文字列は整数のみを表現します。 | |
| 7326 | ||
| 4611 | 整数オーバーフローを起こすような文字列は警告を引き起こします。 | |
| 7327 | その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と | |
| 7328 | 異なり)文字列の残りの部分は無視されます。 | |
| 7329 | 整数のみを表現でき、整数オーバーフローは警告を引き起こします。 | |
| 7330 | 4612 | |
| 7331 | = | |
| 4613 | =item import | |
| 7332 | 4614 | |
| 7333 | To convert strings that might start with any of C<0>, C<0x>, or C<0b>, | |
| 7334 | see L<C<oct>|/oct EXPR>. To present something as hex, look into | |
| 7335 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 7336 | L<C<sprintf>|/sprintf FORMAT, LIST>, and | |
| 7337 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
| 7338 | ||
| 7339 | =end original | |
| 7340 | ||
| 7341 | C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、 | |
| 7342 | L<C<oct>|/oct EXPR> を参照してください。 | |
| 7343 | 何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, | |
| 7344 | L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を | |
| 7345 | 参照してください。 | |
| 7346 | ||
| 7347 | =item import LIST | |
| 7348 | X<import> | |
| 7349 | ||
| 7350 | =for Pod::Functions patch a module's namespace into your own | |
| 7351 | ||
| 7352 | 4615 | =begin original |
| 7353 | 4616 | |
| 7354 | There is no builtin | |
| 4617 | There is no builtin C<import> function. It is just an ordinary | |
| 7355 | ||
| 4618 | method (subroutine) defined (or inherited) by modules that wish to export | |
| 7356 | ||
| 4619 | names to another module. The C<use> function calls the C<import> method | |
| 7357 | ||
| 4620 | for the package used. See also L</use>, L<perlmod>, and L<Exporter>. | |
| 7358 | L<C<import>|/import LIST> method for the package used. See also | |
| 7359 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>. | |
| 7360 | 4621 | |
| 7361 | 4622 | =end original |
| 7362 | 4623 | |
| 7363 | ||
| 4625 | 組み込みの C<import> 関数というものはありません。 | |
| 7364 | 4626 | これは単に、別のモジュールに名前をエクスポートしたいモジュールが |
| 7365 | 4627 | 定義した(または継承した)、通常のメソッド(サブルーチン)です。 |
| 7366 | ||
| 4628 | C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。 | |
| 7367 | L< | |
| 4629 | L</use>, L<perlmod>, L<Exporter> も参照してください。 | |
| 7368 | L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も | |
| 7369 | 参照してください。 | |
| 7370 | 4630 | |
| 7371 | 4631 | =item index STR,SUBSTR,POSITION |
| 7372 | X<index> X<indexOf> X<InStr> | |
| 7373 | 4632 | |
| 7374 | 4633 | =item index STR,SUBSTR |
| 7375 | 4634 | |
| 7376 | =for Pod::Functions find a substring within a string | |
| 7377 | ||
| 7378 | 4635 | =begin original |
| 7379 | 4636 | |
| 7380 | 4637 | The index function searches for one string within another, but without |
| 7381 | 4638 | the wildcard-like behavior of a full regular-expression pattern match. |
| 7382 | 4639 | It returns the position of the first occurrence of SUBSTR in STR at |
| 7383 | 4640 | or after POSITION. If POSITION is omitted, starts searching from the |
| 7384 | beginning of the string. | |
| 4641 | beginning of the string. The return value is based at C<0> (or whatever | |
| 7385 | o | |
| 4642 | you've set the C<$[> variable to--but don't do that). If the substring | |
| 7386 | ||
| 4643 | is not found, returns one less than the base, ordinarily C<-1>. | |
| 7387 | If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION> | |
| 7388 | returns -1. | |
| 7389 | 4644 | |
| 7390 | 4645 | =end original |
| 7391 | 4646 | |
| 7392 | 4647 | index 関数は ある文字列をもうひとつの文字列から検索しますが、 |
| 7393 | 4648 | 完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。 |
| 7394 | 4649 | STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。 |
| 7395 | 4650 | POSITION が省略された場合には、STR の最初から探し始めます。 |
| 7396 | ||
| 4651 | 返り値のベースは、C<0> (もしくは、変数 C<$[> に設定した値です -- しかし、 | |
| 7397 | ||
| 4652 | これは使ってはいけません)。 | |
| 7398 | ||
| 4653 | SUBSTR が見つからなかった場合には、ベースよりも 1 小さい値、 | |
| 7399 | ||
| 4654 | 通常は C<-1> が返されます。 | |
| 7400 | -1 が返されます。 | |
| 7401 | 4655 | |
| 7402 | 4656 | =item int EXPR |
| 7403 | X<int> X<integer> X<truncate> X<trunc> X<floor> | |
| 7404 | 4657 | |
| 7405 | 4658 | =item int |
| 7406 | 4659 | |
| 7407 | =for Pod::Functions get the integer portion of a number | |
| 7408 | ||
| 7409 | 4660 | =begin original |
| 7410 | 4661 | |
| 7411 | Returns the integer portion of EXPR. If EXPR is omitted, uses | |
| 4662 | Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>. | |
| 7412 | L<C<$_>|perlvar/$_>. | |
| 7413 | 4663 | You should not use this function for rounding: one because it truncates |
| 7414 | towards C<0>, and two because machine representations of floating | |
| 4664 | towards C<0>, and two because machine representations of floating point | |
| 7415 | 4665 | numbers can sometimes produce counterintuitive results. For example, |
| 7416 | 4666 | C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's |
| 7417 | 4667 | because it's really more like -268.99999999999994315658 instead. Usually, |
| 7418 | the | |
| 4668 | the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil> | |
| 7419 | ||
| 4669 | functions will serve you better than will int(). | |
| 7420 | L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>> | |
| 7421 | functions will serve you better than will L<C<int>|/int EXPR>. | |
| 7422 | 4670 | |
| 7423 | 4671 | =end original |
| 7424 | 4672 | |
| 7425 | 4673 | EXPR の整数部を返します。 |
| 7426 | EXPR | |
| 4674 | EXPR を省略すると、C<$_> を使います。 | |
| 7427 | この関数を丸めのために使うべきではありません | |
| 4675 | この関数を丸めのために使うべきではありません。 | |
| 7428 | 方向への切捨てを行うから、第二の理由として | |
| 4676 | 第一の理由として C<0> の方向への切捨てを行うから、第二の理由として | |
| 7429 | 反した結果を生み出すからです。 | |
| 4677 | 浮動小数点数の機械表現は時々直感に反した結果を生み出すからです。 | |
| 7430 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく | |
| 4678 | たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく | |
| 7431 | ||
| 4679 | -268 を返します。 | |
| 7432 | なっているからです。 | |
| 4680 | これは実際には -268.99999999999994315658 というような値になっているからです。 | |
| 7433 | 通常、 | |
| 4681 | 通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が | |
| 7434 | ||
| 4682 | int() より便利です。 | |
| 7435 | L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が | |
| 7436 | L<C<int>|/int EXPR> より便利です。 | |
| 7437 | 4683 | |
| 7438 | 4684 | =item ioctl FILEHANDLE,FUNCTION,SCALAR |
| 7439 | X<ioctl> | |
| 7440 | 4685 | |
| 7441 | =for Pod::Functions system-dependent device control system call | |
| 7442 | ||
| 7443 | 4686 | =begin original |
| 7444 | 4687 | |
| 7445 | Implements the | |
| 4688 | Implements the ioctl(2) function. You'll probably first have to say | |
| 7446 | 4689 | |
| 7447 | 4690 | =end original |
| 7448 | 4691 | |
| 7449 | ||
| 4692 | ioctl(2) 関数を実装します。 | |
| 7450 | 4693 | 正しい関数の定義を得るために、おそらく最初に |
| 7451 | 4694 | |
| 7452 | require " | |
| 4695 | require "ioctl.ph"; # probably in /usr/local/lib/perl/ioctl.ph | |
| 7453 | # $Config{archlib}/sys/ioctl.ph | |
| 7454 | 4696 | |
| 7455 | 4697 | =begin original |
| 7456 | 4698 | |
| 7457 | to get the correct function definitions. If F< | |
| 4699 | to get the correct function definitions. If F<ioctl.ph> doesn't | |
| 7458 | 4700 | exist or doesn't have the correct definitions you'll have to roll your |
| 7459 | 4701 | own, based on your C header files such as F<< <sys/ioctl.h> >>. |
| 7460 | 4702 | (There is a Perl script called B<h2ph> that comes with the Perl kit that |
| 7461 | 4703 | may help you in this, but it's nontrivial.) SCALAR will be read and/or |
| 7462 | written depending on the FUNCTION | |
| 4704 | written depending on the FUNCTION--a pointer to the string value of SCALAR | |
| 7463 | will be passed as the third argument of the actual | |
| 4705 | will be passed as the third argument of the actual C<ioctl> call. (If SCALAR | |
| 7464 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR | |
| 7465 | 4706 | has no string value but does have a numeric value, that value will be |
| 7466 | 4707 | passed rather than a pointer to the string value. To guarantee this to be |
| 7467 | true, add a C<0> to the scalar before using it.) The | |
| 4708 | true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack> | |
| 7468 | L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 7469 | 4709 | functions may be needed to manipulate the values of structures used by |
| 7470 | ||
| 4710 | C<ioctl>. | |
| 7471 | 4711 | |
| 7472 | 4712 | =end original |
| 7473 | 4713 | |
| 7474 | 4714 | としなくてはならないでしょう。 |
| 7475 | ||
| 4715 | ioctl.h がないか、間違った定義をしている場合には、 | |
| 7476 | F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、 | |
| 4716 | F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、 | |
| 7477 | 4717 | 自分で作らなければなりません。 |
| 7478 | (Perl の配布キットに入っている B<h2ph> という | |
| 4718 | (Perl の配布キットに入っている B<h2ph> という | |
| 7479 | これを手助けしてくれるでしょうが、これは | |
| 4719 | Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要です。) | |
| 7480 | FOUNCTION に応じて SCALAR が読み書きされます | |
| 4720 | FOUNCTION に応じて SCALAR が読み書きされます。 | |
| 7481 | SCALAR の文字列値へのポインタが、実際の | |
| 4721 | SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの | |
| 7482 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの | |
| 7483 | 4722 | 3 番目の引数として渡されます。 |
| 7484 | 4723 | (SCALAR が文字列値を持っておらず、数値を持っている場合には、 |
| 7485 | 4724 | 文字列値へのポインタの代わりに、その値が渡されます。 |
| 7486 | 4725 | このことを保証するためには、使用する前に SCALAR にC<0> を足してください。) |
| 7487 | ||
| 4726 | C<ioctl> で使われる構造体の値を操作するには、 | |
| 7488 | ||
| 4727 | C<pack> 関数と C<unpack> 関数が必要となるでしょう。 | |
| 7489 | L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。 | |
| 7490 | 4728 | |
| 7491 | 4729 | =begin original |
| 7492 | 4730 | |
| 7493 | The return value of | |
| 4731 | The return value of C<ioctl> (and C<fcntl>) is as follows: | |
| 7494 | L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows: | |
| 7495 | 4732 | |
| 7496 | 4733 | =end original |
| 7497 | 4734 | |
| 7498 | ||
| 4735 | C<ioctl> (と C<fcntl>) の返り値は、以下のようになります: | |
| 7499 | (と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、 | |
| 7500 | 以下のようになります: | |
| 7501 | 4736 | |
| 7502 | 4737 | =begin original |
| 7503 | 4738 | |
| 7504 | ||
| 4739 | if OS returns: then Perl returns: | |
| 7505 | | |
| 4740 | -1 undefined value | |
| 7506 | | |
| 4741 | 0 string "0 but true" | |
| 7507 | ||
| 4742 | anything else that number | |
| 7508 | 4743 | |
| 7509 | 4744 | =end original |
| 7510 | 4745 | |
| 7511 | ||
| 4746 | OS が返した値: Perl が返す値: | |
| 7512 | | |
| 4747 | -1 未定義値 | |
| 7513 | | |
| 4748 | 0 「0 だが真」の文字列 | |
| 7514 | | |
| 4749 | その他 その値そのもの | |
| 7515 | 4750 | |
| 7516 | 4751 | =begin original |
| 7517 | 4752 | |
| 7518 | 4753 | Thus Perl returns true on success and false on failure, yet you can |
| 7519 | 4754 | still easily determine the actual value returned by the operating |
| 7520 | 4755 | system: |
| 7521 | 4756 | |
| 7522 | 4757 | =end original |
| 7523 | 4758 | |
| 7524 | 4759 | つまり Perl は、成功時に「真」、失敗時に「偽」を返す |
| 7525 | 4760 | ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。 |
| 7526 | 4761 | |
| 7527 | | |
| 4762 | $retval = ioctl(...) || -1; | |
| 7528 | 4763 | printf "System returned %d\n", $retval; |
| 7529 | 4764 | |
| 7530 | 4765 | =begin original |
| 7531 | 4766 | |
| 7532 | The special string C< | |
| 4767 | The special string "C<0> but true" is exempt from B<-w> complaints | |
| 7533 | ||
| 4768 | about improper numeric conversions. | |
| 7534 | L<warnings> on improper numeric conversions. | |
| 7535 | 4769 | |
| 7536 | 4770 | =end original |
| 7537 | 4771 | |
| 7538 | 4772 | 特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する |
| 7539 | ||
| 4773 | B<-w> 警告を回避します。 | |
| 7540 | L<warnings> 警告を回避します。 | |
| 7541 | 4774 | |
| 7542 | 4775 | =begin original |
| 7543 | 4776 | |
| 7544 | ||
| 4777 | Here's an example of setting a filehandle named C<REMOTE> to be | |
| 4778 | non-blocking at the system level. You'll have to negotiate C<$|> | |
| 4779 | on your own, though. | |
| 7545 | 4780 | |
| 7546 | 4781 | =end original |
| 7547 | 4782 | |
| 7548 | ||
| 4783 | これは C<REMOTE> というファイルハンドルをシステムレベルで | |
| 4784 | 非ブロックモードにセットする例です。 | |
| 4785 | ただし、 C<$|> を自分で管理しなければなりません。 | |
| 7549 | 4786 | |
| 7550 | ||
| 4787 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | |
| 7551 | X<join> | |
| 7552 | 4788 | |
| 7553 | ||
| 4789 | $flags = fcntl(REMOTE, F_GETFL, 0) | |
| 4790 | or die "Can't get flags for the socket: $!\n"; | |
| 7554 | 4791 | |
| 4792 | $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK) | |
| 4793 | or die "Can't set flags for the socket: $!\n"; | |
| 4794 | ||
| 4795 | =item join EXPR,LIST | |
| 4796 | ||
| 7555 | 4797 | =begin original |
| 7556 | 4798 | |
| 7557 | 4799 | Joins the separate strings of LIST into a single string with fields |
| 7558 | 4800 | separated by the value of EXPR, and returns that new string. Example: |
| 7559 | 4801 | |
| 7560 | 4802 | =end original |
| 7561 | 4803 | |
| 7562 | 4804 | LIST の個別の文字列を、EXPR の値で区切って |
| 7563 | 4805 | 1 つの文字列につなげ、その文字列を返します。 |
| 7564 | 4806 | 例: |
| 7565 | 4807 | |
| 7566 | | |
| 4808 | $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); | |
| 7567 | 4809 | |
| 7568 | 4810 | =begin original |
| 7569 | 4811 | |
| 7570 | Beware that unlike | |
| 4812 | Beware that unlike C<split>, C<join> doesn't take a pattern as its | |
| 7571 | ||
| 4813 | first argument. Compare L</split>. | |
| 7572 | Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>. | |
| 7573 | 4814 | |
| 7574 | 4815 | =end original |
| 7575 | 4816 | |
| 7576 | ||
| 4817 | C<split> と違って、C<join> は最初の引数にパターンは取れないことに | |
| 7577 | L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに | |
| 7578 | 4818 | 注意してください。 |
| 7579 | L< | |
| 4819 | L</split> と比較してください。 | |
| 7580 | 4820 | |
| 7581 | 4821 | =item keys HASH |
| 7582 | X<keys> X<key> | |
| 7583 | 4822 | |
| 7584 | =item keys ARRAY | |
| 7585 | ||
| 7586 | =for Pod::Functions retrieve list of indices from a hash | |
| 7587 | ||
| 7588 | 4823 | =begin original |
| 7589 | 4824 | |
| 7590 | ||
| 4825 | Returns a list consisting of all the keys of the named hash. (In | |
| 7591 | ||
| 4826 | scalar context, returns the number of keys.) The keys are returned in | |
| 7592 | rel | |
| 4827 | an apparently random order. The actual random order is subject to | |
| 7593 | a | |
| 4828 | change in future versions of perl, but it is guaranteed to be the same | |
| 4829 | order as either the C<values> or C<each> function produces (given | |
| 4830 | that the hash has not been modified). As a side effect, it resets | |
| 4831 | HASH's iterator. | |
| 7594 | 4832 | |
| 7595 | 4833 | =end original |
| 7596 | 4834 | |
| 7597 | ||
| 4835 | 指定したハッシュのすべての key からなる、リストを返します。 | |
| 7598 | ||
| 4836 | (スカラコンテキストでは、key の数を返します。) | |
| 7599 | ||
| 4837 | キーは見たところではランダムな順番に返されます。 | |
| 7600 | ||
| 4838 | 実際のランダムな順番は perl の将来のバージョンでは変わるかもしれませんが、 | |
| 4839 | C<values> や C<each> 関数が同じ(変更されていない)ハッシュに対して | |
| 4840 | 生成するのと同じ順番であることは保証されます。 | |
| 4841 | 副作用として、HASH の反復子を初期化します。 | |
| 7601 | 4842 | |
| 7602 | 4843 | =begin original |
| 7603 | 4844 | |
| 7604 | Hash entries are returned in an apparently random order. The actual random | |
| 7605 | order is specific to a given hash; the exact same series of operations | |
| 7606 | on two hashes may result in a different order for each hash. Any insertion | |
| 7607 | into the hash may change the order, as will any deletion, with the exception | |
| 7608 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 7609 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 7610 | long as a given hash is unmodified you may rely on | |
| 7611 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each | |
| 7612 | HASH> to repeatedly return the same order | |
| 7613 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 7614 | details on why hash order is randomized. Aside from the guarantees | |
| 7615 | provided here the exact details of Perl's hash algorithm and the hash | |
| 7616 | traversal order are subject to change in any release of Perl. Tied hashes | |
| 7617 | may behave differently to Perl's hashes with respect to changes in order on | |
| 7618 | insertion and deletion of items. | |
| 7619 | ||
| 7620 | =end original | |
| 7621 | ||
| 7622 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 | |
| 7623 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の | |
| 7624 | 操作を行っても、ハッシュによって異なった順序になります。 | |
| 7625 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 | |
| 7626 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 7627 | 最近のキーは順序を変えることなく削除できます。 | |
| 7628 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 7629 | L<C<each>|/each HASH> が繰り返し同じ順序で | |
| 7630 | 返すことに依存してもかまいません。 | |
| 7631 | なぜハッシュの順序がランダム化されているかの詳細については | |
| 7632 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
| 7633 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
| 7634 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
| 7635 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
| 7636 | 異なった振る舞いをします。 | |
| 7637 | ||
| 7638 | =begin original | |
| 7639 | ||
| 7640 | As a side effect, calling L<C<keys>|/keys HASH> resets the internal | |
| 7641 | iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before | |
| 7642 | yielding the keys. In | |
| 7643 | particular, calling L<C<keys>|/keys HASH> in void context resets the | |
| 7644 | iterator with no other overhead. | |
| 7645 | ||
| 7646 | =end original | |
| 7647 | ||
| 7648 | 副作用として、L<C<keys>|/keys HASH> の呼び出しは、 | |
| 7649 | キーを取り出す前に HASH や ARRAY の反復子を | |
| 7650 | 初期化します (L<C<each>|/each HASH> を参照してください)。 | |
| 7651 | 特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと | |
| 7652 | オーバーヘッドなしで反復子を初期化します。 | |
| 7653 | ||
| 7654 | =begin original | |
| 7655 | ||
| 7656 | 4845 | Here is yet another way to print your environment: |
| 7657 | 4846 | |
| 7658 | 4847 | =end original |
| 7659 | 4848 | |
| 7660 | 4849 | 環境変数を表示する別の例です: |
| 7661 | 4850 | |
| 7662 | | |
| 4851 | @keys = keys %ENV; | |
| 7663 | | |
| 4852 | @values = values %ENV; | |
| 7664 | while (@keys) { | |
| 4853 | while (@keys) { | |
| 7665 | ||
| 4854 | print pop(@keys), '=', pop(@values), "\n"; | |
| 7666 | 4855 | } |
| 7667 | 4856 | |
| 7668 | 4857 | =begin original |
| 7669 | 4858 | |
| 7670 | 4859 | or how about sorted by key: |
| 7671 | 4860 | |
| 7672 | 4861 | =end original |
| 7673 | 4862 | |
| 7674 | 4863 | key でソートしてもいいでしょう: |
| 7675 | 4864 | |
| 7676 | foreach | |
| 4865 | foreach $key (sort(keys %ENV)) { | |
| 7677 | ||
| 4866 | print $key, '=', $ENV{$key}, "\n"; | |
| 7678 | 4867 | } |
| 7679 | 4868 | |
| 7680 | 4869 | =begin original |
| 7681 | 4870 | |
| 7682 | 4871 | The returned values are copies of the original keys in the hash, so |
| 7683 | modifying them will not affect the original hash. Compare | |
| 4872 | modifying them will not affect the original hash. Compare L</values>. | |
| 7684 | L<C<values>|/values HASH>. | |
| 7685 | 4873 | |
| 7686 | 4874 | =end original |
| 7687 | 4875 | |
| 7688 | 4876 | 返される値はハッシュにある元のキーのコピーなので、 |
| 7689 | 4877 | これを変更しても元のハッシュには影響を与えません。 |
| 7690 | L< | |
| 4878 | L</values> と比較してください。 | |
| 7691 | 4879 | |
| 7692 | 4880 | =begin original |
| 7693 | 4881 | |
| 7694 | To sort a hash by value, you'll need to use a | |
| 4882 | To sort a hash by value, you'll need to use a C<sort> function. | |
| 7695 | ||
| 4883 | Here's a descending numeric sort of a hash by its values: | |
| 7696 | sort of a hash by its values: | |
| 7697 | 4884 | |
| 7698 | 4885 | =end original |
| 7699 | 4886 | |
| 7700 | ハッシュを値でソートするためには、 | |
| 4887 | ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。 | |
| 7701 | 必要があります。 | |
| 7702 | 4888 | 以下ではハッシュの値を数値の降順でソートしています: |
| 7703 | 4889 | |
| 7704 | foreach | |
| 4890 | foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) { | |
| 7705 | ||
| 4891 | printf "%4d %s\n", $hash{$key}, $key; | |
| 7706 | 4892 | } |
| 7707 | 4893 | |
| 7708 | 4894 | =begin original |
| 7709 | 4895 | |
| 7710 | ||
| 4896 | As an lvalue C<keys> allows you to increase the number of hash buckets | |
| 7711 | number of hash buckets | |
| 7712 | 4897 | allocated for the given hash. This can gain you a measure of efficiency if |
| 7713 | 4898 | you know the hash is going to get big. (This is similar to pre-extending |
| 7714 | 4899 | an array by assigning a larger number to $#array.) If you say |
| 7715 | 4900 | |
| 7716 | 4901 | =end original |
| 7717 | 4902 | |
| 7718 | 左辺値として | |
| 4903 | 左辺値としては、C<keys> を使うことで与えられたハッシュに割り当てられた | |
| 7719 | ||
| 4904 | ハッシュ表の大きさを増やすことができます。 | |
| 7720 | 4905 | これによって、ハッシュが大きくなっていくなっていくときの |
| 7721 | 効率の測定ができます。 | |
| 4906 | 効率の測定ができます。以下のようにすると: | |
| 7722 | (これは大きい値を $#array に代入することで配列を予め拡張することに | |
| 7723 | 似ています。) | |
| 7724 | 以下のようにすると: | |
| 7725 | 4907 | |
| 7726 | 4908 | keys %hash = 200; |
| 7727 | 4909 | |
| 7728 | 4910 | =begin original |
| 7729 | 4911 | |
| 7730 | 4912 | then C<%hash> will have at least 200 buckets allocated for it--256 of them, |
| 7731 | 4913 | in fact, since it rounds up to the next power of two. These |
| 7732 | 4914 | buckets will be retained even if you do C<%hash = ()>, use C<undef |
| 7733 | 4915 | %hash> if you want to free the storage while C<%hash> is still in scope. |
| 7734 | 4916 | You can't shrink the number of buckets allocated for the hash using |
| 7735 | ||
| 4917 | C<keys> in this way (but you needn't worry about doing this by accident, | |
| 7736 | ||
| 4918 | as trying has no effect). | |
| 7737 | context is a syntax error. | |
| 7738 | 4919 | |
| 7739 | 4920 | =end original |
| 7740 | 4921 | |
| 7741 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
| 4922 | C<%hash> は少なくとも 200 の大きさの表が割り当てられます -- | |
| 7742 | 4923 | 実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。 |
| 7743 | 4924 | この表はたとえ C<%hash = ()> としても残るので、 |
| 7744 | 4925 | もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は |
| 7745 | 4926 | C<undef %hash> を使います。 |
| 7746 | この方法で | |
| 4927 | この方法で C<keys> を使うことで、表の大きさを小さくすることはできません | |
| 7747 | できません | |
| 7748 | 4928 | (間違えてそのようなことをしても何も起きないので気にすることはありません)。 |
| 7749 | 左辺値コンテキストでの C<keys @array> は文法エラーとなります。 | |
| 7750 | 4929 | |
| 7751 | 4930 | =begin original |
| 7752 | 4931 | |
| 7753 | S | |
| 4932 | See also C<each>, C<values> and C<sort>. | |
| 7754 | L<C<keys>|/keys HASH> to take a scalar expression. This experiment has | |
| 7755 | been deemed unsuccessful, and was removed as of Perl 5.24. | |
| 7756 | 4933 | |
| 7757 | 4934 | =end original |
| 7758 | 4935 | |
| 7759 | ||
| 4936 | C<each>, C<values>, C<sort> も参照してください。 | |
| 7760 | 実験的機能がありました。 | |
| 7761 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 7762 | 4937 | |
| 7763 | =begin original | |
| 7764 | ||
| 7765 | To avoid confusing would-be users of your code who are running earlier | |
| 7766 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
| 7767 | the top of your file to signal that your code will work I<only> on Perls of | |
| 7768 | a recent vintage: | |
| 7769 | ||
| 7770 | =end original | |
| 7771 | ||
| 7772 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
| 7773 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
| 7774 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
| 7775 | 書いてください: | |
| 7776 | ||
| 7777 | use 5.012; # so keys/values/each work on arrays | |
| 7778 | ||
| 7779 | =begin original | |
| 7780 | ||
| 7781 | See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and | |
| 7782 | L<C<sort>|/sort SUBNAME LIST>. | |
| 7783 | ||
| 7784 | =end original | |
| 7785 | ||
| 7786 | L<C<each>|/each HASH>, L<C<values>|/values HASH>, | |
| 7787 | L<C<sort>|/sort SUBNAME LIST> も参照してください。 | |
| 7788 | ||
| 7789 | 4938 | =item kill SIGNAL, LIST |
| 7790 | 4939 | |
| 7791 | =item kill SIGNAL | |
| 7792 | X<kill> X<signal> | |
| 7793 | ||
| 7794 | =for Pod::Functions send a signal to a process or process group | |
| 7795 | ||
| 7796 | 4940 | =begin original |
| 7797 | 4941 | |
| 7798 | Sends a signal to a list of processes. Returns the number of | |
| 4942 | Sends a signal to a list of processes. Returns the number of | |
| 7799 | ||
| 4943 | processes successfully signaled (which is not necessarily the | |
| 7800 | as the number | |
| 4944 | same as the number actually killed). | |
| 7801 | killed). | |
| 7802 | 4945 | |
| 7803 | 4946 | =end original |
| 7804 | 4947 | |
| 7805 | プロセスのリストにシグナルを送ります。 | |
| 4948 | プロセスのリストにシグナルを送ります。シグナル送信に成功したプロセスの | |
| 7806 | ||
| 4949 | 数を返します | |
| 7807 | ( | |
| 4950 | (実際に kill に成功したプロセスと同じとは限りません)。 | |
| 7808 | プロセスの数と同じとは限りません)。 | |
| 7809 | 4951 | |
| 7810 | | |
| 4952 | $cnt = kill 1, $child1, $child2; | |
| 7811 | kill | |
| 4953 | kill 9, @goners; | |
| 7812 | 4954 | |
| 7813 | 4955 | =begin original |
| 7814 | 4956 | |
| 7815 | SIGNAL | |
| 4957 | If SIGNAL is zero, no signal is sent to the process. This is a | |
| 7816 | ||
| 4958 | useful way to check that the process is alive and hasn't changed | |
| 7817 | s | |
| 4959 | its UID. See L<perlport> for notes on the portability of this | |
| 7818 | ||
| 4960 | construct. | |
| 7819 | 4961 | |
| 7820 | 4962 | =end original |
| 7821 | 4963 | |
| 7822 | SIGNAL | |
| 4964 | SIGNAL がゼロの場合、プロセスにシグナルは送られません。 | |
| 7823 | ||
| 4965 | これはプロセスが生きていて、 UID が変わっていないことを調べる時に | |
| 7824 | ||
| 4966 | 有用です。 | |
| 7825 | 移植性 | |
| 4967 | この構成の移植性に関する注意については L<perlport> を参照して下さい。 | |
| 7826 | オペレーティングシステムでは異なった番号になることがあるからです。 | |
| 7827 | 4968 | |
| 7828 | 4969 | =begin original |
| 7829 | 4970 | |
| 7830 | ||
| 4971 | Unlike in the shell, if SIGNAL is negative, it kills | |
| 7831 | ||
| 4972 | process groups instead of processes. (On System V, a negative I<PROCESS> | |
| 7832 | ||
| 4973 | number will also kill process groups, but that's not portable.) That | |
| 4974 | means you usually want to use positive not negative signals. You may also | |
| 4975 | use a signal name in quotes. See L<perlipc/"Signals"> for details. | |
| 7833 | 4976 | |
| 7834 | 4977 | =end original |
| 7835 | 4978 | |
| 7836 | ||
| 4979 | シェルとは異なり、シグナルに負の数を与えると、 | |
| 7837 | モジュールによって提供される C<$Config{sig_name}> にあります。 | |
| 7838 | さらなる詳細については L<Config> を参照してください。 | |
| 7839 | ||
| 7840 | =begin original | |
| 7841 | ||
| 7842 | A negative signal name is the same as a negative signal number, killing process | |
| 7843 | groups instead of processes. For example, C<kill '-KILL', $pgrp> and | |
| 7844 | C<kill -9, $pgrp> will send C<SIGKILL> to | |
| 7845 | the entire process group specified. That | |
| 7846 | means you usually want to use positive not negative signals. | |
| 7847 | ||
| 7848 | =end original | |
| 7849 | ||
| 7850 | 負のシグナル名は負のシグナル番号と同じで、 | |
| 7851 | 4980 | プロセスではなくプロセスグループに対して kill を行ないます。 |
| 7852 | ||
| 4981 | (Syetem V では、プロセス番号として負の値を与えても、 | |
| 7853 | プロセスグループ | |
| 4982 | プロセスグループの kill を行ないますが、 | |
| 4983 | 移植性がありません。) | |
| 7854 | 4984 | すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。 |
| 4985 | シグナル名をクォートして使うこともできます。 | |
| 4986 | 詳細はL<perlipc/"Signals">を参照してください。 | |
| 7855 | 4987 | |
| 7856 | =begin original | |
| 7857 | ||
| 7858 | If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>), | |
| 7859 | no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST> | |
| 7860 | checks whether it's I<possible> to send a signal to it | |
| 7861 | (that means, to be brief, that the process is owned by the same user, or we are | |
| 7862 | the super-user). This is useful to check that a child process is still | |
| 7863 | alive (even if only as a zombie) and hasn't changed its UID. See | |
| 7864 | L<perlport> for notes on the portability of this construct. | |
| 7865 | ||
| 7866 | =end original | |
| 7867 | ||
| 7868 | SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに | |
| 7869 | シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、 | |
| 7870 | シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、 | |
| 7871 | プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを | |
| 7872 | 意味します)。 | |
| 7873 | これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が | |
| 7874 | 変わっていないことを調べる時に有用です。 | |
| 7875 | この構成の移植性に関する注意については L<perlport> を参照してください。 | |
| 7876 | ||
| 7877 | =begin original | |
| 7878 | ||
| 7879 | The behavior of kill when a I<PROCESS> number is zero or negative depends on | |
| 7880 | the operating system. For example, on POSIX-conforming systems, zero will | |
| 7881 | signal the current process group, -1 will signal all processes, and any | |
| 7882 | other negative PROCESS number will act as a negative signal number and | |
| 7883 | kill the entire process group specified. | |
| 7884 | ||
| 7885 | =end original | |
| 7886 | ||
| 7887 | I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは | |
| 7888 | オペレーティングシステムに依存します。 | |
| 7889 | 例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、 | |
| 7890 | -1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は | |
| 7891 | 負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。 | |
| 7892 | ||
| 7893 | =begin original | |
| 7894 | ||
| 7895 | If both the SIGNAL and the PROCESS are negative, the results are undefined. | |
| 7896 | A warning may be produced in a future version. | |
| 7897 | ||
| 7898 | =end original | |
| 7899 | ||
| 7900 | SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。 | |
| 7901 | 将来のバージョンでは警告が出るかも知れません。 | |
| 7902 | ||
| 7903 | =begin original | |
| 7904 | ||
| 7905 | See L<perlipc/"Signals"> for more details. | |
| 7906 | ||
| 7907 | =end original | |
| 7908 | ||
| 7909 | 詳細は L<perlipc/"Signals"> を参照してください。 | |
| 7910 | ||
| 7911 | =begin original | |
| 7912 | ||
| 7913 | On some platforms such as Windows where the L<fork(2)> system call is not | |
| 7914 | available, Perl can be built to emulate L<C<fork>|/fork> at the | |
| 7915 | interpreter level. | |
| 7916 | This emulation has limitations related to kill that have to be considered, | |
| 7917 | for code running on Windows and in code intended to be portable. | |
| 7918 | ||
| 7919 | =end original | |
| 7920 | ||
| 7921 | Windows のような L<fork(2)> が利用不能なシステムでは、Perl は | |
| 7922 | L<C<fork>|/fork> をインタプリタレベルでエミュレートします。 | |
| 7923 | エミュレーションは kill に関連して、コードが Windows で実行されて | |
| 7924 | しかしコードが移植性があると考えられるように制限があります。 | |
| 7925 | ||
| 7926 | =begin original | |
| 7927 | ||
| 7928 | See L<perlfork> for more details. | |
| 7929 | ||
| 7930 | =end original | |
| 7931 | ||
| 7932 | さらなる詳細については L<perlfork> を参照してください。 | |
| 7933 | ||
| 7934 | =begin original | |
| 7935 | ||
| 7936 | If there is no I<LIST> of processes, no signal is sent, and the return | |
| 7937 | value is 0. This form is sometimes used, however, because it causes | |
| 7938 | tainting checks to be run. But see | |
| 7939 | L<perlsec/Laundering and Detecting Tainted Data>. | |
| 7940 | ||
| 7941 | =end original | |
| 7942 | ||
| 7943 | 処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。 | |
| 7944 | しかし、この形式は時々使われます; 実行するために汚染チェックを | |
| 7945 | 引き起こすからです。 | |
| 7946 | しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。 | |
| 7947 | ||
| 7948 | =begin original | |
| 7949 | ||
| 7950 | Portability issues: L<perlport/kill>. | |
| 7951 | ||
| 7952 | =end original | |
| 7953 | ||
| 7954 | 移植性の問題: L<perlport/kill>。 | |
| 7955 | ||
| 7956 | 4988 | =item last LABEL |
| 7957 | X<last> X<break> | |
| 7958 | 4989 | |
| 7959 | =item last EXPR | |
| 7960 | ||
| 7961 | 4990 | =item last |
| 7962 | 4991 | |
| 7963 | =for Pod::Functions exit a block prematurely | |
| 7964 | ||
| 7965 | 4992 | =begin original |
| 7966 | 4993 | |
| 7967 | The | |
| 4994 | The C<last> command is like the C<break> statement in C (as used in | |
| 7968 | (as used in | |
| 7969 | 4995 | loops); it immediately exits the loop in question. If the LABEL is |
| 7970 | omitted, the command refers to the innermost enclosing | |
| 4996 | omitted, the command refers to the innermost enclosing loop. The | |
| 7971 | ||
| 4997 | C<continue> block, if any, is not executed: | |
| 7972 | 5.18.0, allows a label name to be computed at run time, | |
| 7973 | and is otherwise identical to C<last LABEL>. The | |
| 7974 | L<C<continue>|/continue BLOCK> block, if any, is not executed: | |
| 7975 | 4998 | |
| 7976 | 4999 | =end original |
| 7977 | 5000 | |
| 7978 | ||
| 5001 | C<last> コマンドは、(ループ内で使った) C の C<break> 文と | |
| 7979 | 5002 | 同じようなもので、LABEL で指定されるループを即座に抜けます。 |
| 7980 | LABEL が省略されると、 | |
| 5003 | LABEL が省略されると、一番内側のループが対象となります。 | |
| 7981 | ||
| 5004 | C<continue> ブロックがあっても実行されません: | |
| 7982 | ラベル名を使えます; それ以外は C<last LABEL> と同一です。 | |
| 7983 | L<C<continue>|/continue BLOCK> ブロックがあっても実行されません: | |
| 7984 | 5005 | |
| 7985 | 5006 | LINE: while (<STDIN>) { |
| 7986 | ||
| 5007 | last LINE if /^$/; # exit when done with header | |
| 7987 | ||
| 5008 | #... | |
| 7988 | 5009 | } |
| 7989 | 5010 | |
| 7990 | 5011 | =begin original |
| 7991 | 5012 | |
| 7992 | ||
| 5013 | C<last> cannot be used to exit a block which returns a value such as | |
| 7993 | ||
| 5014 | C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit | |
| 7994 | ||
| 5015 | a grep() or map() operation. | |
| 7995 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 7996 | operation. | |
| 7997 | 5016 | |
| 7998 | 5017 | =end original |
| 7999 | 5018 | |
| 8000 | ||
| 5019 | C<last> は C<eval {}>, C<sub {}>, C<do {}> といった | |
| 8001 | ||
| 5020 | 値を返すブロックを終了するのには使えませんし、 | |
| 8002 | ||
| 5021 | grep() や map() 操作を終了するのに使うべきではありません。 | |
| 8003 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 8004 | 使うべきではありません。 | |
| 8005 | 5022 | |
| 8006 | 5023 | =begin original |
| 8007 | 5024 | |
| 8008 | 5025 | Note that a block by itself is semantically identical to a loop |
| 8009 | that executes once. Thus | |
| 5026 | that executes once. Thus C<last> can be used to effect an early | |
| 8010 | ||
| 5027 | exit out of such a block. | |
| 8011 | 5028 | |
| 8012 | 5029 | =end original |
| 8013 | 5030 | |
| 8014 | ブロック自 | |
| 5031 | ブロックはそれ自体文法的には一度だけ実行されるループと同等であることに | |
| 8015 | 注意してください。 | |
| 5032 | 注意してください。従って、C<last> でそのようなブロックを | |
| 8016 | ||
| 5033 | 途中で抜け出すことができます。 | |
| 8017 | 抜け出すことができます。 | |
| 8018 | 5034 | |
| 8019 | 5035 | =begin original |
| 8020 | 5036 | |
| 8021 | See also L< | |
| 5037 | See also L</continue> for an illustration of how C<last>, C<next>, and | |
| 8022 | ||
| 5038 | C<redo> work. | |
| 8023 | L<C<redo>|/redo LABEL> work. | |
| 8024 | 5039 | |
| 8025 | 5040 | =end original |
| 8026 | 5041 | |
| 8027 | ||
| 5042 | C<last>, C<next>, C<redo> がどのように働くかについては | |
| 8028 | ||
| 5043 | L</continue> を参照して下さい。 | |
| 8029 | 5044 | |
| 8030 | =begin original | |
| 8031 | ||
| 8032 | Unlike most named operators, this has the same precedence as assignment. | |
| 8033 | It is also exempt from the looks-like-a-function rule, so | |
| 8034 | C<last ("foo")."bar"> will cause "bar" to be part of the argument to | |
| 8035 | L<C<last>|/last LABEL>. | |
| 8036 | ||
| 8037 | =end original | |
| 8038 | ||
| 8039 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
| 8040 | また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と | |
| 8041 | すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。 | |
| 8042 | ||
| 8043 | 5045 | =item lc EXPR |
| 8044 | X<lc> X<lowercase> | |
| 8045 | 5046 | |
| 8046 | 5047 | =item lc |
| 8047 | 5048 | |
| 8048 | =for Pod::Functions return lower-case version of a string | |
| 8049 | ||
| 8050 | 5049 | =begin original |
| 8051 | 5050 | |
| 8052 | Returns a lowercased version of EXPR. This is the internal function | |
| 5051 | Returns an lowercased version of EXPR. This is the internal function | |
| 8053 | 5052 | implementing the C<\L> escape in double-quoted strings. |
| 5053 | Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale> | |
| 5054 | and L<utf8>. | |
| 8054 | 5055 | |
| 8055 | 5056 | =end original |
| 8056 | 5057 | |
| 8057 | 5058 | EXPR を小文字に変換したものを返します。 |
| 8058 | 5059 | これは、ダブルクォート文字列における、 |
| 8059 | 5060 | C<\L> エスケープを実装する内部関数です。 |
| 5061 | C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。 | |
| 5062 | L<perllocale> と L<utf8> を参照してください。 | |
| 8060 | 5063 | |
| 8061 | 5064 | =begin original |
| 8062 | 5065 | |
| 8063 | If EXPR is omitted, uses | |
| 5066 | If EXPR is omitted, uses C<$_>. | |
| 8064 | 5067 | |
| 8065 | 5068 | =end original |
| 8066 | 5069 | |
| 8067 | EXPR が省略されると、 | |
| 5070 | EXPR が省略されると、C<$_>を使います。 | |
| 8068 | 5071 | |
| 8069 | =begin original | |
| 8070 | ||
| 8071 | What gets returned depends on several factors: | |
| 8072 | ||
| 8073 | =end original | |
| 8074 | ||
| 8075 | 返り値として得られるものは色々な要素に依存します: | |
| 8076 | ||
| 8077 | =over | |
| 8078 | ||
| 8079 | =item If C<use bytes> is in effect: | |
| 8080 | ||
| 8081 | (C<use bytes> が有効の場合) | |
| 8082 | ||
| 8083 | =begin original | |
| 8084 | ||
| 8085 | The results follow ASCII rules. Only the characters C<A-Z> change, | |
| 8086 | to C<a-z> respectively. | |
| 8087 | ||
| 8088 | =end original | |
| 8089 | ||
| 8090 | 結果は ASCII の規則に従います。 | |
| 8091 | C<A-Z> のみが変換され、それぞれ C<a-z> になります。 | |
| 8092 | ||
| 8093 | =item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect: | |
| 8094 | ||
| 8095 | (それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合) | |
| 8096 | ||
| 8097 | =begin original | |
| 8098 | ||
| 8099 | Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode | |
| 8100 | rules for the remaining code points (this last can only happen if | |
| 8101 | the UTF8 flag is also set). See L<perllocale>. | |
| 8102 | ||
| 8103 | =end original | |
| 8104 | ||
| 8105 | 符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして | |
| 8106 | 残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも | |
| 8107 | 設定されている場合にのみ起こります)。 | |
| 8108 | L<perllocale> を参照してください。 | |
| 8109 | ||
| 8110 | =begin original | |
| 8111 | ||
| 8112 | Starting in v5.20, Perl uses full Unicode rules if the locale is | |
| 8113 | UTF-8. Otherwise, there is a deficiency in this scheme, which is that | |
| 8114 | case changes that cross the 255/256 | |
| 8115 | boundary are not well-defined. For example, the lower case of LATIN CAPITAL | |
| 8116 | LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII | |
| 8117 | platforms). But under C<use locale> (prior to v5.20 or not a UTF-8 | |
| 8118 | locale), the lower case of U+1E9E is | |
| 8119 | itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the | |
| 8120 | current locale, and Perl has no way of knowing if that character even | |
| 8121 | exists in the locale, much less what code point it is. Perl returns | |
| 8122 | a result that is above 255 (almost always the input character unchanged), | |
| 8123 | for all instances (and there aren't many) where the 255/256 boundary | |
| 8124 | would otherwise be crossed; and starting in v5.22, it raises a | |
| 8125 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning. | |
| 8126 | ||
| 8127 | =end original | |
| 8128 | ||
| 8129 | v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。 | |
| 8130 | さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は | |
| 8131 | 未定義であるという欠点があります。 | |
| 8132 | 例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は | |
| 8133 | (ASCII プラットフォームでは) U+00DF です。 | |
| 8134 | しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の | |
| 8135 | 小文字は自分自身です; なぜなら 0xDF は現在のロケールでは | |
| 8136 | LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が | |
| 8137 | 存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が | |
| 8138 | ないからです。 | |
| 8139 | Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については | |
| 8140 | (ほとんど常に入力文字を変更せずに)256 以上の値を返します; | |
| 8141 | そして v5.22 から | |
| 8142 | L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> | |
| 8143 | 警告を出力します。 | |
| 8144 | ||
| 8145 | =item Otherwise, If EXPR has the UTF8 flag set: | |
| 8146 | ||
| 8147 | (その他の場合で、EXPR に UTF8 フラグがセットされている場合) | |
| 8148 | ||
| 8149 | =begin original | |
| 8150 | ||
| 8151 | Unicode rules are used for the case change. | |
| 8152 | ||
| 8153 | =end original | |
| 8154 | ||
| 8155 | 大文字小文字変換には Unicode の規則が使われます。 | |
| 8156 | ||
| 8157 | =item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect: | |
| 8158 | ||
| 8159 | (それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合) | |
| 8160 | ||
| 8161 | =begin original | |
| 8162 | ||
| 8163 | Unicode rules are used for the case change. | |
| 8164 | ||
| 8165 | =end original | |
| 8166 | ||
| 8167 | 大文字小文字変換には Unicode の規則が使われます。 | |
| 8168 | ||
| 8169 | =item Otherwise: | |
| 8170 | ||
| 8171 | (それ以外の場合) | |
| 8172 | ||
| 8173 | =begin original | |
| 8174 | ||
| 8175 | ASCII rules are used for the case change. The lowercase of any character | |
| 8176 | outside the ASCII range is the character itself. | |
| 8177 | ||
| 8178 | =end original | |
| 8179 | ||
| 8180 | 大文字小文字変換には ASCII の規則が使われます。 | |
| 8181 | ASCII の範囲外の文字の「小文字」はその文字自身です。 | |
| 8182 | ||
| 8183 | =back | |
| 8184 | ||
| 8185 | 5072 | =item lcfirst EXPR |
| 8186 | X<lcfirst> X<lowercase> | |
| 8187 | 5073 | |
| 8188 | 5074 | =item lcfirst |
| 8189 | 5075 | |
| 8190 | =for Pod::Functions return a string with just the next letter in lower case | |
| 8191 | ||
| 8192 | 5076 | =begin original |
| 8193 | 5077 | |
| 8194 | Returns the value of EXPR with the first character lowercased. This | |
| 5078 | Returns the value of EXPR with the first character lowercased. This is | |
| 8195 | ||
| 5079 | the internal function implementing the C<\l> escape in double-quoted strings. | |
| 8196 | ||
| 5080 | Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>. | |
| 8197 | 5081 | |
| 8198 | 5082 | =end original |
| 8199 | 5083 | |
| 8200 | 5084 | 最初の文字だけを小文字にした、EXPR を返します。 |
| 8201 | 5085 | これは、ダブルクォート文字列における、C<\l> エスケープを |
| 8202 | 5086 | 実装する内部関数です。 |
| 5087 | C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。 | |
| 5088 | L<perllocale> を参照してください。 | |
| 8203 | 5089 | |
| 8204 | 5090 | =begin original |
| 8205 | 5091 | |
| 8206 | If EXPR is omitted, uses | |
| 5092 | If EXPR is omitted, uses C<$_>. | |
| 8207 | 5093 | |
| 8208 | 5094 | =end original |
| 8209 | 5095 | |
| 8210 | EXPR が省略されると、 | |
| 5096 | EXPR が省略されると、C<$_>を使います。 | |
| 8211 | 5097 | |
| 8212 | =begin original | |
| 8213 | ||
| 8214 | This function behaves the same way under various pragmas, such as in a locale, | |
| 8215 | as L<C<lc>|/lc EXPR> does. | |
| 8216 | ||
| 8217 | =end original | |
| 8218 | ||
| 8219 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
| 8220 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 8221 | ||
| 8222 | 5098 | =item length EXPR |
| 8223 | X<length> X<size> | |
| 8224 | 5099 | |
| 8225 | 5100 | =item length |
| 8226 | 5101 | |
| 8227 | =for Pod::Functions return the number of characters in a string | |
| 8228 | ||
| 8229 | 5102 | =begin original |
| 8230 | 5103 | |
| 8231 | Returns the length in | |
| 5104 | Returns the length in characters of the value of EXPR. If EXPR is | |
| 8232 | omitted, returns | |
| 5105 | omitted, returns length of C<$_>. Note that this cannot be used on | |
| 8233 | ||
| 5106 | an entire array or hash to find out how many elements these have. | |
| 5107 | For that, use C<scalar @array> and C<scalar keys %hash> respectively. | |
| 8234 | 5108 | |
| 8235 | 5109 | =end original |
| 8236 | 5110 | |
| 8237 | EXPR の値の | |
| 5111 | EXPR の値の文字の長さを返します。 | |
| 8238 | EXPR が省略されたときには、 | |
| 5112 | EXPR が省略されたときには、C<$_> の長さを返します。 | |
| 8239 | ||
| 5113 | これは配列やハッシュ全体に対してどれだけの要素を含んでいるかを | |
| 8240 | ||
| 8241 | =begin original | |
| 8242 | ||
| 8243 | This function cannot be used on an entire array or hash to find out how | |
| 8244 | many elements these have. For that, use C<scalar @array> and C<scalar keys | |
| 8245 | %hash>, respectively. | |
| 8246 | ||
| 8247 | =end original | |
| 8248 | ||
| 8249 | この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを | |
| 8250 | 5114 | 調べるためには使えません。 |
| 8251 | 5115 | そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を |
| 8252 | 5116 | 利用してください。 |
| 8253 | 5117 | |
| 8254 | =begin original | |
| 8255 | ||
| 8256 | Like all Perl character operations, L<C<length>|/length EXPR> normally | |
| 8257 | deals in logical | |
| 8258 | characters, not physical bytes. For how many bytes a string encoded as | |
| 8259 | UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))> | |
| 8260 | (you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>. | |
| 8261 | ||
| 8262 | =end original | |
| 8263 | ||
| 8264 | 全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な | |
| 8265 | バイトではなく論理文字を扱います。 | |
| 8266 | UTF-8 でエンコードされた文字列が何バイトかを知るには、 | |
| 8267 | C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に | |
| 8268 | C<use Encode> する必要があります)。 | |
| 8269 | L<Encode> と L<perlunicode> を参照してください。 | |
| 8270 | ||
| 8271 | =item __LINE__ | |
| 8272 | X<__LINE__> | |
| 8273 | ||
| 8274 | =for Pod::Functions the current source line number | |
| 8275 | ||
| 8276 | =begin original | |
| 8277 | ||
| 8278 | A special token that compiles to the current line number. | |
| 8279 | ||
| 8280 | =end original | |
| 8281 | ||
| 8282 | 現在の行番号にコンパイルされる特殊トークン。 | |
| 8283 | ||
| 8284 | 5118 | =item link OLDFILE,NEWFILE |
| 8285 | X<link> | |
| 8286 | 5119 | |
| 8287 | =for Pod::Functions create a hard link in the filesystem | |
| 8288 | ||
| 8289 | 5120 | =begin original |
| 8290 | 5121 | |
| 8291 | 5122 | Creates a new filename linked to the old filename. Returns true for |
| 8292 | success, false otherwise. | |
| 5123 | success, false otherwise. | |
| 8293 | 5124 | |
| 8294 | 5125 | =end original |
| 8295 | 5126 | |
| 8296 | OLDFILE にリンクされた、新しいファイル NEWFILE を作 | |
| 5127 | OLDFILE にリンクされた、新しいファイル NEWFILE を作 | |
| 8297 | 成功時には | |
| 5128 | ります。 成功時には true を、失敗時には false を返します。 | |
| 8298 | 5129 | |
| 8299 | =begin original | |
| 8300 | ||
| 8301 | Portability issues: L<perlport/link>. | |
| 8302 | ||
| 8303 | =end original | |
| 8304 | ||
| 8305 | 移植性の問題: L<perlport/link>。 | |
| 8306 | ||
| 8307 | 5130 | =item listen SOCKET,QUEUESIZE |
| 8308 | X<listen> | |
| 8309 | 5131 | |
| 8310 | =for Pod::Functions register your socket as a server | |
| 8311 | ||
| 8312 | 5132 | =begin original |
| 8313 | 5133 | |
| 8314 | Does the same thing that the | |
| 5134 | Does the same thing that the listen system call does. Returns true if | |
| 8315 | it succeeded, false otherwise. See the example in | |
| 5135 | it succeeded, false otherwise. See the example in | |
| 8316 | 5136 | L<perlipc/"Sockets: Client/Server Communication">. |
| 8317 | 5137 | |
| 8318 | 5138 | =end original |
| 8319 | 5139 | |
| 8320 | ||
| 5140 | listen システムコールと同じことをします。成功時には真を返し、 | |
| 8321 | ||
| 5141 | 失敗時には偽を返します。 | |
| 8322 | L<perlipc/"Sockets: Client/Server Communication"> | |
| 5142 | L<perlipc/"Sockets: Client/Server Communication">の例を参照してください。 | |
| 8323 | 5143 | |
| 8324 | 5144 | =item local EXPR |
| 8325 | X<local> | |
| 8326 | 5145 | |
| 8327 | =for Pod::Functions create a temporary value for a global variable (dynamic scoping) | |
| 8328 | ||
| 8329 | 5146 | =begin original |
| 8330 | 5147 | |
| 8331 | You really probably want to be using | |
| 5148 | You really probably want to be using C<my> instead, because C<local> isn't | |
| 8332 | ||
| 5149 | what most people think of as "local". See | |
| 8333 | ||
| 5150 | L<perlsub/"Private Variables via my()"> for details. | |
| 8334 | 5151 | |
| 8335 | 5152 | =end original |
| 8336 | 5153 | |
| 8337 | あなたはが本当に望んでいるのは | |
| 5154 | あなたはが本当に望んでいるのは C<my> の方でしょう。 | |
| 8338 | ||
| 5155 | C<local> はほとんどの人々が「ローカル」と考えるものと違うからです。 | |
| 8339 | ||
| 5156 | 詳細はL<perlsub/"Private Variables | |
| 8340 | ||
| 5157 | via my()">を参照してください。 | |
| 8341 | 5158 | |
| 8342 | 5159 | =begin original |
| 8343 | 5160 | |
| 8344 | 5161 | A local modifies the listed variables to be local to the enclosing |
| 8345 | 5162 | block, file, or eval. If more than one value is listed, the list must |
| 8346 | 5163 | be placed in parentheses. See L<perlsub/"Temporary Values via local()"> |
| 8347 | 5164 | for details, including issues with tied arrays and hashes. |
| 8348 | 5165 | |
| 8349 | 5166 | =end original |
| 8350 | 5167 | |
| 8351 | 5168 | "local" はリストアップされた変数を、囲っているブロック、 |
| 8352 | 5169 | ファイル、eval の中で、ローカルなものにします。 |
| 8353 | 複数の値を指定する場合は、リストは | |
| 5170 | 複数の値を指定する場合は、リストは括弧でくくらなければなりません。 | |
| 8354 | 5171 | tie した配列とハッシュに関する事項を含む詳細については |
| 8355 | 5172 | L<perlsub/"Temporary Values via local()"> を参照してください。 |
| 8356 | 5173 | |
| 8357 | =begin original | |
| 8358 | ||
| 8359 | The C<delete local EXPR> construct can also be used to localize the deletion | |
| 8360 | of array/hash elements to the current block. | |
| 8361 | See L<perlsub/"Localized deletion of elements of composite types">. | |
| 8362 | ||
| 8363 | =end original | |
| 8364 | ||
| 8365 | C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の | |
| 8366 | ブロックにローカル化するためにも使われていました。 | |
| 8367 | L<perlsub/"Localized deletion of elements of composite types"> を | |
| 8368 | 参照してください。 | |
| 8369 | ||
| 8370 | 5174 | =item localtime EXPR |
| 8371 | X<localtime> X<ctime> | |
| 8372 | 5175 | |
| 8373 | =item localtime | |
| 8374 | ||
| 8375 | =for Pod::Functions convert UNIX time into record or string using local time | |
| 8376 | ||
| 8377 | 5176 | =begin original |
| 8378 | 5177 | |
| 8379 | 5178 | Converts a time as returned by the time function to a 9-element list |
| 8380 | 5179 | with the time analyzed for the local time zone. Typically used as |
| 8381 | 5180 | follows: |
| 8382 | 5181 | |
| 8383 | 5182 | =end original |
| 8384 | 5183 | |
| 8385 | 5184 | time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、 |
| 8386 | 5185 | 9 要素の配列に変換します。 |
| 8387 | ||
| 5186 | 通常は、以下のようにして使用します。 | |
| 8388 | 5187 | |
| 8389 | # | |
| 5188 | # 0 1 2 3 4 5 6 7 8 | |
| 8390 | | |
| 5189 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = | |
| 8391 | ||
| 5190 | localtime(time); | |
| 8392 | 5191 | |
| 8393 | 5192 | =begin original |
| 8394 | 5193 | |
| 8395 | All list elements are numeric and come straight out of the C `struct | |
| 5194 | All list elements are numeric, and come straight out of the C `struct | |
| 8396 | tm'. | |
| 5195 | tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the | |
| 8397 | ||
| 5196 | specified time. $mday is the day of the month, and $mon is the month | |
| 5197 | itself, in the range C<0..11> with 0 indicating January and 11 | |
| 5198 | indicating December. $year is the number of years since 1900. That | |
| 5199 | is, $year is C<123> in year 2023. $wday is the day of the week, with | |
| 5200 | 0 indicating Sunday and 3 indicating Wednesday. $yday is the day of | |
| 5201 | the year, in the range C<0..364> (or C<0..365> in leap years.) $isdst | |
| 5202 | is true if the specified time occurs during daylight savings time, | |
| 5203 | false otherwise. | |
| 8398 | 5204 | |
| 8399 | 5205 | =end original |
| 8400 | 5206 | |
| 8401 | すべてのリスト要素は数値で、C の `struct tm' 構造体から | |
| 5207 | すべてのリスト要素は数値で、C の `struct tm' 構造体から | |
| 8402 | 5208 | 直接持ってきます。 |
| 8403 | ||
| 5209 | $sec, $min, $hour は指定された時刻の秒、分、時です。 | |
| 5210 | $mday は月の何日目か、$mon は月の値です。 | |
| 5211 | 月の値は C<0..11> で、0 が 1 月、11 が 12 月です。 | |
| 5212 | $year は 1900 年からの年数です。 | |
| 5213 | つまり、$year が C<123> なら 2023 年です。 | |
| 5214 | $wday は曜日で、0 が日曜日、3 が水曜日です。 | |
| 5215 | $yday はその年の何日目かで、C<0..364> の値を取ります | |
| 5216 | (うるう年は C<0..365> です)。 | |
| 5217 | $isdst は指定された時刻が夏時間の場合は真、そうでなければ偽です。 | |
| 8404 | 5218 | |
| 8405 | 5219 | =begin original |
| 8406 | 5220 | |
| 8407 | ||
| 5221 | Note that the $year element is I<not> simply the last two digits of | |
| 8408 | the ra | |
| 5222 | the year. If you assume it is, then you create non-Y2K-compliant | |
| 8409 | ||
| 5223 | programs--and you wouldn't want to do that, would you? | |
| 8410 | 5224 | |
| 8411 | 5225 | =end original |
| 8412 | 5226 | |
| 8413 | ||
| 5227 | $year 要素が単に西暦の下 2 桁を表している I<のではない> ことに | |
| 8414 | ||
| 5228 | 注意してください。これを仮定すると、Y2K 問題を含んだプログラムを | |
| 8415 | こ | |
| 5229 | 作ることになります。それはお望みじゃないでしょう? | |
| 8416 | 5230 | |
| 8417 | my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |
| 8418 | print "$abbr[$mon] $mday"; | |
| 8419 | # $mon=9, $mday=18 gives "Oct 18" | |
| 8420 | ||
| 8421 | 5231 | =begin original |
| 8422 | 5232 | |
| 8423 | ||
| 5233 | The proper way to get a complete 4-digit year is simply: | |
| 8424 | year write: | |
| 8425 | 5234 | |
| 8426 | 5235 | =end original |
| 8427 | 5236 | |
| 8428 | ||
| 5237 | 完全な 4 桁の西暦を得るには単に以下のようにしてください: | |
| 8429 | 4 桁の年を得るには以下のようにします: | |
| 8430 | 5238 | |
| 8431 | ||
| 5239 | $year += 1900; | |
| 8432 | 5240 | |
| 8433 | 5241 | =begin original |
| 8434 | 5242 | |
| 8435 | ||
| 5243 | And to get the last two digits of the year (e.g., '01' in 2001) do: | |
| 8436 | 5244 | |
| 8437 | 5245 | =end original |
| 8438 | 5246 | |
| 8439 | 西暦の下 2 桁(2001 年では | |
| 5247 | そして西暦の下 2 桁(2001 年では '01')がほしい場合は以下のようにします: | |
| 8440 | 5248 | |
| 8441 | ||
| 5249 | $year = sprintf("%02d", $year % 100); | |
| 8442 | 5250 | |
| 8443 | 5251 | =begin original |
| 8444 | 5252 | |
| 8445 | ||
| 5253 | If EXPR is omitted, C<localtime()> uses the current time (C<localtime(time)>). | |
| 8446 | Wednesday. C<$yday> is the day of the year, in the range C<0..364> | |
| 8447 | (or C<0..365> in leap years.) | |
| 8448 | 5254 | |
| 8449 | 5255 | =end original |
| 8450 | 5256 | |
| 8451 | ||
| 5257 | EXPR が省略されると、localtime(time()) を行ないます。 | |
| 8452 | C<$yday> はその年の何日目かで、C<0..364> の値を取ります | |
| 8453 | (うるう年は C<0..365> です。) | |
| 8454 | 5258 | |
| 8455 | 5259 | =begin original |
| 8456 | 5260 | |
| 8457 | ||
| 5261 | In scalar context, C<localtime()> returns the ctime(3) value: | |
| 8458 | Time, false otherwise. | |
| 8459 | 5262 | |
| 8460 | 5263 | =end original |
| 8461 | 5264 | |
| 8462 | ||
| 5265 | スカラコンテキストでは、ctime(3) の値を返します: | |
| 8463 | 5266 | |
| 8464 | ||
| 5267 | $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" | |
| 8465 | 5268 | |
| 8466 | If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current | |
| 8467 | time (as returned by L<C<time>|/time>). | |
| 8468 | ||
| 8469 | =end original | |
| 8470 | ||
| 8471 | EXPR が省略されると、L<C<localtime>|/localtime EXPR> は | |
| 8472 | (L<C<time>|/time> によって返される) 現在時刻を使います。 | |
| 8473 | ||
| 8474 | 5269 | =begin original |
| 8475 | 5270 | |
| 8476 | ||
| 5271 | This scalar value is B<not> locale dependent, see L<perllocale>, but | |
| 8477 | ||
| 5272 | instead a Perl builtin. Also see the C<Time::Local> module | |
| 5273 | (to convert the second, minutes, hours, ... back to seconds since the | |
| 5274 | stroke of midnight the 1st of January 1970, the value returned by | |
| 5275 | time()), and the strftime(3) and mktime(3) functions available via the | |
| 5276 | POSIX module. To get somewhat similar but locale dependent date | |
| 5277 | strings, set up your locale environment variables appropriately | |
| 5278 | (please see L<perllocale>) and try for example: | |
| 8478 | 5279 | |
| 8479 | 5280 | =end original |
| 8480 | 5281 | |
| 8481 | スカラ | |
| 5282 | スカラ値はロケール依存 B<ではなく>、Perl の組み込みの値です | |
| 8482 | ||
| 5283 | (L<perllocale> を参照してください)。 | |
| 5284 | また、(秒、分、時…の形から、time() が返す値である | |
| 8484 | | |
| 5285 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール | |
| 5286 | 及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も | |
| 8486 | =begin original | |
| 8487 | ||
| 8488 | The format of this scalar value is B<not> locale-dependent but built | |
| 8489 | into Perl. For GMT instead of local time use the | |
| 8490 | L<C<gmtime>|/gmtime EXPR> builtin. See also the | |
| 8491 | L<C<Time::Local>|Time::Local> module (for converting seconds, minutes, | |
| 8492 | hours, and such back to the integer value returned by L<C<time>|/time>), | |
| 8493 | and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and | |
| 8494 | L<C<mktime>|POSIX/C<mktime>> functions. | |
| 8495 | ||
| 8496 | =end original | |
| 8497 | ||
| 8498 | このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。 | |
| 8499 | ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み | |
| 8500 | 関数を使ってください。 | |
| 8501 | また、(秒、分、時などの形から、L<C<time>|/time> が返す値である | |
| 8502 | 1970 年 1 月 1 日の真夜中からの秒数に変換する) | |
| 8503 | L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される | |
| 8504 | L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も | |
| 8505 | 5287 | 参照してください。 |
| 8506 | ||
| 8507 | =begin original | |
| 8508 | ||
| 8509 | To get somewhat similar but locale-dependent date strings, set up your | |
| 8510 | locale environment variables appropriately (please see L<perllocale>) and | |
| 8511 | try for example: | |
| 8512 | ||
| 8513 | =end original | |
| 8514 | ||
| 8515 | 5288 | 似たような、しかしロケール依存の日付文字列がほしい場合は、 |
| 8516 | 5289 | ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、 |
| 8517 | 5290 | 以下の例を試してください: |
| 8518 | 5291 | |
| 8519 | 5292 | use POSIX qw(strftime); |
| 8520 | | |
| 5293 | $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; | |
| 8521 | # or for GMT formatted appropriately for your locale: | |
| 8522 | my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime; | |
| 8523 | 5294 | |
| 8524 | 5295 | =begin original |
| 8525 | 5296 | |
| 8526 | Note that C<%a> and C<%b>, the short forms of the day of the week | |
| 5297 | Note that the C<%a> and C<%b>, the short forms of the day of the week | |
| 8527 | 5298 | and the month of the year, may not necessarily be three characters wide. |
| 8528 | 5299 | |
| 8529 | 5300 | =end original |
| 8530 | 5301 | |
| 8531 | 5302 | 曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに |
| 8532 | 5303 | 注意してください。 |
| 8533 | 5304 | |
| 8534 | = | |
| 5305 | =item lock | |
| 8535 | 5306 | |
| 8536 | ||
| 5307 | lock I<THING> | |
| 8537 | by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and | |
| 8538 | L<C<localtime>|/localtime EXPR> functions, respectively. | |
| 8539 | 5308 | |
| 8540 | =end original | |
| 8541 | ||
| 8542 | L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ | |
| 8543 | L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、 | |
| 8544 | 名前でアクセスする機構を提供する便利なモジュールです。 | |
| 8545 | ||
| 8546 | 5309 | =begin original |
| 8547 | 5310 | |
| 8548 | ||
| 5311 | This function places an advisory lock on a variable, subroutine, | |
| 8549 | ||
| 5312 | or referenced object contained in I<THING> until the lock goes out | |
| 5313 | of scope. This is a built-in function only if your version of Perl | |
| 5314 | was built with threading enabled, and if you've said C<use Threads>. | |
| 5315 | Otherwise a user-defined function by this name will be called. See | |
| 5316 | L<Thread>. | |
| 8550 | 5317 | |
| 8551 | 5318 | =end original |
| 8552 | 5319 | |
| 8553 | ||
| 5320 | この関数は I<THING> が含む変数、サブルーチン、リファレンスされた | |
| 8554 | ||
| 5321 | オブジェクトに、スコープから出るまでアドバイサリロックを掛けます. | |
| 5322 | これはスレッドを有効にしてビルドされた Perl で、かつ C<use Threads> した | |
| 5323 | 場合にのみ組み込み関数となります。 | |
| 5324 | それ以外の場合はこの名前をもつユーザーが定義した関数が呼び出されます。 | |
| 5325 | L<Thread> を参照してください。 | |
| 8555 | 5326 | |
| 8556 | =begin original | |
| 8557 | ||
| 8558 | Portability issues: L<perlport/localtime>. | |
| 8559 | ||
| 8560 | =end original | |
| 8561 | ||
| 8562 | 移植性の問題: L<perlport/localtime>。 | |
| 8563 | ||
| 8564 | =item lock THING | |
| 8565 | X<lock> | |
| 8566 | ||
| 8567 | =for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method | |
| 8568 | ||
| 8569 | =begin original | |
| 8570 | ||
| 8571 | This function places an advisory lock on a shared variable or referenced | |
| 8572 | object contained in I<THING> until the lock goes out of scope. | |
| 8573 | ||
| 8574 | =end original | |
| 8575 | ||
| 8576 | この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、 | |
| 8577 | スコープから出るまでアドバイサリロックを掛けます. | |
| 8578 | ||
| 8579 | =begin original | |
| 8580 | ||
| 8581 | The value returned is the scalar itself, if the argument is a scalar, or a | |
| 8582 | reference, if the argument is a hash, array or subroutine. | |
| 8583 | ||
| 8584 | =end original | |
| 8585 | ||
| 8586 | 返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、 | |
| 8587 | サブルーチンならリファレンスです。 | |
| 8588 | ||
| 8589 | =begin original | |
| 8590 | ||
| 8591 | L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've | |
| 8592 | defined a function | |
| 8593 | by this name (before any calls to it), that function will be called | |
| 8594 | instead. If you are not under C<use threads::shared> this does nothing. | |
| 8595 | See L<threads::shared>. | |
| 8596 | ||
| 8597 | =end original | |
| 8598 | ||
| 8599 | L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に) | |
| 8600 | この名前で関数を定義すると、定義された関数の方が呼び出されます。 | |
| 8601 | C<use threads::shared> の影響下でない場合は、これは何もしません。 | |
| 8602 | L<threads::shared> を参照してください。 | |
| 8603 | ||
| 8604 | 5327 | =item log EXPR |
| 8605 | X<log> X<logarithm> X<e> X<ln> X<base> | |
| 8606 | 5328 | |
| 8607 | 5329 | =item log |
| 8608 | 5330 | |
| 8609 | =for Pod::Functions retrieve the natural logarithm for a number | |
| 8610 | ||
| 8611 | 5331 | =begin original |
| 8612 | 5332 | |
| 8613 | 5333 | Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted, |
| 8614 | returns | |
| 5334 | returns log of C<$_>. To get the log of another base, use basic algebra: | |
| 8615 | log of another base, use basic algebra: | |
| 8616 | 5335 | The base-N log of a number is equal to the natural log of that number |
| 8617 | 5336 | divided by the natural log of N. For example: |
| 8618 | 5337 | |
| 8619 | 5338 | =end original |
| 8620 | 5339 | |
| 8621 | 5340 | EXPR の (I<e> を底とする) 自然対数を返します。 |
| 8622 | EXPR が省略されると、 | |
| 5341 | EXPR が省略されると、C<$_> の対数を返します。 | |
| 8623 | 5342 | 底の異なる対数を求めるためには、基礎代数を利用してください: |
| 8624 | 5343 | ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。 |
| 8625 | 例 | |
| 5344 | 例: | |
| 8626 | 5345 | |
| 8627 | 5346 | sub log10 { |
| 8628 | ||
| 5347 | my $n = shift; | |
| 8629 | ||
| 5348 | return log($n)/log(10); | |
| 8630 | } | |
| 5349 | } | |
| 8631 | 5350 | |
| 8632 | 5351 | =begin original |
| 8633 | 5352 | |
| 8634 | See also L< | |
| 5353 | See also L</exp> for the inverse operation. | |
| 8635 | 5354 | |
| 8636 | 5355 | =end original |
| 8637 | 5356 | |
| 8638 | 逆操作については L< | |
| 5357 | 逆操作については L</exp> を参照して下さい。 | |
| 8639 | 5358 | |
| 8640 | 5359 | =item lstat FILEHANDLE |
| 8641 | X<lstat> | |
| 8642 | 5360 | |
| 8643 | 5361 | =item lstat EXPR |
| 8644 | 5362 | |
| 8645 | =item lstat DIRHANDLE | |
| 8646 | ||
| 8647 | 5363 | =item lstat |
| 8648 | 5364 | |
| 8649 | =for Pod::Functions stat a symbolic link | |
| 8650 | ||
| 8651 | 5365 | =begin original |
| 8652 | 5366 | |
| 8653 | Does the same thing as the | |
| 5367 | Does the same thing as the C<stat> function (including setting the | |
| 8654 | ||
| 5368 | special C<_> filehandle) but stats a symbolic link instead of the file | |
| 8655 | ||
| 5369 | the symbolic link points to. If symbolic links are unimplemented on | |
| 8656 | ||
| 5370 | your system, a normal C<stat> is done. | |
| 8657 | is done. For much more detailed information, please see the | |
| 8658 | documentation for L<C<stat>|/stat FILEHANDLE>. | |
| 8659 | 5371 | |
| 8660 | 5372 | =end original |
| 8661 | 5373 | |
| 8662 | 5374 | (特別なファイルハンドルである C<_> の設定を含めて) |
| 8663 | ||
| 5375 | C<stat> 関数と同じことをしますが、シンボリックリンクが | |
| 8664 | 5376 | 指しているファイルではなく、シンボリックリンク自体の stat をとります。 |
| 8665 | シンボリックリンクがシステムに実装されていないと、通常の | |
| 5377 | シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。 | |
| 8666 | L<C<stat>|/stat FILEHANDLE> が行なわれます。 | |
| 8667 | さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を | |
| 8668 | 参照してください。 | |
| 8669 | 5378 | |
| 8670 | 5379 | =begin original |
| 8671 | 5380 | |
| 8672 | If EXPR is omitted, stats | |
| 5381 | If EXPR is omitted, stats C<$_>. | |
| 8673 | 5382 | |
| 8674 | 5383 | =end original |
| 8675 | 5384 | |
| 8676 | EXPR が省略されると、 | |
| 5385 | EXPR が省略されると、C<$_> の stat をとります。 | |
| 8677 | 5386 | |
| 8678 | =begin original | |
| 8679 | ||
| 8680 | Portability issues: L<perlport/lstat>. | |
| 8681 | ||
| 8682 | =end original | |
| 8683 | ||
| 8684 | 移植性の問題: L<perlport/lstat>。 | |
| 8685 | ||
| 8686 | 5387 | =item m// |
| 8687 | 5388 | |
| 8688 | =for Pod::Functions match a string with a regular expression pattern | |
| 8689 | ||
| 8690 | 5389 | =begin original |
| 8691 | 5390 | |
| 8692 | The match operator. See L<perlop | |
| 5391 | The match operator. See L<perlop>. | |
| 8693 | 5392 | |
| 8694 | 5393 | =end original |
| 8695 | 5394 | |
| 8696 | 5395 | マッチ演算子です。 |
| 8697 | L<perlop | |
| 5396 | L<perlop> を参照してください。 | |
| 8698 | 5397 | |
| 8699 | 5398 | =item map BLOCK LIST |
| 8700 | X<map> | |
| 8701 | 5399 | |
| 8702 | 5400 | =item map EXPR,LIST |
| 8703 | 5401 | |
| 8704 | =for Pod::Functions apply a change to a list to get back a new list with the changes | |
| 8705 | ||
| 8706 | 5402 | =begin original |
| 8707 | 5403 | |
| 8708 | 5404 | Evaluates the BLOCK or EXPR for each element of LIST (locally setting |
| 8709 | ||
| 5405 | C<$_> to each element) and returns the list value composed of the | |
| 8710 | each such evaluation. | |
| 5406 | results of each such evaluation. In scalar context, returns the | |
| 8711 | ||
| 5407 | total number of elements so generated. Evaluates BLOCK or EXPR in | |
| 8712 | list | |
| 5408 | list context, so each element of LIST may produce zero, one, or | |
| 8713 | ||
| 5409 | more elements in the returned value. | |
| 8714 | 5410 | |
| 8715 | 5411 | =end original |
| 8716 | 5412 | |
| 8717 | 5413 | LIST の個々の要素に対して、BLOCK か EXPR を評価し |
| 8718 | ( | |
| 5414 | (C<$_> は、ローカルに個々の要素が設定されます) 、 | |
| 8719 | それぞれの評価結果からなるリスト | |
| 5415 | それぞれの評価結果からなるリスト値が返されます。 | |
| 8720 | LIST の個々の要素によって作られる、生成されたリストの要素数は、 | |
| 8721 | 0 個の場合もあれば、複数の場合もあるので、 | |
| 8722 | 生成されたリストの要素数は LIST の要素数と異なるかも知れません。 | |
| 8723 | 5416 | スカラコンテキストでは、生成された要素の数を返します。 |
| 8724 | リストコンテキストで | |
| 5417 | BLOCK や EXPR をリストコンテキストで評価しますので、LIST の | |
| 5418 | 個々の要素によって作られる、返り値であるリストの要素数は、 | |
| 5419 | 0 個の場合もあれば、複数の場合もあります。 | |
| 8725 | 5420 | |
| 8726 | | |
| 5421 | @chars = map(chr, @nums); | |
| 8727 | 5422 | |
| 8728 | 5423 | =begin original |
| 8729 | 5424 | |
| 8730 | translates a list of numbers to the corresponding characters. | |
| 5425 | translates a list of numbers to the corresponding characters. And | |
| 8731 | 5426 | |
| 8732 | 5427 | =end original |
| 8733 | 5428 | |
| 8734 | は、数のリストを対応する文字に変換します。 | |
| 5429 | は、数のリストを対応する文字に変換します。また、 | |
| 8735 | 5430 | |
| 8736 | | |
| 5431 | %hash = map { getkey($_) => $_ } @array; | |
| 8737 | 5432 | |
| 8738 | 5433 | =begin original |
| 8739 | 5434 | |
| 8740 | translates a list of numbers to their squared values. | |
| 8741 | ||
| 8742 | =end original | |
| 8743 | ||
| 8744 | これは数値のリストを、その 2 乗に変換します。 | |
| 8745 | ||
| 8746 | my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers; | |
| 8747 | ||
| 8748 | =begin original | |
| 8749 | ||
| 8750 | shows that number of returned elements can differ from the number of | |
| 8751 | input elements. To omit an element, return an empty list (). | |
| 8752 | This could also be achieved by writing | |
| 8753 | ||
| 8754 | =end original | |
| 8755 | ||
| 8756 | のように、返された要素の数が入力要素の数と異なる場合もあります。 | |
| 8757 | 要素を省略するには、空リスト () を返します。 | |
| 8758 | これは以下のように書くことでも達成できて | |
| 8759 | ||
| 8760 | my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers; | |
| 8761 | ||
| 8762 | =begin original | |
| 8763 | ||
| 8764 | which makes the intention more clear. | |
| 8765 | ||
| 8766 | =end original | |
| 8767 | ||
| 8768 | この方が目的がよりはっきりします。 | |
| 8769 | ||
| 8770 | =begin original | |
| 8771 | ||
| 8772 | Map always returns a list, which can be | |
| 8773 | assigned to a hash such that the elements | |
| 8774 | become key/value pairs. See L<perldata> for more details. | |
| 8775 | ||
| 8776 | =end original | |
| 8777 | ||
| 8778 | map は常にリストを返し、要素がキー/値の組になるようなハッシュに | |
| 8779 | 代入できます。 | |
| 8780 | さらなる詳細については L<perldata> を参照してください。 | |
| 8781 | ||
| 8782 | my %hash = map { get_a_key_for($_) => $_ } @array; | |
| 8783 | ||
| 8784 | =begin original | |
| 8785 | ||
| 8786 | 5435 | is just a funny way to write |
| 8787 | 5436 | |
| 8788 | 5437 | =end original |
| 8789 | 5438 | |
| 8790 | 5439 | は以下のものをちょっと変わった書き方で書いたものです。 |
| 8791 | 5440 | |
| 8792 | | |
| 5441 | %hash = (); | |
| 8793 | foreach (@array) { | |
| 5442 | foreach $_ (@array) { | |
| 8794 | ||
| 5443 | $hash{getkey($_)} = $_; | |
| 8795 | 5444 | } |
| 8796 | 5445 | |
| 8797 | 5446 | =begin original |
| 8798 | 5447 | |
| 8799 | Note that | |
| 5448 | Note that C<$_> is an alias to the list value, so it can be used to | |
| 8800 | ||
| 5449 | modify the elements of the LIST. While this is useful and supported, | |
| 8801 | ||
| 5450 | it can cause bizarre results if the elements of LIST are not variables. | |
| 8802 | ||
| 5451 | Using a regular C<foreach> loop for this purpose would be clearer in | |
| 8803 | ||
| 5452 | most cases. See also L</grep> for an array composed of those items of | |
| 8804 | ||
| 5453 | the original list for which the BLOCK or EXPR evaluates to true. | |
| 8805 | or EXPR evaluates to true. | |
| 8806 | 5454 | |
| 8807 | 5455 | =end original |
| 8808 | 5456 | |
| 8809 | ||
| 5457 | C<$_> は、LIST の値へのエイリアスですので、LIST の要素を | |
| 8810 | 5458 | 変更するために使うことができます。 |
| 8811 | 5459 | これは、便利でサポートされていますが、 |
| 8812 | 5460 | LIST の要素が変数でないと、おかしな結果になります。 |
| 8813 | 5461 | この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は |
| 8814 | 5462 | より明確になります。 |
| 8815 | BLOCK や EXPR が真になる元のリストの要素からなる | |
| 5463 | BLOCK や EXPR が真になる元のリストの要素からなる配列については、 | |
| 8816 | L< | |
| 5464 | L</grep> も参照してください。 | |
| 8817 | 5465 | |
| 8818 | 5466 | =begin original |
| 8819 | 5467 | |
| 8820 | 5468 | C<{> starts both hash references and blocks, so C<map { ...> could be either |
| 8821 | the start of map BLOCK LIST or map EXPR, LIST. | |
| 5469 | the start of map BLOCK LIST or map EXPR, LIST. Because perl doesn't look | |
| 8822 | ahead for the closing C<}> it has to take a guess at which it | |
| 5470 | ahead for the closing C<}> it has to take a guess at which its dealing with | |
| 8823 | based | |
| 5471 | based what it finds just after the C<{>. Usually it gets it right, but if it | |
| 8824 | C<{>. Usually it gets it right, but if it | |
| 8825 | 5472 | doesn't it won't realize something is wrong until it gets to the C<}> and |
| 8826 | encounters the missing (or unexpected) comma. | |
| 5473 | encounters the missing (or unexpected) comma. The syntax error will be | |
| 8827 | reported close to the C<}> | |
| 5474 | reported close to the C<}> but you'll need to change something near the C<{> | |
| 8828 | such as using a unary C<+> | |
| 5475 | such as using a unary C<+> to give perl some help: | |
| 8829 | 5476 | |
| 8830 | 5477 | =end original |
| 8831 | 5478 | |
| 8832 | 5479 | C<{> はハッシュリファレンスとブロックの両方の開始文字なので、 |
| 8833 | 5480 | C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。 |
| 8834 | ||
| 5481 | perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て | |
| 8835 | 5482 | どちらとして扱うかを推測します。 |
| 8836 | 5483 | 通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで |
| 8837 | 5484 | カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに |
| 8838 | 5485 | 気付きません。 |
| 8839 | C<}> の近くで文法エラーが出ますが、 | |
| 5486 | C<}> の近くで文法エラーが出ますが、perl を助けるために単項の C<+> を | |
| 8840 | ||
| 5487 | 使うというように、C<{> の近くの何かを変更する必要があります。 | |
| 8841 | 5488 | |
| 8842 | | |
| 5489 | %hash = map { "\L$_", 1 } @array # perl guesses EXPR. wrong | |
| 8843 | | |
| 5490 | %hash = map { +"\L$_", 1 } @array # perl guesses BLOCK. right | |
| 8844 | | |
| 5491 | %hash = map { ("\L$_", 1) } @array # this also works | |
| 8845 | | |
| 5492 | %hash = map { lc($_), 1 } @array # as does this. | |
| 8846 | | |
| 5493 | %hash = map +( lc($_), 1 ), @array # this is EXPR and works! | |
| 8847 | my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works! | |
| 8848 | 5494 | |
| 8849 | | |
| 5495 | %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) | |
| 8850 | 5496 | |
| 8851 | 5497 | =begin original |
| 8852 | 5498 | |
| 8853 | or to force an anon hash constructor use C<+{> | |
| 5499 | or to force an anon hash constructor use C<+{> | |
| 8854 | 5500 | |
| 8855 | 5501 | =end original |
| 8856 | 5502 | |
| 8857 | 5503 | または C<+{> を使って無名ハッシュコンストラクタを強制します: |
| 8858 | 5504 | |
| 8859 | | |
| 5505 | @hashes = map +{ lc($_), 1 }, @array # EXPR, so needs , at end | |
| 8860 | # comma at end | |
| 8861 | 5506 | |
| 8862 | 5507 | =begin original |
| 8863 | 5508 | |
| 8864 | ||
| 5509 | and you get list of anonymous hashes each with only 1 entry. | |
| 8865 | 5510 | |
| 8866 | 5511 | =end original |
| 8867 | 5512 | |
| 8868 | 5513 | こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。 |
| 8869 | 5514 | |
| 8870 | =item mkdir FILENAME,M | |
| 5515 | =item mkdir FILENAME,MASK | |
| 8871 | X<mkdir> X<md> X<directory, create> | |
| 8872 | 5516 | |
| 8873 | 5517 | =item mkdir FILENAME |
| 8874 | 5518 | |
| 8875 | =item mkdir | |
| 8876 | ||
| 8877 | =for Pod::Functions create a directory | |
| 8878 | ||
| 8879 | 5519 | =begin original |
| 8880 | 5520 | |
| 8881 | 5521 | Creates the directory specified by FILENAME, with permissions |
| 8882 | specified by M | |
| 5522 | specified by MASK (as modified by C<umask>). If it succeeds it | |
| 8883 | ||
| 5523 | returns true, otherwise it returns false and sets C<$!> (errno). | |
| 8884 | ||
| 5524 | If omitted, MASK defaults to 0777. | |
| 8885 | MODE defaults to 0777 if omitted, and FILENAME defaults | |
| 8886 | to L<C<$_>|perlvar/$_> if omitted. | |
| 8887 | 5525 | |
| 8888 | 5526 | =end original |
| 8889 | 5527 | |
| 8890 | FILENAME で指定したディレクトリを、M | |
| 5528 | FILENAME で指定したディレクトリを、MASK で指定した許可モード(を | |
| 8891 | ||
| 5529 | C<umask> で修正したもの) で作成します。 | |
| 8892 | 成功時には真を返し | |
| 5530 | 成功時には真を返し、失敗時には偽を返して C<$!> (errno) を設定します。 | |
| 8893 | ||
| 5531 | MASK を省略すると、0777 とみなします。 | |
| 8894 | MODE を省略すると、0777 とみなし、 | |
| 8895 | FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。 | |
| 8896 | 5532 | |
| 8897 | 5533 | =begin original |
| 8898 | 5534 | |
| 8899 | In general, it is better to create directories with | |
| 5535 | In general, it is better to create directories with permissive MASK, | |
| 8900 | and let the user modify that with their | |
| 5536 | and let the user modify that with their C<umask>, than it is to supply | |
| 8901 | is to | |
| 5537 | a restrictive MASK and give the user no way to be more permissive. | |
| 8902 | a restrictive MODE and give the user no way to be more permissive. | |
| 8903 | 5538 | The exceptions to this rule are when the file or directory should be |
| 8904 | kept private (mail files, for instance). The | |
| 5539 | kept private (mail files, for instance). The perlfunc(1) entry on | |
| 8905 | ||
| 5540 | C<umask> discusses the choice of MASK in more detail. | |
| 8906 | 5541 | |
| 8907 | 5542 | =end original |
| 8908 | 5543 | |
| 8909 | 一般的に、制限された M | |
| 5544 | 一般的に、制限された MASK を使ってユーザーがより寛容にする方法を | |
| 8910 | 与えないより、寛容な M | |
| 5545 | 与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で | |
| 8911 | ||
| 5546 | 修正するようにした方がよいです。 | |
| 8912 | 5547 | 例外は、(例えばメールファイルのような)プライベートに保つべきファイルや |
| 8913 | 5548 | ディレクトリを書く場合です。 |
| 8914 | ||
| 5549 | perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。 | |
| 8915 | 5550 | |
| 8916 | =begin original | |
| 8917 | ||
| 8918 | Note that according to the POSIX 1003.1-1996 the FILENAME may have any | |
| 8919 | number of trailing slashes. Some operating and filesystems do not get | |
| 8920 | this right, so Perl automatically removes all trailing slashes to keep | |
| 8921 | everyone happy. | |
| 8922 | ||
| 8923 | =end original | |
| 8924 | ||
| 8925 | POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを | |
| 8926 | つけることができます。 | |
| 8927 | このようには動かない OS やファイルシステムもあるので、Perl はみんなが | |
| 8928 | 幸せになれるように、自動的に末尾のスラッシュを削除します。 | |
| 8929 | ||
| 8930 | =begin original | |
| 8931 | ||
| 8932 | To recursively create a directory structure, look at | |
| 8933 | the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function | |
| 8934 | of the L<File::Path> module. | |
| 8935 | ||
| 8936 | =end original | |
| 8937 | ||
| 8938 | ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの | |
| 8939 | L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を | |
| 8940 | 参照してください。 | |
| 8941 | ||
| 8942 | 5551 | =item msgctl ID,CMD,ARG |
| 8943 | X<msgctl> | |
| 8944 | 5552 | |
| 8945 | =for Pod::Functions SysV IPC message control operations | |
| 8946 | ||
| 8947 | 5553 | =begin original |
| 8948 | 5554 | |
| 8949 | Calls the System V IPC function | |
| 5555 | Calls the System V IPC function msgctl(2). You'll probably have to say | |
| 8950 | 5556 | |
| 8951 | =end original | |
| 8952 | ||
| 8953 | System V IPC 関数 L<msgctl(2)> を呼び出します。 | |
| 8954 | 正しい定数定義を得るために、まず | |
| 8955 | ||
| 8956 | 5557 | use IPC::SysV; |
| 8957 | 5558 | |
| 8958 | =begin original | |
| 8959 | ||
| 8960 | 5559 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
| 8961 | then ARG must be a variable | |
| 5560 | then ARG must be a variable which will hold the returned C<msqid_ds> | |
| 8962 | structure. Returns like | |
| 5561 | structure. Returns like C<ioctl>: the undefined value for error, | |
| 8963 | ||
| 5562 | C<"0 but true"> for zero, or the actual return value otherwise. See also | |
| 8964 | ||
| 5563 | L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::Semaphore> documentation. | |
| 8965 | documentation for L<C<IPC::SysV>|IPC::SysV> and | |
| 8966 | L<C<IPC::Semaphore>|IPC::Semaphore>. | |
| 8967 | 5564 | |
| 8968 | 5565 | =end original |
| 8969 | 5566 | |
| 8970 | ||
| 5567 | System V IPC 関数 msgctl を呼び出します。正しい定数定義を得るために、まず | |
| 5568 | ||
| 5569 | use IPC::SysV; | |
| 5570 | ||
| 5571 | と宣言する必要があるでしょう。 | |
| 8971 | 5572 | CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を |
| 8972 | 5573 | 納める変数でなければなりません。 |
| 8973 | ||
| 5574 | C<ioctl> と同じように、エラー時には未定義値、 | |
| 8974 | ||
| 5575 | ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。 | |
| 8975 | ||
| 5576 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。 | |
| 8976 | L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>, | |
| 8977 | L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。 | |
| 8978 | 5577 | |
| 8979 | =begin original | |
| 8980 | ||
| 8981 | Portability issues: L<perlport/msgctl>. | |
| 8982 | ||
| 8983 | =end original | |
| 8984 | ||
| 8985 | 移植性の問題: L<perlport/msgctl>。 | |
| 8986 | ||
| 8987 | 5578 | =item msgget KEY,FLAGS |
| 8988 | X<msgget> | |
| 8989 | 5579 | |
| 8990 | =for Pod::Functions get SysV IPC message queue | |
| 8991 | ||
| 8992 | 5580 | =begin original |
| 8993 | 5581 | |
| 8994 | Calls the System V IPC function | |
| 5582 | Calls the System V IPC function msgget(2). Returns the message queue | |
| 8995 | id, or | |
| 5583 | id, or the undefined value if there is an error. See also | |
| 8996 | ||
| 5584 | L<perlipc/"SysV IPC"> and C<IPC::SysV> and C<IPC::Msg> documentation. | |
| 8997 | L<C<IPC::Msg>|IPC::Msg>. | |
| 8998 | 5585 | |
| 8999 | 5586 | =end original |
| 9000 | 5587 | |
| 9001 | System V IPC 関数 | |
| 5588 | System V IPC 関数 msgget を呼び出します。 | |
| 9002 | メッセージキューの ID か、エラー時には | |
| 5589 | メッセージキューの ID か、エラー時には未定義値を返します。 | |
| 9003 | L<perlipc/"SysV IPC"> | |
| 5590 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Msg> も参照してください。 | |
| 9004 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 9005 | 5591 | |
| 9006 | =begin original | |
| 9007 | ||
| 9008 | Portability issues: L<perlport/msgget>. | |
| 9009 | ||
| 9010 | =end original | |
| 9011 | ||
| 9012 | 移植性の問題: L<perlport/msgget>。 | |
| 9013 | ||
| 9014 | 5592 | =item msgrcv ID,VAR,SIZE,TYPE,FLAGS |
| 9015 | X<msgrcv> | |
| 9016 | 5593 | |
| 9017 | =for Pod::Functions receive a SysV IPC message from a message queue | |
| 9018 | ||
| 9019 | 5594 | =begin original |
| 9020 | 5595 | |
| 9021 | 5596 | Calls the System V IPC function msgrcv to receive a message from |
| 9022 | 5597 | message queue ID into variable VAR with a maximum message size of |
| 9023 | 5598 | SIZE. Note that when a message is received, the message type as a |
| 9024 | 5599 | native long integer will be the first thing in VAR, followed by the |
| 9025 | 5600 | actual message. This packing may be opened with C<unpack("l! a*")>. |
| 9026 | Taints the variable. Returns true if successful, false | |
| 5601 | Taints the variable. Returns true if successful, or false if there is | |
| 9027 | ||
| 5602 | an error. See also L<perlipc/"SysV IPC">, C<IPC::SysV>, and | |
| 9028 | ||
| 5603 | C<IPC::SysV::Msg> documentation. | |
| 9029 | 5604 | |
| 9030 | 5605 | =end original |
| 9031 | 5606 | |
| 9032 | 5607 | System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、 |
| 9033 | 5608 | 変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。 |
| 9034 | 5609 | メッセージが受信された時、ネイティブな long 整数のメッセージタイプが |
| 9035 | 5610 | VAR の先頭となり、実際のメッセージが続きます。 |
| 9036 | 5611 | このパッキングは C<unpack("l! a*")> で展開できます。 |
| 9037 | 5612 | 変数は汚染されます。 |
| 9038 | 成功時には真を、エラー時には偽を返します。 | |
| 5613 | 成功時には真を返し、エラー時には偽を返します。 | |
| 9039 | L<perlipc/"SysV IPC"> | |
| 5614 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Msg> も参照してください。 | |
| 9040 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 9041 | 5615 | |
| 9042 | =begin original | |
| 9043 | ||
| 9044 | Portability issues: L<perlport/msgrcv>. | |
| 9045 | ||
| 9046 | =end original | |
| 9047 | ||
| 9048 | 移植性の問題: L<perlport/msgrcv>。 | |
| 9049 | ||
| 9050 | 5616 | =item msgsnd ID,MSG,FLAGS |
| 9051 | X<msgsnd> | |
| 9052 | 5617 | |
| 9053 | =for Pod::Functions send a SysV IPC message to a message queue | |
| 9054 | ||
| 9055 | 5618 | =begin original |
| 9056 | 5619 | |
| 9057 | 5620 | Calls the System V IPC function msgsnd to send the message MSG to the |
| 9058 | 5621 | message queue ID. MSG must begin with the native long integer message |
| 9059 | type, be followed by the length of the actual message, and | |
| 5622 | type, and be followed by the length of the actual message, and finally | |
| 9060 | 5623 | the message itself. This kind of packing can be achieved with |
| 9061 | 5624 | C<pack("l! a*", $type, $message)>. Returns true if successful, |
| 9062 | false | |
| 5625 | or false if there is an error. See also C<IPC::SysV> | |
| 9063 | ||
| 5626 | and C<IPC::SysV::Msg> documentation. | |
| 9064 | 5627 | |
| 9065 | 5628 | =end original |
| 9066 | 5629 | |
| 9067 | 5630 | System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に |
| 9068 | 5631 | メッセージ MSG を送信します。 |
| 9069 | MSG の先頭は、ネイティブな | |
| 5632 | MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、 | |
| 9070 | 5633 | メッセージの長さ、メッセージ本体と続きます。 |
| 9071 | 5634 | これは、C<pack("l! a*", $type, $message)> として生成できます。 |
| 9072 | 5635 | 成功時には真を、エラー時には偽を返します。 |
| 9073 | ||
| 5636 | C<IPC::SysV> と C<IPC::SysV::Msg> も参照してください。 | |
| 9074 | L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。 | |
| 9075 | 5637 | |
| 9076 | = | |
| 5638 | =item my EXPR | |
| 9077 | 5639 | |
| 9078 | ||
| 5640 | =item my EXPR : ATTRIBUTES | |
| 9079 | 5641 | |
| 9080 | =end original | |
| 9081 | ||
| 9082 | 移植性の問題: L<perlport/msgsnd>。 | |
| 9083 | ||
| 9084 | =item my VARLIST | |
| 9085 | X<my> | |
| 9086 | ||
| 9087 | =item my TYPE VARLIST | |
| 9088 | ||
| 9089 | =item my VARLIST : ATTRS | |
| 9090 | ||
| 9091 | =item my TYPE VARLIST : ATTRS | |
| 9092 | ||
| 9093 | =for Pod::Functions declare and assign a local variable (lexical scoping) | |
| 9094 | ||
| 9095 | 5642 | =begin original |
| 9096 | 5643 | |
| 9097 | A | |
| 5644 | A C<my> declares the listed variables to be local (lexically) to the | |
| 9098 | ||
| 5645 | enclosing block, file, or C<eval>. If | |
| 9099 | more than one va | |
| 5646 | more than one value is listed, the list must be placed in parentheses. See | |
| 9100 | parentheses. | |
| 9101 | ||
| 9102 | =end original | |
| 9103 | ||
| 9104 | L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、 | |
| 9105 | L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。 | |
| 9106 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 | |
| 9107 | ||
| 9108 | =begin original | |
| 9109 | ||
| 9110 | The exact semantics and interface of TYPE and ATTRS are still | |
| 9111 | evolving. TYPE may be a bareword, a constant declared | |
| 9112 | with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It | |
| 9113 | is | |
| 9114 | currently bound to the use of the L<fields> pragma, | |
| 9115 | and attributes are handled using the L<attributes> pragma, or starting | |
| 9116 | from Perl 5.8.0 also via the L<Attribute::Handlers> module. See | |
| 9117 | 5647 | L<perlsub/"Private Variables via my()"> for details. |
| 9118 | 5648 | |
| 9119 | 5649 | =end original |
| 9120 | 5650 | |
| 9121 | ||
| 5651 | C<my> はリストアップされた変数を、囲っているブロック、ファイル、 | |
| 9122 | ||
| 5652 | C<eval> の中でローカルな (レキシカルな) ものにします。 | |
| 9123 | ||
| 5653 | 複数の値を並べる場合には、括弧で括る必要があります。 | |
| 9124 | ||
| 5654 | 詳しくはL<perlsub/"Private Variables via my()">を参照してください。 | |
| 9125 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
| 9126 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
| 9127 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
| 9128 | 5655 | |
| 9129 | =begin original | |
| 9130 | ||
| 9131 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
| 9132 | as a dummy placeholder, for example to skip assignment of initial | |
| 9133 | values: | |
| 9134 | ||
| 9135 | =end original | |
| 9136 | ||
| 9137 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
| 9138 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
| 9139 | ||
| 9140 | my ( undef, $min, $hour ) = localtime; | |
| 9141 | ||
| 9142 | 5656 | =item next LABEL |
| 9143 | X<next> X<continue> | |
| 9144 | 5657 | |
| 9145 | =item next EXPR | |
| 9146 | ||
| 9147 | 5658 | =item next |
| 9148 | 5659 | |
| 9149 | =for Pod::Functions iterate a block prematurely | |
| 9150 | ||
| 9151 | 5660 | =begin original |
| 9152 | 5661 | |
| 9153 | The | |
| 5662 | The C<next> command is like the C<continue> statement in C; it starts | |
| 9154 | ||
| 5663 | the next iteration of the loop: | |
| 9155 | 5664 | |
| 9156 | 5665 | =end original |
| 9157 | 5666 | |
| 9158 | ||
| 5667 | C<next> コマンドは、C での C<continue> 文のようなもので、 | |
| 9159 | 5668 | ループの次の繰り返しを開始します: |
| 9160 | 5669 | |
| 9161 | 5670 | LINE: while (<STDIN>) { |
| 9162 | ||
| 5671 | next LINE if /^#/; # discard comments | |
| 9163 | ||
| 5672 | #... | |
| 9164 | 5673 | } |
| 9165 | 5674 | |
| 9166 | 5675 | =begin original |
| 9167 | 5676 | |
| 9168 | Note that if there were a | |
| 5677 | Note that if there were a C<continue> block on the above, it would get | |
| 9169 | ||
| 5678 | executed even on discarded lines. If the LABEL is omitted, the command | |
| 9170 | e | |
| 5679 | refers to the innermost enclosing loop. | |
| 9171 | refers to the innermost enclosing loop. The C<next EXPR> form, available | |
| 9172 | as of Perl 5.18.0, allows a label name to be computed at run time, being | |
| 9173 | otherwise identical to C<next LABEL>. | |
| 9174 | 5680 | |
| 9175 | 5681 | =end original |
| 9176 | 5682 | |
| 9177 | ||
| 5683 | C<continue> ブロックが存在すれば、たとえ捨てられる行に | |
| 9178 | 5684 | あっても、それが実行されます。 |
| 9179 | LABEL が省略されると、コマンドは | |
| 5685 | LABEL が省略されると、このコマンドはもっとも内側のループを参照します。 | |
| 9180 | Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される | |
| 9181 | ラベル名が使えます; それ以外は C<next LABEL> と同一です。 | |
| 9182 | 5686 | |
| 9183 | 5687 | =begin original |
| 9184 | 5688 | |
| 9185 | ||
| 5689 | C<next> cannot be used to exit a block which returns a value such as | |
| 9186 | ||
| 5690 | C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit | |
| 9187 | ||
| 5691 | a grep() or map() operation. | |
| 9188 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 9189 | operation. | |
| 9190 | 5692 | |
| 9191 | 5693 | =end original |
| 9192 | 5694 | |
| 9193 | ||
| 5695 | C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
| 9194 | ||
| 5696 | ブロックから抜けるのには使えません。 | |
| 9195 | ||
| 5697 | また、grep() や map() 操作から抜けるのに使うべきではありません。 | |
| 9196 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 9197 | 使うべきではありません。 | |
| 9198 | 5698 | |
| 9199 | 5699 | =begin original |
| 9200 | 5700 | |
| 9201 | 5701 | Note that a block by itself is semantically identical to a loop |
| 9202 | that executes once. Thus | |
| 5702 | that executes once. Thus C<next> will exit such a block early. | |
| 9203 | early. | |
| 9204 | 5703 | |
| 9205 | 5704 | =end original |
| 9206 | 5705 | |
| 9207 | 5706 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
| 9208 | 5707 | 注意してください。 |
| 9209 | 従って、 | |
| 5708 | 従って、C<next> はそのようなブロックから早く抜けるのに使えます。 | |
| 9210 | 5709 | |
| 9211 | 5710 | =begin original |
| 9212 | 5711 | |
| 9213 | See also L< | |
| 5712 | See also L</continue> for an illustration of how C<last>, C<next>, and | |
| 9214 | ||
| 5713 | C<redo> work. | |
| 9215 | L<C<redo>|/redo LABEL> work. | |
| 9216 | 5714 | |
| 9217 | 5715 | =end original |
| 9218 | 5716 | |
| 9219 | ||
| 5717 | C<last>, C<next>, C<redo> がどのように働くかについては | |
| 9220 | ||
| 5718 | L</continue> も参照して下さい。 | |
| 9221 | 5719 | |
| 9222 | = | |
| 5720 | =item no Module LIST | |
| 9223 | 5721 | |
| 9224 | Unlike most named operators, this has the same precedence as assignment. | |
| 9225 | It is also exempt from the looks-like-a-function rule, so | |
| 9226 | C<next ("foo")."bar"> will cause "bar" to be part of the argument to | |
| 9227 | L<C<next>|/next LABEL>. | |
| 9228 | ||
| 9229 | =end original | |
| 9230 | ||
| 9231 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
| 9232 | また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と | |
| 9233 | すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。 | |
| 9234 | ||
| 9235 | =item no MODULE VERSION LIST | |
| 9236 | X<no declarations> | |
| 9237 | X<unimporting> | |
| 9238 | ||
| 9239 | =item no MODULE VERSION | |
| 9240 | ||
| 9241 | =item no MODULE LIST | |
| 9242 | ||
| 9243 | =item no MODULE | |
| 9244 | ||
| 9245 | =item no VERSION | |
| 9246 | ||
| 9247 | =for Pod::Functions unimport some module symbols or semantics at compile time | |
| 9248 | ||
| 9249 | 5722 | =begin original |
| 9250 | 5723 | |
| 9251 | See the L< | |
| 5724 | See the L</use> function, which C<no> is the opposite of. | |
| 9252 | L<C<no>|/no MODULE VERSION LIST> is the opposite. | |
| 9253 | 5725 | |
| 9254 | 5726 | =end original |
| 9255 | 5727 | |
| 9256 | L< | |
| 5728 | L</use> 関数を参照してください。C<no> は、その逆を行なうものです。 | |
| 9257 | L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。 | |
| 9258 | 5729 | |
| 9259 | 5730 | =item oct EXPR |
| 9260 | X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin> | |
| 9261 | 5731 | |
| 9262 | 5732 | =item oct |
| 9263 | 5733 | |
| 9264 | =for Pod::Functions convert a string to an octal number | |
| 9265 | ||
| 9266 | 5734 | =begin original |
| 9267 | 5735 | |
| 9268 | 5736 | Interprets EXPR as an octal string and returns the corresponding |
| 9269 | 5737 | value. (If EXPR happens to start off with C<0x>, interprets it as a |
| 9270 | 5738 | hex string. If EXPR starts off with C<0b>, it is interpreted as a |
| 9271 | binary string. | |
| 5739 | binary string.) The following will handle decimal, binary, octal, and | |
| 9272 | ||
| 5740 | hex in the standard Perl or C notation: | |
| 9273 | Perl notation: | |
| 9274 | 5741 | |
| 9275 | 5742 | =end original |
| 9276 | 5743 | |
| 9277 | 5744 | EXPR を 8 進数文字列と解釈して、対応する値を返します。 |
| 9278 | 5745 | (EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。 |
| 9279 | EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。 | |
| 5746 | EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。) | |
| 9280 | ||
| 5747 | 以下の例は、標準的な Perl や C の記法での | |
| 9281 | 以下の例は、標準的な Perl の記法での | |
| 9282 | 5748 | 10 進数、2 進数、8 進数、16 進数を扱います: |
| 9283 | 5749 | |
| 9284 | 5750 | $val = oct($val) if $val =~ /^0/; |
| 9285 | 5751 | |
| 9286 | 5752 | =begin original |
| 9287 | 5753 | |
| 9288 | If EXPR is omitted, uses | |
| 5754 | If EXPR is omitted, uses C<$_>. To go the other way (produce a number | |
| 9289 | ||
| 5755 | in octal), use sprintf() or printf(): | |
| 9290 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST>: | |
| 9291 | 5756 | |
| 9292 | 5757 | =end original |
| 9293 | 5758 | |
| 9294 | EXPR | |
| 5759 | EXPR を省略すると、C<$_> を使用します。 | |
| 9295 | (8 進数を扱う)その他の方法 | |
| 5760 | (8 進数を扱う)その他の方法としては sprintf() または printf()があります。 | |
| 9296 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります: | |
| 9297 | 5761 | |
| 9298 | | |
| 5762 | $perms = (stat("filename"))[2] & 07777; | |
| 9299 | | |
| 5763 | $oct_perms = sprintf "%lo", $perms; | |
| 9300 | 5764 | |
| 9301 | 5765 | =begin original |
| 9302 | 5766 | |
| 9303 | The | |
| 5767 | The oct() function is commonly used when a string such as C<644> needs | |
| 9304 | ||
| 5768 | to be converted into a file mode, for example. (Although perl will | |
| 9305 | to | |
| 5769 | automatically convert strings into numbers as needed, this automatic | |
| 9306 | ||
| 5770 | conversion assumes base 10.) | |
| 9307 | conversion assumes base 10. | |
| 9308 | 5771 | |
| 9309 | 5772 | =end original |
| 9310 | 5773 | |
| 9311 | ||
| 5774 | oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時に | |
| 9312 | ||
| 5775 | よく使います。 | |
| 9313 | Perl は必要に応じて自動的に文字列を数値に変換しますが、 | |
| 5776 | (Perl は必要に応じて自動的に文字列を数値に変換しますが、 | |
| 9314 | この自動変換は十進数を仮定します。 | |
| 5777 | この自動変換は十進数を仮定します。) | |
| 9315 | 5778 | |
| 9316 | = | |
| 5779 | =item open FILEHANDLE,MODE,LIST | |
| 9317 | 5780 | |
| 9318 | Leading white space is ignored without warning, as too are any trailing | |
| 9319 | non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles | |
| 9320 | non-negative integers, not negative integers or floating point). | |
| 9321 | ||
| 9322 | =end original | |
| 9323 | ||
| 9324 | 先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます | |
| 9325 | (L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。 | |
| 9326 | ||
| 9327 | 5781 | =item open FILEHANDLE,EXPR |
| 9328 | X<open> X<pipe> X<file, open> X<fopen> | |
| 9329 | 5782 | |
| 9330 | =item open FILEHANDLE,MODE,EXPR | |
| 9331 | ||
| 9332 | =item open FILEHANDLE,MODE,EXPR,LIST | |
| 9333 | ||
| 9334 | =item open FILEHANDLE,MODE,REFERENCE | |
| 9335 | ||
| 9336 | 5783 | =item open FILEHANDLE |
| 9337 | 5784 | |
| 9338 | =for Pod::Functions open a file, pipe, or descriptor | |
| 9339 | ||
| 9340 | 5785 | =begin original |
| 9341 | 5786 | |
| 9342 | 5787 | Opens the file whose filename is given by EXPR, and associates it with |
| 9343 | FILEHANDLE. | |
| 5788 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as the | |
| 5789 | name of the real filehandle wanted. (This is considered a symbolic | |
| 5790 | reference, so C<use strict 'refs'> should I<not> be in effect.) | |
| 9344 | 5791 | |
| 9345 | 5792 | =end original |
| 9346 | 5793 | |
| 9347 | EXPR で | |
| 5794 | EXPR でファイル名を指定するファイルをオープンして、 | |
| 5795 | FILEHANDLE に対応させます。 | |
| 5796 | FILEHANDLE が式のときには、その値が実際に使用するファイルハンドルの | |
| 5797 | 名前として使われます。 | |
| 5798 | (これはシンボリックリファレンスと考えられますので、 | |
| 5799 | C<use strict 'refs'> はI<効果がありません>。) | |
| 9348 | 5800 | |
| 9349 | 5801 | =begin original |
| 9350 | 5802 | |
| 9351 | ||
| 5803 | If EXPR is omitted, the scalar | |
| 5804 | variable of the same name as the FILEHANDLE contains the filename. | |
| 5805 | (Note that lexical variables--those declared with C<my>--will not work | |
| 5806 | for this purpose; so if you're using C<my>, specify EXPR in your call | |
| 5807 | to open.) See L<perlopentut> for a kinder, gentler explanation of opening | |
| 5808 | files. | |
| 9352 | 5809 | |
| 9353 | 5810 | =end original |
| 9354 | 5811 | |
| 9355 | ||
| 5812 | EXPR を省略すると、FILEHANDLE と同じ名前のスカラ変数に、 | |
| 5813 | ファイル名が入れられているものとして処理されます。 | |
| 5814 | (C<my> で宣言されたレキシカル変数はこの目的には使えません。 | |
| 5815 | 従って、C<my>を使った場合は、open を呼び出すときに EXPR を指定してください。) | |
| 5816 | ファイルのオープンに関するより親切な説明については | |
| 5817 | L<perlopentut> を参照して下さい。 | |
| 9356 | 5818 | |
| 9357 | open(my $fh, "<", "input.txt") | |
| 9358 | or die "Can't open < input.txt: $!"; | |
| 9359 | ||
| 9360 | 5819 | =begin original |
| 9361 | 5820 | |
| 9362 | ||
| 5821 | If MODE is C<< '<' >> or nothing, the file is opened for input. | |
| 5822 | If MODE is C<< '>' >>, the file is truncated and opened for | |
| 5823 | output, being created if necessary. If MODE is C<<< '>>' >>>, | |
| 5824 | the file is opened for appending, again being created if necessary. | |
| 5825 | You can put a C<'+'> in front of the C<< '>' >> or C<< '<' >> to indicate that | |
| 5826 | you want both read and write access to the file; thus C<< '+<' >> is almost | |
| 5827 | always preferred for read/write updates--the C<< '+>' >> mode would clobber the | |
| 5828 | file first. You can't usually use either read-write mode for updating | |
| 5829 | textfiles, since they have variable length records. See the B<-i> | |
| 5830 | switch in L<perlrun> for a better approach. The file is created with | |
| 5831 | permissions of C<0666> modified by the process' C<umask> value. | |
| 9363 | 5832 | |
| 9364 | 5833 | =end original |
| 9365 | 5834 | |
| 9366 | ||
| 5835 | MODE が C<< '<' >> か、何も付けなかった場合には、 | |
| 5836 | 入力用としてオープンされることになります。 | |
| 5837 | MODE が C<< '>' >> の場合には、ファイルは空にされたあと出力用に | |
| 5838 | オープンされ、必要ならファイルが作成されます。 | |
| 5839 | MODE が C<<< '>>' >>> の場合には、追記用にオープンされ、 | |
| 5840 | 必要ならファイルが作成されます。 | |
| 5841 | C<< '>' >> や C<< '<' >> の前に C<'+'> を置くことで、 | |
| 5842 | ファイルを読み書き両用にすることもできます。 | |
| 5843 | 従って、C<< '+<' >> はほとんどの場合読み書き更新をするために適したものです。 | |
| 5844 | C<< '+>' >> は最初にファイルを上書きします。 | |
| 5845 | テキストファイルを更新する場合には普通はどちらの読み書きモードも使えません。 | |
| 5846 | 可変長のレコードを持つからです。 | |
| 5847 | よりよい手法については L<perlrun> の B<-i> オプションを参照して下さい。 | |
| 5848 | 作成されるファイルのパーミッションは C<0666> を | |
| 5849 | プロセスの C<umask> の値で修正したものになります。 | |
| 9367 | 5850 | |
| 9368 | open(my $fh, ">", "output.txt") | |
| 9369 | or die "Can't open > output.txt: $!"; | |
| 9370 | ||
| 9371 | 5851 | =begin original |
| 9372 | 5852 | |
| 9373 | ||
| 5853 | These various prefixes correspond to the fopen(3) modes of C<'r'>, C<'r+'>, | |
| 9374 | ||
| 5854 | C<'w'>, C<'w+'>, C<'a'>, and C<'a+'>. | |
| 9375 | consider L<perlopentut>.) | |
| 9376 | 5855 | |
| 9377 | 5856 | =end original |
| 9378 | 5857 | |
| 9379 | ||
| 5858 | これらの様々な前置詞は fopen(3) の C<'r'>, C<'r+'>, | |
| 9380 | ||
| 5859 | C<'w'>, C<'w+'>, C<'a'>, C<'a+'> のモードに対応します。 | |
| 9381 | 5860 | |
| 9382 | 5861 | =begin original |
| 9383 | 5862 | |
| 9384 | I | |
| 5863 | In the 2-arguments (and 1-argument) form of the call the mode and | |
| 9385 | ||
| 5864 | filename should be concatenated (in this order), possibly separated by | |
| 9386 | ||
| 5865 | spaces. It is possible to omit the mode if the mode is C<< '<' >>. | |
| 9387 | FILEHANDLE is an expression, its value is the real filehandle. (This is | |
| 9388 | considered a symbolic reference, so C<use strict "refs"> should I<not> be | |
| 9389 | in effect.) | |
| 9390 | 5866 | |
| 9391 | 5867 | =end original |
| 9392 | 5868 | |
| 9393 | ||
| 5869 | 2 引数(と 1 引数) の形式ではモードとファイル名は(この順番で) | |
| 9394 | ||
| 5870 | 結合されます(空白によって分割されているかもしれません)。 | |
| 9395 | ||
| 5871 | モードが C<< '<' >> の場合はモードを省略できます。 | |
| 9396 | さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の | |
| 9397 | ファイルハンドルの名前として使います。 | |
| 9398 | (これはシンボリックリファレンスとして扱われるので、 | |
| 9399 | C<use strict "refs"> の影響を I<受けません>。) | |
| 9400 | 5872 | |
| 9401 | 5873 | =begin original |
| 9402 | 5874 | |
| 9403 | If th | |
| 5875 | If the filename begins with C<'|'>, the filename is interpreted as a | |
| 9404 | o | |
| 5876 | command to which output is to be piped, and if the filename ends with a | |
| 9405 | ||
| 5877 | C<'|'>, the filename is interpreted as a command which pipes output to | |
| 9406 | ||
| 5878 | us. See L<perlipc/"Using open() for IPC"> | |
| 9407 | f | |
| 5879 | for more examples of this. (You are not allowed to C<open> to a command | |
| 9408 | ||
| 5880 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, | |
| 9409 | creat | |
| 5881 | and L<perlipc/"Bidirectional Communication with Another Process"> | |
| 5882 | for alternatives.) | |
| 9410 | 5883 | |
| 9411 | 5884 | =end original |
| 9412 | 5885 | |
| 9413 | ||
| 5886 | ファイル名の先頭に C<'|'> を付けると、 | |
| 9414 | ||
| 5887 | そのファイル名をコマンドとして解釈し、ファイルハンドルへの | |
| 9415 | ||
| 5888 | 出力がパイプを通じて、そのコマンドへ入力されます。 | |
| 9416 | ||
| 5889 | 逆にファイル名の最後に C<'|'> を付けた場合には、 | |
| 9417 | ||
| 5890 | 同様にファイル名をコマンドと解釈し、そのコマンドの出力がパイプを通じて、 | |
| 9418 | ||
| 5891 | ファイルハンドルから入力として読み込むことができるようになります。 | |
| 9419 | ||
| 5892 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を | |
| 5893 | 参照してください。 | |
| 5894 | (C<open> を入出力 I<両用> にパイプすることは出来ませんが | |
| 5895 | 代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
| 5896 | L<perlipc/"Bidirectional Communication with Another Process"> | |
| 5897 | を参照してください。) | |
| 9420 | 5898 | |
| 9421 | 5899 | =begin original |
| 9422 | 5900 | |
| 9423 | ||
| 5901 | If MODE is C<'|-'>, the filename is interpreted as a | |
| 9424 | ||
| 5902 | command to which output is to be piped, and if MODE is | |
| 9425 | C< | |
| 5903 | C<'-|'>, the filename is interpreted as a command which pipes output to | |
| 9426 | ||
| 5904 | us. In the 2-arguments (and 1-argument) form one should replace dash | |
| 9427 | ||
| 5905 | (C<'-'>) with the command. See L<perlipc/"Using open() for IPC"> | |
| 9428 | ||
| 5906 | for more examples of this. (You are not allowed to C<open> to a command | |
| 9429 | ||
| 5907 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, | |
| 9430 | ||
| 5908 | and L<perlipc/"Bidirectional Communication"> for alternatives.) | |
| 9431 | 5909 | |
| 9432 | 5910 | =end original |
| 9433 | 5911 | |
| 9434 | ファイル | |
| 5912 | MODE が C<'|-'> の場合、ファイル名は出力がパイプされるコマンドとして | |
| 9435 | ||
| 5913 | 解釈され、MODE が C<'-|'> の場合、ファイル名は出力がこちらに | |
| 9436 | 従って、ほとんど常に C<< +< >> が読み書き更新のために使われます -- | |
| 9437 | C<< +> >> モードはまずファイルを上書きします。 | |
| 9438 | 普通はこれらの読み書きモードをテキストファイルの更新のためには使えません; | |
| 9439 | なぜなら可変長のレコードで構成されているからです。 | |
| 9440 | よりよい手法については L<perlrun> の B<-i> オプションを参照してください。 | |
| 9441 | ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した | |
| 9442 | パーミッションで作成されます。 | |
| 9443 | ||
| 9444 | =begin original | |
| 9445 | ||
| 9446 | These various prefixes correspond to the L<fopen(3)> modes of C<r>, | |
| 9447 | C<r+>, C<w>, C<w+>, C<a>, and C<a+>. | |
| 9448 | ||
| 9449 | =end original | |
| 9450 | ||
| 9451 | これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>, | |
| 9452 | C<w>, C<w+>, C<a>, C<a+> のモードに対応します。 | |
| 9453 | ||
| 9454 | =begin original | |
| 9455 | ||
| 9456 | In the one- and two-argument forms of the call, the mode and filename | |
| 9457 | should be concatenated (in that order), preferably separated by white | |
| 9458 | space. You can--but shouldn't--omit the mode in these forms when that mode | |
| 9459 | is C<< < >>. It is safe to use the two-argument form of | |
| 9460 | L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal. | |
| 9461 | ||
| 9462 | =end original | |
| 9463 | ||
| 9464 | 1 引数 と 2 引数の形式ではモードとファイル名は(この順番で) | |
| 9465 | 結合されます(空白によって分割されているかもしれません)。 | |
| 9466 | この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、 | |
| 9467 | するべきではありません)。 | |
| 9468 | ファイル引数が既知のリテラルの場合、2 引数形式の | |
| 9469 | L<C<open>|/open FILEHANDLE,EXPR> は安全です。 | |
| 9470 | ||
| 9471 | =begin original | |
| 9472 | ||
| 9473 | For three or more arguments if MODE is C<|->, the filename is | |
| 9474 | interpreted as a command to which output is to be piped, and if MODE | |
| 9475 | is C<-|>, the filename is interpreted as a command that pipes | |
| 9476 | output to us. In the two-argument (and one-argument) form, one should | |
| 9477 | replace dash (C<->) with the command. | |
| 9478 | See L<perlipc/"Using open() for IPC"> for more examples of this. | |
| 9479 | (You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command | |
| 9480 | that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and | |
| 9481 | L<perlipc/"Bidirectional Communication with Another Process"> for | |
| 9482 | alternatives.) | |
| 9483 | ||
| 9484 | =end original | |
| 9485 | ||
| 9486 | 3 引数以上の形式で | |
| 9487 | MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして | |
| 9488 | 解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに | |
| 9489 | 5914 | パイプされるコマンドとして解釈されます。 |
| 9490 | 2 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに | |
| 5915 | 2 引数(と 1 引数) の形式ではハイフン(C<'-'>)をコマンドの代わりに | |
| 5916 | 使えます。 | |
| 9491 | 5917 | これに関するさらなる例については L<perlipc/"Using open() for IPC"> を |
| 9492 | 5918 | 参照してください。 |
| 9493 | ( | |
| 5919 | (C<open> を入出力 I<両用> にパイプすることは出来ませんが | |
| 9494 | ||
| 5920 | 代替案としては L<IPC::Open2>, L<IPC::Open3>, | |
| 9495 | L<perlipc/"Bidirectional Communication | |
| 5921 | L<perlipc/"Bidirectional Communication"> を参照してください。) | |
| 9496 | 参照してください。) | |
| 9497 | 5922 | |
| 9498 | 5923 | =begin original |
| 9499 | 5924 | |
| 9500 | In the | |
| 5925 | In the 2-arguments (and 1-argument) form opening C<'-'> opens STDIN | |
| 9501 | ||
| 5926 | and opening C<< '>-' >> opens STDOUT. | |
| 9502 | to the command invoked if the platform supports it. The meaning of | |
| 9503 | L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for | |
| 9504 | non-pipe modes is not yet defined, but experimental "layers" may give | |
| 9505 | extra LIST arguments meaning. | |
| 9506 | 5927 | |
| 9507 | 5928 | =end original |
| 9508 | 5929 | |
| 9509 | ||
| 5930 | 2 引数(と 1 引数)で C<'-'> を open すると STDIN がオープンされ、 | |
| 9510 | ||
| 5931 | C<< '>-' >> を open すると STDOUT がオープンされます。 | |
| 9511 | コマンドへの引数となります。 | |
| 9512 | パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の | |
| 9513 | 意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。 | |
| 9514 | 5932 | |
| 9515 | 5933 | =begin original |
| 9516 | 5934 | |
| 9517 | ||
| 5935 | Open returns | |
| 9518 | or | |
| 5936 | nonzero upon success, the undefined value otherwise. If the C<open> | |
| 5937 | involved a pipe, the return value happens to be the pid of the | |
| 5938 | subprocess. | |
| 9519 | 5939 | |
| 9520 | 5940 | =end original |
| 9521 | 5941 | |
| 9522 | 2 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が | |
| 9523 | オープンされ、C<< >- >> を open すると STDOUT がオープンされます。 | |
| 9524 | ||
| 9525 | =begin original | |
| 9526 | ||
| 9527 | You may (and usually should) use the three-argument form of open to specify | |
| 9528 | I/O layers (sometimes referred to as "disciplines") to apply to the handle | |
| 9529 | that affect how the input and output are processed (see L<open> and | |
| 9530 | L<PerlIO> for more details). For example: | |
| 9531 | ||
| 9532 | =end original | |
| 9533 | ||
| 9534 | open の 3 引数形式では、どのように入出力が処理されるかに影響を与える | |
| 9535 | I/O 層(「ディシプリン」とも呼ばれます)を指定できます | |
| 9536 | (そして普通はそうするべきです) | |
| 9537 | (詳細については L<open> と L<PerlIO> を参照してください)。 | |
| 9538 | 例えば: | |
| 9539 | ||
| 9540 | open(my $fh, "<:encoding(UTF-8)", $filename) | |
| 9541 | || die "Can't open UTF-8 encoded $filename: $!"; | |
| 9542 | ||
| 9543 | =begin original | |
| 9544 | ||
| 9545 | opens the UTF8-encoded file containing Unicode characters; | |
| 9546 | see L<perluniintro>. Note that if layers are specified in the | |
| 9547 | three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>; | |
| 9548 | usually set by the L<open> pragma or the switch C<-CioD>) are ignored. | |
| 9549 | Those layers will also be ignored if you specify a colon with no name | |
| 9550 | following it. In that case the default layer for the operating system | |
| 9551 | (:raw on Unix, :crlf on Windows) is used. | |
| 9552 | ||
| 9553 | =end original | |
| 9554 | ||
| 9555 | は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます; | |
| 9556 | L<perluniintro> を参照してください。 | |
| 9557 | 3 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください; | |
| 9558 | 通常は L<open> プラグマか C<-CioD> オプションでセットされます) に保存された | |
| 9559 | デフォルト層は無視されることに注意してください。 | |
| 9560 | これらの層は、名前なしでコロンを指定した場合にも無視されます。 | |
| 9561 | この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が | |
| 9562 | 使われます。 | |
| 9563 | ||
| 9564 | =begin original | |
| 9565 | ||
| 9566 | Open returns nonzero on success, the undefined value otherwise. If | |
| 9567 | the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value | |
| 9568 | happens to be the pid of the subprocess. | |
| 9569 | ||
| 9570 | =end original | |
| 9571 | ||
| 9572 | 5942 | open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。 |
| 9573 | パイプに関る | |
| 5943 | パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。 | |
| 9574 | サブプロセスの pid となります。 | |
| 9575 | 5944 | |
| 9576 | 5945 | =begin original |
| 9577 | 5946 | |
| 9578 | ||
| 5947 | If you're unfortunate enough to be running Perl on a system that | |
| 9579 | ||
| 5948 | distinguishes between text files and binary files (modern operating | |
| 9580 | ||
| 5949 | systems don't care), then you should check out L</binmode> for tips for | |
| 9581 | al | |
| 5950 | dealing with this. The key distinction between systems that need C<binmode> | |
| 9582 | a | |
| 5951 | and those that don't is their text file formats. Systems like Unix, MacOS, and | |
| 9583 | ||
| 5952 | Plan9, which delimit lines with a single character, and which encode that | |
| 5953 | character in C as C<"\n">, do not need C<binmode>. The rest need it. | |
| 9584 | 5954 | |
| 9585 | 5955 | =end original |
| 9586 | 5956 | |
| 9587 | テキストファイル | |
| 5957 | 不幸にしてテキストファイルとバイナリファイルを区別するシステムで | |
| 9588 | ||
| 5958 | Perl を動かす場合(最近の OS は区別しません)、これを扱うための | |
| 9589 | ||
| 5959 | TIPS について L</binmode> をチェックするべきです。 | |
| 9590 | ||
| 5960 | C<binmode> が必要なシステムと不要なシステムを区別する鍵は | |
| 9591 | ||
| 5961 | テキストファイルの形式です。 | |
| 9592 | ||
| 5962 | Unix, MacOS, Plan9 のような、行が 1 文字で分割され、その文字が | |
| 9593 | ||
| 5963 | C では C<"\n"> でエンコードされる場合、C<binmode> は不要です。 | |
| 5964 | そうでない場合は必要です。 | |
| 9594 | 5965 | |
| 9595 | 5966 | =begin original |
| 9596 | 5967 | |
| 9597 | When opening a file, it's s | |
| 5968 | When opening a file, it's usually a bad idea to continue normal execution | |
| 9598 | if the request failed, so | |
| 5969 | if the request failed, so C<open> is frequently used in connection with | |
| 9599 | ||
| 5970 | C<die>. Even if C<die> won't do what you want (say, in a CGI script, | |
| 9600 | wh | |
| 5971 | where you want to make a nicely formatted error message (but there are | |
| 9601 | ||
| 5972 | modules that can help with that problem)) you should always check | |
| 9602 | ||
| 5973 | the return value from opening a file. The infrequent exception is when | |
| 9603 | th | |
| 5974 | working with an unopened filehandle is actually what you want to do. | |
| 9604 | 5975 | |
| 9605 | 5976 | =end original |
| 9606 | 5977 | |
| 9607 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは | |
| 5978 | ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは | |
| 9608 | 考え | |
| 5979 | 普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて | |
| 9609 | ||
| 5980 | 使われます。 | |
| 9610 | 望むものが | |
| 5981 | 望むものが C<die> がない場合(例えば、CGI スクリプト のように | |
| 9611 | 5982 | きれいにフォーマットされたエラーメッセージを作りたい場合 |
| 9612 | 5983 | (但しこの問題を助けるモジュールがあります))でも、 |
| 9613 | ファイルを開いた時の | |
| 5984 | ファイルを開いた時の帰り値を常にチェックするべきです。 | |
| 5985 | めったにない例外は、開いていないファイルハンドルを使うのが | |
| 5986 | 本当にやりたいことの場合です。 | |
| 9614 | 5987 | |
| 9615 | 5988 | =begin original |
| 9616 | 5989 | |
| 9617 | ||
| 5990 | Examples: | |
| 9618 | If it is a lexically scoped variable declared with L<C<my>|/my VARLIST>, | |
| 9619 | that usually | |
| 9620 | means the end of the enclosing scope. However, this automatic close | |
| 9621 | does not check for errors, so it is better to explicitly close | |
| 9622 | filehandles, especially those used for writing: | |
| 9623 | 5991 | |
| 9624 | 5992 | =end original |
| 9625 | 5993 | |
| 9626 | ||
| 5994 | 例: | |
| 9627 | これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、 | |
| 9628 | 普通は囲まれたスコープの終わりを意味します。 | |
| 9629 | しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、 | |
| 9630 | 明示的にファイルハンドルを閉じる方がよいです。 | |
| 9631 | 5995 | |
| 9632 | close($handle) | |
| 9633 | || warn "close failed: $!"; | |
| 9634 | ||
| 9635 | =begin original | |
| 9636 | ||
| 9637 | An older style is to use a bareword as the filehandle, as | |
| 9638 | ||
| 9639 | =end original | |
| 9640 | ||
| 9641 | より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います | |
| 9642 | ||
| 9643 | open(FH, "<", "input.txt") | |
| 9644 | or die "Can't open < input.txt: $!"; | |
| 9645 | ||
| 9646 | =begin original | |
| 9647 | ||
| 9648 | Then you can use C<FH> as the filehandle, in C<< close FH >> and C<< | |
| 9649 | <FH> >> and so on. Note that it's a global variable, so this form is | |
| 9650 | not recommended in new code. | |
| 9651 | ||
| 9652 | =end original | |
| 9653 | ||
| 9654 | それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、 | |
| 9655 | ファイルハンドルとして使えます。 | |
| 9656 | これはグローバル変数なので、新しいコードでは非推奨であることに | |
| 9657 | 注意してください。 | |
| 9658 | ||
| 9659 | =begin original | |
| 9660 | ||
| 9661 | As a shortcut a one-argument call takes the filename from the global | |
| 9662 | scalar variable of the same name as the filehandle: | |
| 9663 | ||
| 9664 | =end original | |
| 9665 | ||
| 9666 | 短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の | |
| 9667 | グローバルなスカラ変数から取ります: | |
| 9668 | ||
| 9669 | 5996 | $ARTICLE = 100; |
| 9670 | open | |
| 5997 | open ARTICLE or die "Can't find article $ARTICLE: $!\n"; | |
| 5998 | while (<ARTICLE>) {... | |
| 9671 | 5999 | |
| 9672 | ||
| 6000 | open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved) | |
| 6001 | # if the open fails, output is discarded | |
| 9673 | 6002 | |
| 9674 | ||
| 6003 | open(DBASE, '+<', 'dbase.mine') # open for update | |
| 9675 | ||
| 6004 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 9676 | 6005 | |
| 9677 | ||
| 6006 | open(DBASE, '+<dbase.mine') # ditto | |
| 6007 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 9678 | 6008 | |
| 9679 | ||
| 6009 | open(ARTICLE, '-|', "caesar <$article") # decrypt article | |
| 9680 | ||
| 6010 | or die "Can't start caesar: $!"; | |
| 9681 | 変数ではありません。 | |
| 9682 | 6011 | |
| 9683 | ||
| 6012 | open(ARTICLE, "caesar <$article |") # ditto | |
| 6013 | or die "Can't start caesar: $!"; | |
| 9684 | 6014 | |
| 9685 | ||
| 6015 | open(EXTRACT, "|sort >/tmp/Tmp$$") # $$ is our process id | |
| 9686 | ||
| 6016 | or die "Can't start sort: $!"; | |
| 9687 | 6017 | |
| 9688 | ||
| 6018 | # process argument list of files along with any includes | |
| 9689 | 6019 | |
| 9690 | ||
| 6020 | foreach $file (@ARGV) { | |
| 9691 | ||
| 6021 | process($file, 'fh00'); | |
| 6022 | } | |
| 9692 | 6023 | |
| 9693 | | |
| 6024 | sub process { | |
| 6025 | my($filename, $input) = @_; | |
| 6026 | $input++; # this is a string increment | |
| 6027 | unless (open($input, $filename)) { | |
| 6028 | print STDERR "Can't open $filename: $!\n"; | |
| 6029 | return; | |
| 6030 | } | |
| 9694 | 6031 | |
| 9695 | ||
| 6032 | local $_; | |
| 6033 | while (<$input>) { # note use of indirection | |
| 6034 | if (/^#include "(.*)"/) { | |
| 6035 | process($1, $input); | |
| 6036 | next; | |
| 6037 | } | |
| 6038 | #... # whatever | |
| 6039 | } | |
| 6040 | } | |
| 9696 | 6041 | |
| 9697 | opens a filehandle to a newly created empty anonymous temporary file. | |
| 9698 | (This happens under any mode, which makes C<< +> >> the only useful and | |
| 9699 | sensible mode to use.) You will need to | |
| 9700 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading. | |
| 9701 | ||
| 9702 | =end original | |
| 9703 | ||
| 9704 | 新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。 | |
| 9705 | (これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります) | |
| 9706 | 読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が | |
| 9707 | 必要です。 | |
| 9708 | ||
| 9709 | 6042 | =begin original |
| 9710 | 6043 | |
| 9711 | Perl is built using PerlIO by default. Unless you've | |
| 9712 | changed this (such as building Perl with C<Configure -Uuseperlio>), you can | |
| 9713 | open filehandles directly to Perl scalars via: | |
| 9714 | ||
| 9715 | =end original | |
| 9716 | ||
| 9717 | Perl はデフォルトで PerlIO を使ってビルドされています。 | |
| 9718 | (C<Configure -Uuseperlio> して Perl をビルドするなどして)これを | |
| 9719 | 変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで | |
| 9720 | 開くことができます: | |
| 9721 | ||
| 9722 | open(my $fh, ">", \$variable) || .. | |
| 9723 | ||
| 9724 | =begin original | |
| 9725 | ||
| 9726 | To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first: | |
| 9727 | ||
| 9728 | =end original | |
| 9729 | ||
| 9730 | C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして | |
| 9731 | 再び開きたい場合は、先にそれを閉じます: | |
| 9732 | ||
| 9733 | close STDOUT; | |
| 9734 | open(STDOUT, ">", \$variable) | |
| 9735 | or die "Can't open STDOUT: $!"; | |
| 9736 | ||
| 9737 | =begin original | |
| 9738 | ||
| 9739 | The scalars for in-memory files are treated as octet strings: unless | |
| 9740 | the file is being opened with truncation the scalar may not contain | |
| 9741 | any code points over 0xFF. | |
| 9742 | ||
| 9743 | =end original | |
| 9744 | ||
| 9745 | オンメモリファイルのためのスカラはオクテット文字列として扱われます: | |
| 9746 | ファイルが切り詰められて開かれない限り、 | |
| 9747 | スカラは 0xFF を超える符号位置を含みません。 | |
| 9748 | ||
| 9749 | =begin original | |
| 9750 | ||
| 9751 | Opening in-memory files I<can> fail for a variety of reasons. As with | |
| 9752 | any other C<open>, check the return value for success. | |
| 9753 | ||
| 9754 | =end original | |
| 9755 | ||
| 9756 | オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。 | |
| 9757 | その他の C<open> と同様、成功したかを返り値でチェックしてください。 | |
| 9758 | ||
| 9759 | =begin original | |
| 9760 | ||
| 9761 | See L<perliol> for detailed info on PerlIO. | |
| 9762 | ||
| 9763 | =end original | |
| 9764 | ||
| 9765 | PerlIO に関する詳しい情報については L<perliol> を参照してください。 | |
| 9766 | ||
| 9767 | =begin original | |
| 9768 | ||
| 9769 | General examples: | |
| 9770 | ||
| 9771 | =end original | |
| 9772 | ||
| 9773 | 一般的な例: | |
| 9774 | ||
| 9775 | open(my $log, ">>", "/usr/spool/news/twitlog"); | |
| 9776 | # if the open fails, output is discarded | |
| 9777 | ||
| 9778 | open(my $dbase, "+<", "dbase.mine") # open for update | |
| 9779 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 9780 | ||
| 9781 | open(my $dbase, "+<dbase.mine") # ditto | |
| 9782 | or die "Can't open 'dbase.mine' for update: $!"; | |
| 9783 | ||
| 9784 | open(my $article_fh, "-|", "caesar <$article") # decrypt | |
| 9785 | # article | |
| 9786 | or die "Can't start caesar: $!"; | |
| 9787 | ||
| 9788 | open(my $article_fh, "caesar <$article |") # ditto | |
| 9789 | or die "Can't start caesar: $!"; | |
| 9790 | ||
| 9791 | open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id | |
| 9792 | or die "Can't start sort: $!"; | |
| 9793 | ||
| 9794 | # in-memory files | |
| 9795 | open(my $memory, ">", \$var) | |
| 9796 | or die "Can't open memory file: $!"; | |
| 9797 | print $memory "foo!\n"; # output will appear in $var | |
| 9798 | ||
| 9799 | =begin original | |
| 9800 | ||
| 9801 | 6044 | You may also, in the Bourne shell tradition, specify an EXPR beginning |
| 9802 | with C<< >& >>, in which case the rest of the string is interpreted | |
| 6045 | with C<< '>&' >>, in which case the rest of the string is interpreted as the | |
| 9803 | ||
| 6046 | name of a filehandle (or file descriptor, if numeric) to be | |
| 9804 | duped | |
| 6047 | duped and opened. You may use C<&> after C<< > >>, C<<< >> >>>, | |
| 9805 | C<< | |
| 6048 | C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>. The | |
| 9806 | ||
| 6049 | mode you specify should match the mode of the original filehandle. | |
| 9807 | (Duping a filehandle does not take into account any existing contents | |
| 6050 | (Duping a filehandle does not take into account any existing contents of | |
| 9808 | o | |
| 6051 | stdio buffers.) Duping file handles is not yet supported for 3-argument | |
| 9809 | ||
| 6052 | open(). | |
| 9810 | number, the name of a filehandle, or the normal "reference to a glob". | |
| 9811 | 6053 | |
| 9812 | 6054 | =end original |
| 9813 | 6055 | |
| 9814 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >> | |
| 6056 | Bourne シェルの慣例にしたがって、EXPR の先頭に C<< '>&' >> | |
| 9815 | 6057 | を付けると、EXPR の残りの文字列をファイルハンドル名 |
| 9816 | (数字であれば、ファイル記述子) と解釈して、それを | |
| 6058 | (数字であれば、ファイル記述子) と解釈して、それを複製してオープンします。 | |
| 9817 | 複製してオープンします。 | |
| 9818 | 6059 | C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, |
| 9819 | 6060 | C<< +< >>というモード指定に付けることができます。 |
| 9820 | 6061 | 指定するモード指定は、もとのファイルハンドルのモードと |
| 9821 | 6062 | 合っていないといけません。 |
| 9822 | (ファイルハンドルの複製は既に存在する | |
| 6063 | (ファイルハンドルの複製は既に存在する stdio バッファの内容に含めません。) | |
| 9823 | ||
| 6064 | ファイルハンドルの複製は 3 引数 open() ではまだ対応していません。 | |
| 9824 | 通常の「グロブへのリファレンス」を渡します。 | |
| 9825 | 6065 | |
| 9826 | 6066 | =begin original |
| 9827 | 6067 | |
| 9828 | Here is a script that saves, redirects, and restores | |
| 6068 | Here is a script that saves, redirects, and restores STDOUT and | |
| 9829 | ||
| 6069 | STDERR: | |
| 9830 | 6070 | |
| 9831 | 6071 | =end original |
| 9832 | 6072 | |
| 9833 | ||
| 6073 | STDOUT と STDERR を保存し、リダイレクトし、元に戻すスクリプトを示します。 | |
| 9834 | 6074 | |
| 9835 | 6075 | #!/usr/bin/perl |
| 9836 | open( | |
| 6076 | open(OLDOUT, ">&STDOUT"); | |
| 9837 | open(OLDERR, | |
| 6077 | open(OLDERR, ">&STDERR"); | |
| 9838 | 6078 | |
| 9839 | open(STDOUT, '>', "foo.out") | |
| 6079 | open(STDOUT, '>', "foo.out") || die "Can't redirect stdout"; | |
| 9840 | open(STDERR, ">&STDOUT") | |
| 6080 | open(STDERR, ">&STDOUT") || die "Can't dup stdout"; | |
| 9841 | 6081 | |
| 9842 | select | |
| 6082 | select(STDERR); $| = 1; # make unbuffered | |
| 9843 | select | |
| 6083 | select(STDOUT); $| = 1; # make unbuffered | |
| 9844 | 6084 | |
| 9845 | print STDOUT "stdout 1\n"; | |
| 6085 | print STDOUT "stdout 1\n"; # this works for | |
| 9846 | print STDERR "stderr 1\n"; | |
| 6086 | print STDERR "stderr 1\n"; # subprocesses too | |
| 9847 | 6087 | |
| 9848 | o | |
| 6088 | close(STDOUT); | |
| 9849 | o | |
| 6089 | close(STDERR); | |
| 9850 | 6090 | |
| 6091 | open(STDOUT, ">&OLDOUT"); | |
| 6092 | open(STDERR, ">&OLDERR"); | |
| 6093 | ||
| 9851 | 6094 | print STDOUT "stdout 2\n"; |
| 9852 | 6095 | print STDERR "stderr 2\n"; |
| 9853 | 6096 | |
| 9854 | 6097 | =begin original |
| 9855 | 6098 | |
| 9856 | If you specify C<< '<&= | |
| 6099 | If you specify C<< '<&=N' >>, where C<N> is a number, then Perl will do an | |
| 9857 | ||
| 6100 | equivalent of C's C<fdopen> of that file descriptor; this is more | |
| 9858 | that file descriptor (and not call L<dup(2)>); this is more | |
| 9859 | 6101 | parsimonious of file descriptors. For example: |
| 9860 | 6102 | |
| 9861 | 6103 | =end original |
| 9862 | 6104 | |
| 9863 | C< | |
| 6105 | C<N> を数値として、C<< '<&=N' >> と指定すると、Perl は、 | |
| 9864 | ||
| 6106 | そのファイル記述子に対する C の C<fdopen> と同じことを行ないます。 | |
| 9865 | ||
| 6107 | これはファイル記述子をより節約します。たとえば: | |
| 9866 | これはファイル記述子をより節約します。 | |
| 9867 | 例えば: | |
| 9868 | 6108 | |
| 9869 | | |
| 6109 | open(FILEHANDLE, "<&=$fd") | |
| 9870 | open(my $fh, "<&=", $fd) | |
| 9871 | 6110 | |
| 9872 | 6111 | =begin original |
| 9873 | 6112 | |
| 9874 | or | |
| 6113 | Note that this feature depends on the fdopen() C library function. | |
| 6114 | On many UNIX systems, fdopen() is known to fail when file descriptors | |
| 6115 | exceed a certain value, typically 255. If you need more file | |
| 6116 | descriptors than that, consider rebuilding Perl to use the C<sfio> | |
| 6117 | library. | |
| 9875 | 6118 | |
| 9876 | 6119 | =end original |
| 9877 | 6120 | |
| 9878 | ||
| 6121 | この機能は fdopen() C ライブラリ関数に依存します。 | |
| 6122 | 多くの UNIX システムでは、fdopen() はファイル記述子がある値 | |
| 9880 | open(my $fh, "<&=$fd") | |
| 9881 | ||
| 9882 | =begin original | |
| 9883 | ||
| 9884 | or | |
| 9885 | ||
| 9886 | =end original | |
| 9887 | ||
| 9888 | または | |
| 9889 | ||
| 9890 | # open for append, using the fileno of $oldfh | |
| 9891 | open(my $fh, ">>&=", $oldfh) | |
| 9892 | ||
| 9893 | =begin original | |
| 9894 | ||
| 9895 | Being parsimonious on filehandles is also useful (besides being | |
| 9896 | parsimonious) for example when something is dependent on file | |
| 9897 | descriptors, like for example locking using | |
| 9898 | L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just | |
| 9899 | C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the | |
| 9900 | same file descriptor as C<$B>, and therefore C<flock($A)> will not | |
| 9901 | C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>, | |
| 9902 | the filehandles will share the same underlying system file descriptor. | |
| 9903 | ||
| 9904 | =end original | |
| 9905 | ||
| 9906 | ファイルハンドルを倹約することは、(倹約できること以外に)何かが | |
| 9907 | ファイル記述子に依存している場合、例えば | |
| 9908 | L<C<flock>|/flock FILEHANDLE,OPERATION> を使った | |
| 9909 | ファイルロックといった場合に有用です。 | |
| 9910 | C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ | |
| 9911 | ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。 | |
| 9912 | しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの | |
| 9913 | 同じファイル記述子を共有します。 | |
| 9914 | ||
| 9915 | =begin original | |
| 9916 | ||
| 9917 | Note that under Perls older than 5.8.0, Perl uses the standard C library's' | |
| 9918 | L<fdopen(3)> to implement the C<=> functionality. On many Unix systems, | |
| 9919 | L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255. | |
| 9920 | For Perls 5.8.0 and later, PerlIO is (most often) the default. | |
| 9921 | ||
| 9922 | =end original | |
| 9923 | ||
| 9924 | 5.8.0 より前の Perl の場合、C<=> 機能の実装は | |
| 9925 | 標準 C ライブラリの L<fdopen(3)> を使っています。 | |
| 9926 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値 | |
| 9927 | 6123 | (典型的には 255)を超えた場合に失敗することが知られています。 |
| 9928 | ||
| 6124 | これより多くのファイル記述子が必要な場合は、 | |
| 6125 | C<sfio> ライブラリを使って Perl を再ビルドすることを検討して下さい。 | |
| 9929 | 6126 | |
| 9930 | 6127 | =begin original |
| 9931 | 6128 | |
| 9932 | ||
| 6129 | If you open a pipe on the command C<'-'>, i.e., either C<'|-'> or C<'-|'> | |
| 9933 | ||
| 6130 | with 2-arguments (or 1-argument) form of open(), then | |
| 9934 | ||
| 6131 | there is an implicit fork done, and the return value of open is the pid | |
| 6132 | of the child within the parent process, and C<0> within the child | |
| 9936 | ||
| 6133 | process. (Use C<defined($pid)> to determine whether the open was successful.) | |
| 6134 | The filehandle behaves normally for the parent, but i/o to that | |
| 9938 | Perl が PerlIO つきでビルドされているかどうかを確認するには、 | |
| 9939 | C<perl -V:useperlio> を見ます。 | |
| 9940 | これが C<'define'> なら PerlIO を使っています; | |
| 9941 | そうでなければ使っていません。 | |
| 9942 | ||
| 9943 | =begin original | |
| 9944 | ||
| 9945 | If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|> | |
| 9946 | with the one- or two-argument forms of | |
| 9947 | L<C<open>|/open FILEHANDLE,EXPR>), an implicit L<C<fork>|/fork> is done, | |
| 9948 | so L<C<open>|/open FILEHANDLE,EXPR> returns twice: in the parent process | |
| 9949 | it returns the pid | |
| 9950 | of the child process, and in the child process it returns (a defined) C<0>. | |
| 9951 | Use C<defined($pid)> or C<//> to determine whether the open was successful. | |
| 9952 | ||
| 9953 | =end original | |
| 9954 | ||
| 9955 | 1 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR>) で | |
| 9956 | (C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、 | |
| 9957 | 暗黙の L<C<fork>|/fork> が行なわれるので、 | |
| 9958 | L<C<open>|/open FILEHANDLE,EXPR> は 2 回返ります; | |
| 9959 | 親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が | |
| 9960 | 返されます。 | |
| 9961 | open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を | |
| 9962 | 使います。 | |
| 9963 | ||
| 9964 | =begin original | |
| 9965 | ||
| 9966 | For example, use either | |
| 9967 | ||
| 9968 | =end original | |
| 9969 | ||
| 9970 | 例えば、以下の二つ | |
| 9971 | ||
| 9972 | my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!"; | |
| 9973 | ||
| 9974 | =begin original | |
| 9975 | ||
| 9976 | or | |
| 9977 | ||
| 9978 | =end original | |
| 9979 | ||
| 9980 | または | |
| 9981 | ||
| 9982 | my $child_pid = open(my $to_kid, "|-") // die "Can't fork: $!"; | |
| 9983 | ||
| 9984 | =begin original | |
| 9985 | ||
| 9986 | followed by | |
| 9987 | ||
| 9988 | =end original | |
| 9989 | ||
| 9990 | を使って、後で以下のようにします。 | |
| 9991 | ||
| 9992 | if ($child_pid) { | |
| 9993 | # am the parent: | |
| 9994 | # either write $to_kid or else read $from_kid | |
| 9995 | ... | |
| 9996 | waitpid $child_pid, 0; | |
| 9997 | } else { | |
| 9998 | # am the child; use STDIN/STDOUT normally | |
| 9999 | ... | |
| 10000 | exit; | |
| 10001 | } | |
| 10002 | ||
| 10003 | =begin original | |
| 10004 | ||
| 10005 | The filehandle behaves normally for the parent, but I/O to that | |
| 10006 | 6135 | filehandle is piped from/to the STDOUT/STDIN of the child process. |
| 10007 | In the child process | |
| 6136 | In the child process the filehandle isn't opened--i/o happens from/to | |
| 10008 | the new STDOUT | |
| 6137 | the new STDOUT or STDIN. Typically this is used like the normal | |
| 10009 | 6138 | piped open when you want to exercise more control over just how the |
| 10010 | pipe command gets executed, such as when running setuid and | |
| 6139 | pipe command gets executed, such as when you are running setuid, and | |
| 10011 | ||
| 6140 | don't want to have to scan shell commands for metacharacters. | |
| 6141 | The following triples are more or less equivalent: | |
| 10012 | 6142 | |
| 10013 | 6143 | =end original |
| 10014 | 6144 | |
| 10015 | ||
| 6145 | 2 引数(または 1 引数)の形の open() で | |
| 10016 | ||
| 6146 | C<'-|'> や C<'|-'> というふうに、C<'-'> というコマンドに | |
| 10017 | ||
| 6147 | パイプをオープンすると、fork が行なわれ、open の返り値として、 | |
| 10018 | ||
| 6148 | 親プロセスにはチャイルドプロセスの pid が、チャイルドプロセスには | |
| 6149 | C<0> が返されます。 | |
| 6150 | (open が成功したかどうかは、 | |
| 6151 | C<defined($pid)> のようにして調べることができます。) | |
| 6152 | 親プロセスでは、このファイルハンドルは | |
| 6153 | 通常通りに動作しますが、行なわれる入出力は、 | |
| 6154 | チャイルドプロセスの STDIN/STDOUT にパイプされます。 | |
| 6155 | チャイルドプロセス側では、そのファイルハンドルは | |
| 6156 | オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。 | |
| 10019 | 6157 | これは、setuid で実行して、シェルコマンドのメタ文字を |
| 10020 | 6158 | 検索させたくないような場合に、パイプコマンドの起動の仕方を |
| 10021 | 制御したいとき、普通のパイプの | |
| 6159 | 制御したいとき、普通のパイプのopen と同じように使います。 | |
| 10022 | ||
| 10023 | =begin original | |
| 10024 | ||
| 10025 | The following blocks are more or less equivalent: | |
| 10026 | ||
| 10027 | =end original | |
| 10028 | ||
| 10029 | 6160 | 以下の組み合わせは、だいたい同じものです: |
| 10030 | 6161 | |
| 10031 | open( | |
| 6162 | open(FOO, "|tr '[a-z]' '[A-Z]'"); | |
| 10032 | open( | |
| 6163 | open(FOO, '|-', "tr '[a-z]' '[A-Z]'"); | |
| 10033 | open( | |
| 6164 | open(FOO, '|-') || exec 'tr', '[a-z]', '[A-Z]'; | |
| 10034 | open(my $fh, "|-", "tr", '[a-z]', '[A-Z]'); | |
| 10035 | 6165 | |
| 10036 | open( | |
| 6166 | open(FOO, "cat -n '$file'|"); | |
| 10037 | open( | |
| 6167 | open(FOO, '-|', "cat -n '$file'"); | |
| 10038 | open( | |
| 6168 | open(FOO, '-|') || exec 'cat', '-n', $file; | |
| 10039 | open(my $fh, "-|", "cat", "-n", $file); | |
| 10040 | 6169 | |
| 10041 | 6170 | =begin original |
| 10042 | 6171 | |
| 10043 | The last two examples in each block show the pipe as "list form", which is | |
| 10044 | not yet supported on all platforms. A good rule of thumb is that if | |
| 10045 | your platform has a real L<C<fork>|/fork> (in other words, if your platform is | |
| 10046 | Unix, including Linux and MacOS X), you can use the list form. You would | |
| 10047 | want to use the list form of the pipe so you can pass literal arguments | |
| 10048 | to the command without risk of the shell interpreting any shell metacharacters | |
| 10049 | in them. However, this also bars you from opening pipes to commands | |
| 10050 | that intentionally contain shell metacharacters, such as: | |
| 10051 | ||
| 10052 | =end original | |
| 10053 | ||
| 10054 | それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、 | |
| 10055 | これはまだ全てのプラットフォームで対応しているわけではなりません。 | |
| 10056 | よい経験則としては、もし実行しているプラットフォームで本当の | |
| 10057 | L<C<fork>|/fork> があれば(言い換えると、プラットフォームが Linux や | |
| 10058 | MacOS X を含む Unix なら)リスト形式が使えます。 | |
| 10059 | パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、 | |
| 10060 | シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。 | |
| 10061 | しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして | |
| 10062 | 開くことを妨げます: | |
| 10063 | ||
| 10064 | open(my $fh, "|cat -n | expand -4 | lpr") | |
| 10065 | || die "Can't open pipeline to lpr: $!"; | |
| 10066 | ||
| 10067 | =begin original | |
| 10068 | ||
| 10069 | 6172 | See L<perlipc/"Safe Pipe Opens"> for more examples of this. |
| 10070 | 6173 | |
| 10071 | 6174 | =end original |
| 10072 | 6175 | |
| 10073 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を | |
| 6176 | これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を参照して下さい。 | |
| 10074 | 参照してください。 | |
| 10075 | 6177 | |
| 10076 | 6178 | =begin original |
| 10077 | 6179 | |
| 10078 | Perl will attempt to flush all files opened for | |
| 6180 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
| 10079 | 6181 | output before any operation that may do a fork, but this may not be |
| 10080 | 6182 | supported on some platforms (see L<perlport>). To be safe, you may need |
| 10081 | to set | |
| 6183 | to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method | |
| 10082 | o | |
| 6184 | of C<IO::Handle> on any open handles. | |
| 10083 | on any open handles. | |
| 10084 | 6185 | |
| 10085 | 6186 | =end original |
| 10086 | 6187 | |
| 10087 | 6188 | v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して |
| 10088 | 6189 | fork を行う前にフラッシュしようとしますが、これに対応していない |
| 10089 | 6190 | プラットフォームもあります(L<perlport> を参照してください)。 |
| 10090 | 安全のために、 | |
| 6191 | 安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、 | |
| 10091 | ||
| 6192 | 全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを | |
| 10092 | ||
| 6193 | 呼び出すようにしてください。 | |
| 10093 | 呼び出す必要があるかもしれません。 | |
| 10094 | 6194 | |
| 10095 | 6195 | =begin original |
| 10096 | 6196 | |
| 10097 | On systems that support a | |
| 6197 | On systems that support a | |
| 10098 | ||
| 6198 | close-on-exec flag on files, the flag will be set for the newly opened | |
| 10099 | ||
| 6199 | file descriptor as determined by the value of $^F. See L<perlvar/$^F>. | |
| 10100 | 6200 | |
| 10101 | 6201 | =end original |
| 10102 | 6202 | |
| 10103 | 6203 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 10104 | フラグは | |
| 6204 | フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して | |
| 10105 | ||
| 6205 | セットされます。 | |
| 10106 | L<perlvar/$^F> | |
| 6206 | L<perlvar/$^F>を参照してください。 | |
| 10107 | 6207 | |
| 10108 | 6208 | =begin original |
| 10109 | 6209 | |
| 10110 | 6210 | Closing any piped filehandle causes the parent process to wait for the |
| 10111 | child to finish, | |
| 6211 | child to finish, and returns the status value in C<$?>. | |
| 10112 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 10113 | 6212 | |
| 10114 | 6213 | =end original |
| 10115 | 6214 | |
| 10116 | パイプのファイルハンドルを close することで、 | |
| 6215 | パイプのファイルハンドルを close することで、 | |
| 10117 | 待ち、 | |
| 6216 | 親プロセスは、チャイルドプロセスの終了を待ち、C<$?> に | |
| 10118 | ||
| 6217 | ステータス値を返します。 | |
| 10119 | 返します。 | |
| 10120 | 6218 | |
| 10121 | 6219 | =begin original |
| 10122 | 6220 | |
| 10123 | The filename passed to | |
| 6221 | The filename passed to 2-argument (or 1-argument) form of open() | |
| 10124 | ||
| 6222 | will have leading and trailing | |
| 10125 | ||
| 6223 | whitespace deleted, and the normal redirection characters | |
| 10126 | ||
| 6224 | honored. This property, known as "magic open", | |
| 10127 | 6225 | can often be used to good effect. A user could specify a filename of |
| 10128 | 6226 | F<"rsh cat file |">, or you could change certain filenames as needed: |
| 10129 | 6227 | |
| 10130 | 6228 | =end original |
| 10131 | 6229 | |
| 10132 | ||
| 6230 | 2 引数(と 1 引数)の形の open() に渡されたファイル名は、 | |
| 10133 | ||
| 6231 | はじめと終わりの空白が取り除かれ、 | |
| 10134 | 受け付けます。 | |
| 6232 | 通常のリダイレクト文字列を受け付けます。 | |
| 10135 | この機能は "magic open" として知られていますが、 | |
| 6233 | この機能は "magic open" として知られていますが、 | |
| 6234 | 普通いい効果をもたらします。 | |
| 10136 | 6235 | ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、 |
| 10137 | 6236 | 特定のファイル名を必要に応じて変更できます。 |
| 10138 | 6237 | |
| 10139 | 6238 | $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/; |
| 10140 | open( | |
| 6239 | open(FH, $filename) or die "Can't open $filename: $!"; | |
| 10141 | 6240 | |
| 10142 | 6241 | =begin original |
| 10143 | 6242 | |
| 10144 | Use | |
| 6243 | Use 3-argument form to open a file with arbitrary weird characters in it, | |
| 10145 | 6244 | |
| 10146 | 6245 | =end original |
| 10147 | 6246 | |
| 10148 | 6247 | 妙な文字が含まれているようなファイル名をオープンするには、 |
| 10149 | 6248 | 3 引数の形を使います。 |
| 10150 | 6249 | |
| 10151 | open( | |
| 6250 | open(FOO, '<', $file); | |
| 10152 | || die "Can't open $file: $!"; | |
| 10153 | 6251 | |
| 10154 | 6252 | =begin original |
| 10155 | 6253 | |
| 10156 | 6254 | otherwise it's necessary to protect any leading and trailing whitespace: |
| 10157 | 6255 | |
| 10158 | 6256 | =end original |
| 10159 | 6257 | |
| 10160 | 6258 | あるいは、次のようにして、最初と最後の空白を保護します: |
| 10161 | 6259 | |
| 10162 | 6260 | $file =~ s#^(\s)#./$1#; |
| 10163 | open( | |
| 6261 | open(FOO, "< $file\0"); | |
| 10164 | || die "Can't open $file: $!"; | |
| 10165 | 6262 | |
| 10166 | 6263 | =begin original |
| 10167 | 6264 | |
| 10168 | 6265 | (this may not work on some bizarre filesystems). One should |
| 10169 | conscientiously choose between the I<magic> and | |
| 6266 | conscientiously choose between the I<magic> and 3-arguments form | |
| 10170 | of | |
| 6267 | of open(): | |
| 10171 | 6268 | |
| 10172 | 6269 | =end original |
| 10173 | 6270 | |
| 10174 | 6271 | (これは奇妙なファイルシステムでは動作しないかもしれません)。 |
| 10175 | ||
| 6272 | open() の I<magic> と 3 引数形式を誠実に選択するべきです。 | |
| 10176 | 選択するべきです。 | |
| 10177 | 6273 | |
| 10178 | open | |
| 6274 | open IN, $ARGV[0]; | |
| 10179 | 6275 | |
| 10180 | 6276 | =begin original |
| 10181 | 6277 | |
| 10182 | 6278 | will allow the user to specify an argument of the form C<"rsh cat file |">, |
| 10183 | but will not work on a filename | |
| 6279 | but will not work on a filename which happens to have a trailing space, while | |
| 10184 | 6280 | |
| 10185 | 6281 | =end original |
| 10186 | 6282 | |
| 10187 | 6283 | とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、 |
| 10188 | 末尾にスペースがついてしまったファイル名では動作しません | |
| 6284 | 末尾にスペースがついてしまったファイル名では動作しません。一方: | |
| 10189 | 6285 | |
| 10190 | open | |
| 6286 | open IN, '<', $ARGV[0]; | |
| 10191 | || die "Can't open $ARGV[0]: $!"; | |
| 10192 | 6287 | |
| 10193 | 6288 | =begin original |
| 10194 | 6289 | |
| 10195 | will have exactly the opposite restrictions. | |
| 6290 | will have exactly the opposite restrictions. | |
| 10196 | support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which | |
| 10197 | produces a filename that can be opened normally.) | |
| 10198 | 6291 | |
| 10199 | 6292 | =end original |
| 10200 | 6293 | |
| 10201 | 6294 | はまったく逆の制限があります。 |
| 10202 | (しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という | |
| 10203 | 文法に対応していて、普通に開くことが出来るファイル名を出力します。) | |
| 10204 | 6295 | |
| 10205 | 6296 | =begin original |
| 10206 | 6297 | |
| 10207 | If you want a "real" C L<open(2)> | |
| 6298 | If you want a "real" C C<open> (see L<open(2)> on your system), then you | |
| 10208 | ||
| 6299 | should use the C<sysopen> function, which involves no such magic (but | |
| 10209 | ||
| 6300 | may use subtly different filemodes than Perl open(), which is mapped | |
| 10210 | ||
| 6301 | to C fopen()). This is | |
| 10211 | ||
| 6302 | another way to protect your filenames from interpretation. For example: | |
| 10212 | example: | |
| 10213 | 6303 | |
| 10214 | 6304 | =end original |
| 10215 | 6305 | |
| 10216 | もし「本当の」C 言語の L<open(2)> | |
| 6306 | もし「本当の」C 言語の C<open> (システムの L<open(2)> を参照してください)が | |
| 10217 | ||
| 6307 | 必要なら、このような副作用のない C<sysopen> 関数を使うべきです | |
| 10218 | (ただし、C の | |
| 6308 | (ただし、C の fopen() に割り付けられる Perl の open() とは | |
| 10219 | ||
| 6309 | かすかに違うファイルモードを持ちます)。 | |
| 10220 | 6310 | これはファイル名を解釈から守るもう一つの方法です。 |
| 10221 | 6311 | 例えば: |
| 10222 | 6312 | |
| 10223 | 6313 | use IO::Handle; |
| 10224 | sysopen( | |
| 6314 | sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL) | |
| 10225 | ||
| 6315 | or die "sysopen $path: $!"; | |
| 10226 | $fh | |
| 6316 | $oldfh = select(HANDLE); $| = 1; select($oldfh); | |
| 10227 | print | |
| 6317 | print HANDLE "stuff $$\n"; | |
| 10228 | seek( | |
| 6318 | seek(HANDLE, 0, 0); | |
| 10229 | print "File contains: ", | |
| 6319 | print "File contains: ", <HANDLE>; | |
| 10230 | 6320 | |
| 10231 | 6321 | =begin original |
| 10232 | 6322 | |
| 10233 | ||
| 6323 | Using the constructor from the C<IO::Handle> package (or one of its | |
| 10234 | ||
| 6324 | subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous | |
| 6325 | filehandles that have the scope of whatever variables hold references to | |
| 6326 | them, and automatically close whenever and however you leave that scope: | |
| 10235 | 6327 | |
| 10236 | 6328 | =end original |
| 10237 | 6329 | |
| 10238 | ||
| 6330 | C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> といった | |
| 10239 | ||
| 6331 | サブパッケージ)のコンストラクタを使うことで、 | |
| 6332 | これらへのリファレンスを保持している変数のスコープを持ち、 | |
| 6333 | スコープから離れると自動的に閉じる無名ファイルハンドルを作成できます: | |
| 10240 | 6334 | |
| 6335 | use IO::File; | |
| 6336 | #... | |
| 6337 | sub read_myfile_munged { | |
| 6338 | my $ALL = shift; | |
| 6339 | my $handle = new IO::File; | |
| 6340 | open($handle, "myfile") or die "myfile: $!"; | |
| 6341 | $first = <$handle> | |
| 6342 | or return (); # Automatically closed here. | |
| 6343 | mung $first or die "mung failed"; # Or here. | |
| 6344 | return $first, <$handle> if $ALL; # Or here. | |
| 6345 | $first; # Or here. | |
| 6346 | } | |
| 6347 | ||
| 10241 | 6348 | =begin original |
| 10242 | 6349 | |
| 10243 | ||
| 6350 | See L</seek> for some details about mixing reading and writing. | |
| 10244 | 6351 | |
| 10245 | 6352 | =end original |
| 10246 | 6353 | |
| 10247 | ||
| 6354 | 読み書きを混ぜる場合の詳細については L</seek> を参照して下さい。 | |
| 10248 | 6355 | |
| 10249 | 6356 | =item opendir DIRHANDLE,EXPR |
| 10250 | X<opendir> | |
| 10251 | 6357 | |
| 10252 | =for Pod::Functions open a directory | |
| 10253 | ||
| 10254 | 6358 | =begin original |
| 10255 | 6359 | |
| 10256 | Opens a directory named EXPR for processing by | |
| 6360 | Opens a directory named EXPR for processing by C<readdir>, C<telldir>, | |
| 10257 | ||
| 6361 | C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful. | |
| 10258 | L | |
| 6362 | DIRHANDLEs have their own namespace separate from FILEHANDLEs. | |
| 10259 | L<C<rewinddir>|/rewinddir DIRHANDLE>, and | |
| 10260 | L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful. | |
| 10261 | DIRHANDLE may be an expression whose value can be used as an indirect | |
| 10262 | dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined | |
| 10263 | scalar variable (or array or hash element), the variable is assigned a | |
| 10264 | reference to a new anonymous dirhandle; that is, it's autovivified. | |
| 10265 | Dirhandles are the same objects as filehandles; an I/O object can only | |
| 10266 | be open as one of these handle types at once. | |
| 10267 | 6363 | |
| 10268 | 6364 | =end original |
| 10269 | 6365 | |
| 10270 | ||
| 6366 | C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、 | |
| 10271 | ||
| 6367 | C<closedir> で処理するために、EXPR で指定された名前の | |
| 10272 | ||
| 6368 | ディレクトリをオープンします。成功時には真を返します。 | |
| 10273 | ||
| 6369 | DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。 | |
| 10274 | 成功時には真を返します。 | |
| 10275 | DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ | |
| 10276 | ハンドルの名前)となる式でも構いません。 | |
| 10277 | DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は | |
| 10278 | 新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、 | |
| 10279 | 自動有効化されます。 | |
| 10280 | ディレクトリハンドルはファイルハンドルと同じオブジェクトです; | |
| 10281 | 一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ | |
| 10282 | 開くことができます。 | |
| 10283 | 6370 | |
| 10284 | =begin original | |
| 10285 | ||
| 10286 | See the example at L<C<readdir>|/readdir DIRHANDLE>. | |
| 10287 | ||
| 10288 | =end original | |
| 10289 | ||
| 10290 | L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。 | |
| 10291 | ||
| 10292 | 6371 | =item ord EXPR |
| 10293 | X<ord> X<encoding> | |
| 10294 | 6372 | |
| 10295 | 6373 | =item ord |
| 10296 | 6374 | |
| 10297 | =for Pod::Functions find a character's numeric representation | |
| 10298 | ||
| 10299 | 6375 | =begin original |
| 10300 | 6376 | |
| 10301 | Returns the numeric value of the first character of EXPR. | |
| 6377 | Returns the numeric (ASCII or Unicode) value of the first character of EXPR. If | |
| 10302 | ||
| 6378 | EXPR is omitted, uses C<$_>. For the reverse, see L</chr>. | |
| 10303 | L< | |
| 6379 | See L<utf8> for more about Unicode. | |
| 10304 | (Note I<character>, not byte.) | |
| 10305 | 6380 | |
| 10306 | 6381 | =end original |
| 10307 | 6382 | |
| 10308 | EXPR の最初の文字の数値としての値を返します。 | |
| 6383 | EXPR の最初の文字の数値としての(ASCII または Unicode) 値を返します。 | |
| 10309 | EXPR | |
| 6384 | EXPR を省略した場合には、C<$_> を使用します。 | |
| 10310 | ||
| 6385 | 逆のことをするには L</chr> を参照してください。 | |
| 10311 | ||
| 6386 | Unicode については L<utf8> を参照してください。 | |
| 10312 | 6387 | |
| 10313 | = | |
| 6388 | =item our EXPR | |
| 10314 | 6389 | |
| 10315 | For the reverse, see L<C<chr>|/chr NUMBER>. | |
| 10316 | See L<perlunicode> for more about Unicode. | |
| 10317 | ||
| 10318 | =end original | |
| 10319 | ||
| 10320 | 逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。 | |
| 10321 | Unicode については L<perlunicode> を参照してください。 | |
| 10322 | ||
| 10323 | =item our VARLIST | |
| 10324 | X<our> X<global> | |
| 10325 | ||
| 10326 | =item our TYPE VARLIST | |
| 10327 | ||
| 10328 | =item our VARLIST : ATTRS | |
| 10329 | ||
| 10330 | =item our TYPE VARLIST : ATTRS | |
| 10331 | ||
| 10332 | =for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping) | |
| 10333 | ||
| 10334 | 6390 | =begin original |
| 10335 | 6391 | |
| 10336 | ||
| 6392 | An C<our> declares the listed variables to be valid globals within | |
| 10337 | ||
| 6393 | the enclosing block, file, or C<eval>. That is, it has the same | |
| 10338 | c | |
| 6394 | scoping rules as a "my" declaration, but does not create a local | |
| 6395 | variable. If more than one value is listed, the list must be placed | |
| 6396 | in parentheses. The C<our> declaration has no semantic effect unless | |
| 6397 | "use strict vars" is in effect, in which case it lets you use the | |
| 6398 | declared global variable without qualifying it with a package name. | |
| 6399 | (But only within the lexical scope of the C<our> declaration. In this | |
| 6400 | it differs from "use vars", which is package scoped.) | |
| 10339 | 6401 | |
| 10340 | 6402 | =end original |
| 10341 | 6403 | |
| 10342 | ||
| 6404 | C<our> は挙げられた変数をブロック、ファイル、C<eval> 内で | |
| 10343 | ||
| 6405 | グローバルとして宣言します。 | |
| 10344 | ||
| 6406 | これは "my" 宣言と同じスコープルールをもちますが、 | |
| 6407 | ローカル変数を作りません。 | |
| 6408 | 複数の変数を指定する場合は、変数は括弧で囲わなければなりません。 | |
| 6409 | C<our> 宣言は "use strict vars" が有効でなければ | |
| 6410 | 意味論的な効果はもちません。 | |
| 6411 | この場合、宣言したグローバル変数をパッケージ名で修飾せずに使えます。 | |
| 6412 | (しかし C<our> 宣言のレキシカルスコープの内側だけです。 | |
| 6413 | これは "use vars" と異なります。こちらはパッケージスコープです。) | |
| 10345 | 6414 | |
| 10346 | 6415 | =begin original |
| 10347 | 6416 | |
| 10348 | ||
| 6417 | An C<our> declaration declares a global variable that will be visible | |
| 10349 | L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is | |
| 10350 | only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and | |
| 10351 | L<C<state>|/state VARLIST>, which both declare new (lexical) variables, | |
| 10352 | L<C<our>|/our VARLIST> only creates an alias to an existing variable: a | |
| 10353 | package variable of the same name. | |
| 10354 | ||
| 10355 | =end original | |
| 10356 | ||
| 10357 | L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や | |
| 10358 | L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり | |
| 10359 | レキシカルスコープの中でだけ有効です。 | |
| 10360 | 新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や | |
| 10361 | L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に | |
| 10362 | 存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。 | |
| 10363 | ||
| 10364 | =begin original | |
| 10365 | ||
| 10366 | This means that when C<use strict 'vars'> is in effect, L<C<our>|/our | |
| 10367 | VARLIST> lets you use a package variable without qualifying it with the | |
| 10368 | package name, but only within the lexical scope of the | |
| 10369 | L<C<our>|/our VARLIST> declaration. This applies immediately--even | |
| 10370 | within the same statement. | |
| 10371 | ||
| 10372 | =end original | |
| 10373 | ||
| 10374 | つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を | |
| 10375 | 使うことで、 | |
| 10376 | パッケージ変数をパッケージ名で修飾することなく使うことができますが、 | |
| 10377 | L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。 | |
| 10378 | これは(たとえ同じ文の中でも)直ちに適用されます。 | |
| 10379 | ||
| 10380 | package Foo; | |
| 10381 | use strict; | |
| 10382 | ||
| 10383 | $Foo::foo = 23; | |
| 10384 | ||
| 10385 | { | |
| 10386 | our $foo; # alias to $Foo::foo | |
| 10387 | print $foo; # prints 23 | |
| 10388 | } | |
| 10389 | ||
| 10390 | print $Foo::foo; # prints 23 | |
| 10391 | ||
| 10392 | print $foo; # ERROR: requires explicit package name | |
| 10393 | ||
| 10394 | =begin original | |
| 10395 | ||
| 10396 | This works even if the package variable has not been used before, as | |
| 10397 | package variables spring into existence when first used. | |
| 10398 | ||
| 10399 | =end original | |
| 10400 | ||
| 10401 | これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、 | |
| 10402 | 最初に使われた時にひょっこり現れるからです。 | |
| 10403 | ||
| 10404 | package Foo; | |
| 10405 | use strict; | |
| 10406 | ||
| 10407 | our $foo = 23; # just like $Foo::foo = 23 | |
| 10408 | ||
| 10409 | print $Foo::foo; # prints 23 | |
| 10410 | ||
| 10411 | =begin original | |
| 10412 | ||
| 10413 | Because the variable becomes legal immediately under C<use strict 'vars'>, so | |
| 10414 | long as there is no variable with that name is already in scope, you can then | |
| 10415 | reference the package variable again even within the same statement. | |
| 10416 | ||
| 10417 | =end original | |
| 10418 | ||
| 10419 | 変数は C<use strict 'vars'> の基で直ちに正当になるので、 | |
| 10420 | スコープ内に同じ名前の変数がない限り、 | |
| 10421 | たとえ同じ文の中でもパッケージ変数を再び参照できます。 | |
| 10422 | ||
| 10423 | package Foo; | |
| 10424 | use strict; | |
| 10425 | ||
| 10426 | my $foo = $foo; # error, undeclared $foo on right-hand side | |
| 10427 | our $foo = $foo; # no errors | |
| 10428 | ||
| 10429 | =begin original | |
| 10430 | ||
| 10431 | If more than one variable is listed, the list must be placed | |
| 10432 | in parentheses. | |
| 10433 | ||
| 10434 | =end original | |
| 10435 | ||
| 10436 | 複数の変数を指定する場合は、リストはかっこでくくらなければなりません。 | |
| 10437 | ||
| 10438 | our($bar, $baz); | |
| 10439 | ||
| 10440 | =begin original | |
| 10441 | ||
| 10442 | An L<C<our>|/our VARLIST> declaration declares an alias for a package | |
| 10443 | variable that will be visible | |
| 10444 | 6418 | across its entire lexical scope, even across package boundaries. The |
| 10445 | 6419 | package in which the variable is entered is determined at the point |
| 10446 | 6420 | of the declaration, not at the point of use. This means the following |
| 10447 | 6421 | behavior holds: |
| 10448 | 6422 | |
| 10449 | 6423 | =end original |
| 10450 | 6424 | |
| 10451 | ||
| 6425 | C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を | |
| 10452 | ||
| 6426 | 越えていても)見えるグローバル変数を宣言します。 | |
| 10453 | 6427 | この変数が入るパッケージは宣言した時点で定義され、 |
| 10454 | 6428 | 使用した時点ではありません。 |
| 10455 | 6429 | これにより、以下のような振る舞いになります: |
| 10456 | 6430 | |
| 10457 | 6431 | package Foo; |
| 10458 | our $bar; | |
| 6432 | our $bar; # declares $Foo::bar for rest of lexical scope | |
| 10459 | 6433 | $bar = 20; |
| 10460 | 6434 | |
| 10461 | 6435 | package Bar; |
| 10462 | print $bar; | |
| 6436 | print $bar; # prints 20 | |
| 10463 | 6437 | |
| 10464 | 6438 | =begin original |
| 10465 | 6439 | |
| 10466 | Multiple | |
| 6440 | Multiple C<our> declarations in the same lexical scope are allowed | |
| 10467 | sa | |
| 6441 | if they are in different packages. If they happened to be in the same | |
| 10468 | ||
| 6442 | package, Perl will emit warnings if you have asked for them. | |
| 10469 | to be in the same package, Perl will emit warnings if you have asked | |
| 10470 | for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike | |
| 10471 | a second L<C<my>|/my VARLIST> declaration, which will bind the name to a | |
| 10472 | fresh variable, a second L<C<our>|/our VARLIST> declaration in the same | |
| 10473 | package, in the same scope, is merely redundant. | |
| 10474 | 6443 | |
| 10475 | 6444 | =end original |
| 10476 | 6445 | |
| 10477 | 同じレキシカルスコープでも、パッケージが異なっていれば、 | |
| 6446 | 同じレキシカルスコープでも、パッケージが異なっていれば、複数の | |
| 10478 | ||
| 6447 | C<our> 宣言ができます。 | |
| 10479 | 6448 | 同じパッケージになっていると、警告が出力されるようになっていれば |
| 10480 | ||
| 6449 | 警告が出力されます。 | |
| 10481 | 新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と | |
| 10482 | 違って、同じパッケージの同じスコープで 2 回 | |
| 10483 | L<C<our>|/our VARLIST> 宣言するのは単に冗長です。 | |
| 10484 | 6450 | |
| 10485 | 6451 | use warnings; |
| 10486 | 6452 | package Foo; |
| 10487 | our $bar; | |
| 6453 | our $bar; # declares $Foo::bar for rest of lexical scope | |
| 10488 | 6454 | $bar = 20; |
| 10489 | 6455 | |
| 10490 | 6456 | package Bar; |
| 10491 | our $bar = 30; | |
| 6457 | our $bar = 30; # declares $Bar::bar for rest of lexical scope | |
| 10492 | print $bar; | |
| 6458 | print $bar; # prints 30 | |
| 10493 | 6459 | |
| 10494 | our $bar; | |
| 6460 | our $bar; # emits warning | |
| 10495 | print $bar; # still prints 30 | |
| 10496 | 6461 | |
| 10497 | =begin original | |
| 10498 | ||
| 10499 | An L<C<our>|/our VARLIST> declaration may also have a list of attributes | |
| 10500 | associated with it. | |
| 10501 | ||
| 10502 | =end original | |
| 10503 | ||
| 10504 | L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを | |
| 10505 | 持つこともあります。 | |
| 10506 | ||
| 10507 | =begin original | |
| 10508 | ||
| 10509 | The exact semantics and interface of TYPE and ATTRS are still | |
| 10510 | evolving. TYPE is currently bound to the use of the L<fields> pragma, | |
| 10511 | and attributes are handled using the L<attributes> pragma, or, starting | |
| 10512 | from Perl 5.8.0, also via the L<Attribute::Handlers> module. See | |
| 10513 | L<perlsub/"Private Variables via my()"> for details. | |
| 10514 | ||
| 10515 | =end original | |
| 10516 | ||
| 10517 | TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。 | |
| 10518 | 現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、 | |
| 10519 | 属性は L<attributes> プラグマか、Perl 5.8.0 からは | |
| 10520 | L<Attribute::Handlers> モジュールと結び付けられています。 | |
| 10521 | 詳しくは L<perlsub/"Private Variables via my()"> を参照してください。 | |
| 10522 | ||
| 10523 | =begin original | |
| 10524 | ||
| 10525 | Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used | |
| 10526 | as a dummy placeholder, for example to skip assignment of initial | |
| 10527 | values: | |
| 10528 | ||
| 10529 | =end original | |
| 10530 | ||
| 10531 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を | |
| 10532 | 飛ばすために、ダミーのプレースホルダとして使えることに注意してください: | |
| 10533 | ||
| 10534 | our ( undef, $min, $hour ) = localtime; | |
| 10535 | ||
| 10536 | =begin original | |
| 10537 | ||
| 10538 | L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows | |
| 10539 | use of an unqualified name I<only> within the affected package, but | |
| 10540 | across scopes. | |
| 10541 | ||
| 10542 | =end original | |
| 10543 | ||
| 10544 | L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを | |
| 10545 | またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない | |
| 10546 | 名前を使えるようにします。 | |
| 10547 | ||
| 10548 | 6462 | =item pack TEMPLATE,LIST |
| 10549 | X<pack> | |
| 10550 | 6463 | |
| 10551 | =for Pod::Functions convert a list into a binary representation | |
| 10552 | ||
| 10553 | 6464 | =begin original |
| 10554 | 6465 | |
| 10555 | 6466 | Takes a LIST of values and converts it into a string using the rules |
| 10556 | 6467 | given by the TEMPLATE. The resulting string is the concatenation of |
| 10557 | 6468 | the converted values. Typically, each converted value looks |
| 10558 | 6469 | like its machine-level representation. For example, on 32-bit machines |
| 10559 | an integer may be represented by a sequence of 4 bytes | |
| 6470 | a converted integer may be represented by a sequence of 4 bytes. | |
| 10560 | Perl be presented as a string that's 4 characters long. | |
| 10561 | 6471 | |
| 10562 | 6472 | =end original |
| 10563 | 6473 | |
| 10564 | LIST の値を TEMPLATE で与えられたルールを用いて | |
| 6474 | LIST の値を TEMPLATE で与えられたルールを用いて | |
| 6475 | 文字列に変換します。 | |
| 10565 | 6476 | 結果の文字列は変換した値を連結したものです。 |
| 10566 | 6477 | 典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。 |
| 10567 | 例えば、32-bit マシンでは、整数 | |
| 6478 | 例えば、32-bit マシンでは、整数を変換すると 4 バイトのデータとして | |
| 10568 | ||
| 6479 | 表現されます。 | |
| 10569 | 6480 | |
| 10570 | 6481 | =begin original |
| 10571 | 6482 | |
| 10572 | ||
| 6483 | The TEMPLATE is a | |
| 6484 | sequence of characters that give the order and type of values, as | |
| 6485 | follows: | |
| 10573 | 6486 | |
| 10574 | 6487 | =end original |
| 10575 | 6488 | |
| 10576 | ||
| 6489 | TEMPLATE は、以下の | |
| 6490 | ような値の型と順番を指定する文字を並べたものです: | |
| 10577 | 6491 | |
| 10578 | 6492 | =begin original |
| 10579 | 6493 | |
| 10580 | ||
| 6494 | a A string with arbitrary binary data, will be null padded. | |
| 10581 | ||
| 6495 | A An ASCII string, will be space padded. | |
| 6496 | Z A null terminated (asciz) string, will be null padded. | |
| 10582 | 6497 | |
| 10583 | ||
| 6498 | b A bit string (ascending bit order inside each byte, like vec()). | |
| 6499 | B A bit string (descending bit order inside each byte). | |
| 6500 | h A hex string (low nybble first). | |
| 6501 | H A hex string (high nybble first). | |
| 10584 | 6502 | |
| 10585 | ||
| 6503 | c A signed char value. | |
| 6504 | C An unsigned char value. Only does bytes. See U for Unicode. | |
| 10586 | 6505 | |
| 10587 | ||
| 6506 | s A signed short value. | |
| 6507 | S An unsigned short value. | |
| 6508 | (This 'short' is _exactly_ 16 bits, which may differ from | |
| 6509 | what a local C compiler calls 'short'. If you want | |
| 6510 | native-length shorts, use the '!' suffix.) | |
| 10588 | 6511 | |
| 10589 | | |
| 6512 | i A signed integer value. | |
| 10590 | A | |
| 6513 | I An unsigned integer value. | |
| 10591 | | |
| 6514 | (This 'integer' is _at_least_ 32 bits wide. Its exact | |
| 6515 | size depends on what a local C compiler calls 'int', | |
| 6516 | and may even be larger than the 'long' described in | |
| 6517 | the next item.) | |
| 10592 | 6518 | |
| 10593 | ||
| 6519 | l A signed long value. | |
| 6520 | L An unsigned long value. | |
| 6521 | (This 'long' is _exactly_ 32 bits, which may differ from | |
| 6522 | what a local C compiler calls 'long'. If you want | |
| 6523 | native-length longs, use the '!' suffix.) | |
| 10594 | 6524 | |
| 10595 | | |
| 6525 | n An unsigned short in "network" (big-endian) order. | |
| 10596 | A | |
| 6526 | N An unsigned long in "network" (big-endian) order. | |
| 10597 | | |
| 6527 | v An unsigned short in "VAX" (little-endian) order. | |
| 6528 | V An unsigned long in "VAX" (little-endian) order. | |
| 6529 | (These 'shorts' and 'longs' are _exactly_ 16 bits and | |
| 6530 | _exactly_ 32 bits, respectively.) | |
| 10598 | 6531 | |
| 10599 | ||
| 6532 | q A signed quad (64-bit) value. | |
| 6533 | Q An unsigned quad value. | |
| 6534 | (Quads are available only if your system supports 64-bit | |
| 6535 | integer values _and_ if Perl has been compiled to support those. | |
| 6536 | Causes a fatal error otherwise.) | |
| 10600 | 6537 | |
| 10601 | | |
| 6538 | f A single-precision float in the native format. | |
| 10602 | | |
| 6539 | d A double-precision float in the native format. | |
| 10603 | B A bit string (descending bit order inside each byte). | |
| 10604 | h A hex string (low nybble first). | |
| 10605 | H A hex string (high nybble first). | |
| 10606 | 6540 | |
| 10607 | ||
| 6541 | p A pointer to a null-terminated string. | |
| 6542 | P A pointer to a structure (fixed-length string). | |
| 10608 | 6543 | |
| 10609 | | |
| 6544 | u A uuencoded string. | |
| 10610 | | |
| 6545 | U A Unicode character number. Encodes to UTF-8 internally. | |
| 10611 | | |
| 6546 | Works even if C<use utf8> is not in effect. | |
| 10612 | H 16 進数文字列 (高位ニブルが先)。 | |
| 10613 | 6547 | |
| 10614 | ||
| 6548 | w A BER compressed integer. Its bytes represent an unsigned | |
| 6549 | integer in base 128, most significant digit first, with as | |
| 6550 | few digits as possible. Bit eight (the high bit) is set | |
| 6551 | on each byte except the last. | |
| 10615 | 6552 | |
| 10616 | | |
| 6553 | x A null byte. | |
| 10617 | | |
| 6554 | X Back up a byte. | |
| 10618 | | |
| 6555 | @ Null fill to absolute position. | |
| 10619 | 6556 | |
| 10620 | 6557 | =end original |
| 10621 | 6558 | |
| 10622 | | |
| 6559 | a 任意のバイナリデータを含む文字列、ヌル文字で埋める | |
| 10623 | | |
| 6560 | A ASCII 文字列、スペース文字で埋める | |
| 10624 | | |
| 6561 | Z ヌル文字終端(asciz)文字列、ヌル文字で埋める | |
| 10625 | 6562 | |
| 10626 | ||
| 6563 | b ビット列 (バイトごとに昇ビット順、vec() と同じ) | |
| 6564 | B ビット列 (バイトごとに降ビット順) | |
| 6565 | h 16 進数文字列 (低位ニブルが先) | |
| 6566 | H 16 進数文字列 (高位ニブルが先) | |
| 10627 | 6567 | |
| 10628 | | |
| 6568 | c signed char 値 | |
| 10629 | | |
| 6569 | C unsigned char 値。バイトのみ。Unicode 用は U。 | |
| 10630 | 6570 | |
| 10631 | ||
| 6571 | s signed short 値 | |
| 6572 | S unsigned short 値 | |
| 6573 | (ここでの 'short' は「正確に」 16 bit です。 | |
| 6574 | ローカルの C コンパイラの 'short' のサイズとは違うかもしれません。 | |
| 6575 | ネイティブな長さの short を使いたい場合は、 | |
| 6576 | '!' 前置詞を使ってください。) | |
| 10632 | 6577 | |
| 10633 | | |
| 6578 | i signed int 値 | |
| 10634 | | |
| 6579 | I unsigned int 値 | |
| 6580 | (ここでの 'integer' は 「最低」 32 bits 幅です。 | |
| 6581 | 正確なサイズはローカルの C コンパイラの | |
| 6582 | 'int'のサイズに依存します。 | |
| 6583 | また、下記の 'long' より大きい可能性もあります) | |
| 10635 | 6584 | |
| 10636 | ||
| 6585 | l signed long 値 | |
| 6586 | L unsigned long 値 | |
| 6587 | (ここでの 'long' は「正確に」32 ビットです。これは | |
| 6588 | ローカルの C コンパイラの 'long' のサイズとは違うかもしれません。 | |
| 6589 | ネイティブな長さの 'long' が必要な場合は、'!' 前置詞を使ってください) | |
| 10637 | 6590 | |
| 10638 | | |
| 6591 | n "network" 順序 (ビッグエンディアン) の unsigned short | |
| 10639 | | |
| 6592 | N "network" 順序 (ビッグエンディアン) の unsigned long | |
| 6593 | v "VAX" 順序 (リトルエンディアン) の unsigned short | |
| 6594 | V "VAX" 順序 (リトルエンディアン) の unsigned long | |
| 6595 | (これらの 'short' と 'long' は「正確に」それぞれ 16 ビットと | |
| 6596 | 32 ビットす) | |
| 10640 | 6597 | |
| 10641 | ||
| 6598 | q 符号付き 64 ビット整数 | |
| 6599 | Q 符号なし 64 ビット整数 | |
| 6600 | (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が | |
| 6601 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 | |
| 6602 | それ以外の場合は致命的エラーが発生します。) | |
| 10642 | 6603 | |
| 10643 | | |
| 6604 | f 機種依存の単精度浮動小数点数 | |
| 10644 | | |
| 6605 | d 機種依存の倍精度浮動小数点数 | |
| 10645 | 6606 | |
| 10646 | ||
| 6607 | p ヌル文字で終端する文字列へのポインタ | |
| 6608 | P 構造体 (固定長文字列) へのポインタ | |
| 10647 | 6609 | |
| 10648 | | |
| 6610 | u uuencode 文字列 | |
| 10649 | | |
| 6611 | U Unicode 文字番号。内部的に UTF-8 にエンコードされます。 | |
| 10650 | ||
| 6612 | C<use utf8> が有効でなくても動作します。 | |
| 10651 | integer values _and_ if Perl has been compiled to support | |
| 10652 | those. Raises an exception otherwise.) | |
| 10653 | 6613 | |
| 10654 | ||
| 6614 | w A BER 圧縮変数。このバイト列はできるだけ少ない桁数で表現された | |
| 6615 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 | |
| 6616 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 | |
| 10655 | 6617 | |
| 10656 | | |
| 6618 | x ヌル文字 | |
| 10657 | | |
| 6619 | X 1 文字後退 | |
| 10658 | | |
| 6620 | @ 絶対位置までヌル文字で埋める | |
| 10659 | 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。 | |
| 10660 | それ以外の場合は例外が発生します。) | |
| 10661 | 6621 | |
| 10662 | 6622 | =begin original |
| 10663 | 6623 | |
| 10664 | i A signed integer value. | |
| 10665 | I An unsigned integer value. | |
| 10666 | (This 'integer' is _at_least_ 32 bits wide. Its exact | |
| 10667 | size depends on what a local C compiler calls 'int'.) | |
| 10668 | ||
| 10669 | =end original | |
| 10670 | ||
| 10671 | i signed int 値。 | |
| 10672 | I unsigned int 値。 | |
| 10673 | (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは | |
| 10674 | ローカルの C コンパイラの 'int' のサイズに依存します。) | |
| 10675 | ||
| 10676 | =begin original | |
| 10677 | ||
| 10678 | n An unsigned short (16-bit) in "network" (big-endian) order. | |
| 10679 | N An unsigned long (32-bit) in "network" (big-endian) order. | |
| 10680 | v An unsigned short (16-bit) in "VAX" (little-endian) order. | |
| 10681 | V An unsigned long (32-bit) in "VAX" (little-endian) order. | |
| 10682 | ||
| 10683 | =end original | |
| 10684 | ||
| 10685 | n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。 | |
| 10686 | N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。 | |
| 10687 | v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。 | |
| 10688 | V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。 | |
| 10689 | ||
| 10690 | =begin original | |
| 10691 | ||
| 10692 | j A Perl internal signed integer value (IV). | |
| 10693 | J A Perl internal unsigned integer value (UV). | |
| 10694 | ||
| 10695 | =end original | |
| 10696 | ||
| 10697 | j Perl 内部符号付き整数 (IV)。 | |
| 10698 | J Perl 内部符号なし整数 (UV)。 | |
| 10699 | ||
| 10700 | =begin original | |
| 10701 | ||
| 10702 | f A single-precision float in native format. | |
| 10703 | d A double-precision float in native format. | |
| 10704 | ||
| 10705 | =end original | |
| 10706 | ||
| 10707 | f 機種依存の単精度浮動小数点数。 | |
| 10708 | d 機種依存の倍精度浮動小数点数。 | |
| 10709 | ||
| 10710 | =begin original | |
| 10711 | ||
| 10712 | F A Perl internal floating-point value (NV) in native format | |
| 10713 | D A float of long-double precision in native format. | |
| 10714 | (Long doubles are available only if your system supports | |
| 10715 | long double values _and_ if Perl has been compiled to | |
| 10716 | support those. Raises an exception otherwise. | |
| 10717 | Note that there are different long double formats.) | |
| 10718 | ||
| 10719 | =end original | |
| 10720 | ||
| 10721 | F ネイティブフォーマットの Perl 内部浮動小数点数 (NV) | |
| 10722 | D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。 | |
| 10723 | (long double は、システムが long double に対応していて、かつ Perl が | |
| 10724 | long double 対応としてコンパイルされている場合にのみ使用可能です。 | |
| 10725 | それ以外の場合は例外が発生します。 | |
| 10726 | long double 型式の場合は異なることに注意してください) | |
| 10727 | ||
| 10728 | =begin original | |
| 10729 | ||
| 10730 | p A pointer to a null-terminated string. | |
| 10731 | P A pointer to a structure (fixed-length string). | |
| 10732 | ||
| 10733 | =end original | |
| 10734 | ||
| 10735 | p ヌル文字で終端する文字列へのポインタ。 | |
| 10736 | P 構造体 (固定長文字列) へのポインタ。 | |
| 10737 | ||
| 10738 | =begin original | |
| 10739 | ||
| 10740 | u A uuencoded string. | |
| 10741 | U A Unicode character number. Encodes to a character in char- | |
| 10742 | acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in | |
| 10743 | byte mode. | |
| 10744 | ||
| 10745 | =end original | |
| 10746 | ||
| 10747 | u uuencode 文字列。 | |
| 10748 | U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に | |
| 10749 | (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。 | |
| 10750 | ||
| 10751 | =begin original | |
| 10752 | ||
| 10753 | w A BER compressed integer (not an ASN.1 BER, see perlpacktut | |
| 10754 | for details). Its bytes represent an unsigned integer in | |
| 10755 | base 128, most significant digit first, with as few digits | |
| 10756 | as possible. Bit eight (the high bit) is set on each byte | |
| 10757 | except the last. | |
| 10758 | ||
| 10759 | =end original | |
| 10760 | ||
| 10761 | w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を | |
| 10762 | 参照してください)。このバイト列はできるだけ少ない桁数で表現された | |
| 10763 | 128 を基とした符号なし整数で、最上位ビットから順に並びます。 | |
| 10764 | 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。 | |
| 10765 | ||
| 10766 | =begin original | |
| 10767 | ||
| 10768 | x A null byte (a.k.a ASCII NUL, "\000", chr(0)) | |
| 10769 | X Back up a byte. | |
| 10770 | @ Null-fill or truncate to absolute position, counted from the | |
| 10771 | start of the innermost ()-group. | |
| 10772 | . Null-fill or truncate to absolute position specified by | |
| 10773 | the value. | |
| 10774 | ( Start of a ()-group. | |
| 10775 | ||
| 10776 | =end original | |
| 10777 | ||
| 10778 | x ヌル文字 (つまり ASCII NUL, "\000", chr(0)) | |
| 10779 | X 1 文字後退。 | |
| 10780 | @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で | |
| 10781 | 埋めるか切り詰める。 | |
| 10782 | . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。 | |
| 10783 | ( () の組の開始。 | |
| 10784 | ||
| 10785 | =begin original | |
| 10786 | ||
| 10787 | One or more modifiers below may optionally follow certain letters in the | |
| 10788 | TEMPLATE (the second column lists letters for which the modifier is valid): | |
| 10789 | ||
| 10790 | =end original | |
| 10791 | ||
| 10792 | 以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで | |
| 10793 | 付けることができます(表の 2 列目は、その修飾子が有効な文字です): | |
| 10794 | ||
| 10795 | =begin original | |
| 10796 | ||
| 10797 | ! sSlLiI Forces native (short, long, int) sizes instead | |
| 10798 | of fixed (16-/32-bit) sizes. | |
| 10799 | ||
| 10800 | =end original | |
| 10801 | ||
| 10802 | ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな | |
| 10803 | (short, long, int)サイズを強制する。 | |
| 10804 | ||
| 10805 | =begin original | |
| 10806 | ||
| 10807 | ! xX Make x and X act as alignment commands. | |
| 10808 | ||
| 10809 | =end original | |
| 10810 | ||
| 10811 | ! xX x と X をアライメントコマンドとして振舞わせる。 | |
| 10812 | ||
| 10813 | =begin original | |
| 10814 | ||
| 10815 | ! nNvV Treat integers as signed instead of unsigned. | |
| 10816 | ||
| 10817 | =end original | |
| 10818 | ||
| 10819 | ! nNvV 整数を符号なしではなく符号付きとして扱わせる。 | |
| 10820 | ||
| 10821 | =begin original | |
| 10822 | ||
| 10823 | ! @. Specify position as byte offset in the internal | |
| 10824 | representation of the packed string. Efficient | |
| 10825 | but dangerous. | |
| 10826 | ||
| 10827 | =end original | |
| 10828 | ||
| 10829 | ! @. pack された内部表現のバイトオフセットとして位置を指定する。 | |
| 10830 | 効率的ですが危険です。 | |
| 10831 | ||
| 10832 | =begin original | |
| 10833 | ||
| 10834 | > sSiIlLqQ Force big-endian byte-order on the type. | |
| 10835 | jJfFdDpP (The "big end" touches the construct.) | |
| 10836 | ||
| 10837 | =end original | |
| 10838 | ||
| 10839 | > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。 | |
| 10840 | jJfFdDpP (「大きい端」が構造に触れています。) | |
| 10841 | ||
| 10842 | =begin original | |
| 10843 | ||
| 10844 | < sSiIlLqQ Force little-endian byte-order on the type. | |
| 10845 | jJfFdDpP (The "little end" touches the construct.) | |
| 10846 | ||
| 10847 | =end original | |
| 10848 | ||
| 10849 | < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。 | |
| 10850 | jJfFdDpP (「小さい端」が構造に触れています。) | |
| 10851 | ||
| 10852 | =begin original | |
| 10853 | ||
| 10854 | The C<< > >> and C<< < >> modifiers can also be used on C<()> groups | |
| 10855 | to force a particular byte-order on all components in that group, | |
| 10856 | including all its subgroups. | |
| 10857 | ||
| 10858 | =end original | |
| 10859 | ||
| 10860 | C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます; | |
| 10861 | この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に | |
| 10862 | 強制します。 | |
| 10863 | ||
| 10864 | =begin comment | |
| 10865 | ||
| 10866 | Larry recalls that the hex and bit string formats (H, h, B, b) were added to | |
| 10867 | pack for processing data from NASA's Magellan probe. Magellan was in an | |
| 10868 | elliptical orbit, using the antenna for the radar mapping when close to | |
| 10869 | Venus and for communicating data back to Earth for the rest of the orbit. | |
| 10870 | There were two transmission units, but one of these failed, and then the | |
| 10871 | other developed a fault whereby it would randomly flip the sense of all the | |
| 10872 | bits. It was easy to automatically detect complete records with the correct | |
| 10873 | sense, and complete records with all the bits flipped. However, this didn't | |
| 10874 | recover the records where the sense flipped midway. A colleague of Larry's | |
| 10875 | was able to pretty much eyeball where the records flipped, so they wrote an | |
| 10876 | editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to | |
| 10877 | manually correct the records and recover the data. For this purpose pack | |
| 10878 | gained the hex and bit string format specifiers. | |
| 10879 | ||
| 10880 | git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit | |
| 10881 | 27e2fb84680b9cc1), but the patch description makes no mention of their | |
| 10882 | addition, let alone the story behind them. | |
| 10883 | ||
| 10884 | =end comment | |
| 10885 | ||
| 10886 | =begin original | |
| 10887 | ||
| 10888 | 6624 | The following rules apply: |
| 10889 | 6625 | |
| 10890 | 6626 | =end original |
| 10891 | 6627 | |
| 10892 | 6628 | 以下の条件が適用されます: |
| 10893 | 6629 | |
| 10894 | =over | |
| 6630 | =over 8 | |
| 10895 | 6631 | |
| 10896 | 6632 | =item * |
| 10897 | 6633 | |
| 10898 | 6634 | =begin original |
| 10899 | 6635 | |
| 10900 | Each letter may optionally be followed by a number i | |
| 6636 | Each letter may optionally be followed by a number giving a repeat | |
| 10901 | count. | |
| 6637 | count. With all types except C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, | |
| 10902 | ||
| 6638 | C<H>, and C<P> the pack function will gobble up that many values from | |
| 10903 | the LIST | |
| 6639 | the LIST. A C<*> for the repeat count means to use however many items are | |
| 10904 | ||
| 6640 | left, except for C<@>, C<x>, C<X>, where it is equivalent | |
| 10905 | ||
| 6641 | to C<0>, and C<u>, where it is equivalent to 1 (or 45, what is the | |
| 10906 | ||
| 6642 | same). | |
| 10907 | 6643 | |
| 10908 | 6644 | =end original |
| 10909 | 6645 | |
| 10910 | 6646 | これらの文字の後には、繰り返し数を示す数字を付けることができます。 |
| 10911 | ||
| 6647 | C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<P> 以外の全ての型では、 | |
| 10912 | ||
| 6648 | LIST からその数の値を取り出して使います。 | |
| 10913 | ||
| 6649 | くり返し数に C<*> を指定すると、その時点で残っているすべての要素を意味します。 | |
| 10914 | ||
| 6650 | ただし、C<@>, C<x>, C<X>では C<0> と C<u> と等価で、 | |
| 10915 | ||
| 6651 | 1 (あるいは 45 でも同じ) と等価です。 | |
| 10916 | その時点で残っているすべての要素を意味します。 | |
| 10917 | 6652 | |
| 10918 | =over | |
| 10919 | ||
| 10920 | =item * | |
| 10921 | ||
| 10922 | 6653 | =begin original |
| 10923 | 6654 | |
| 10924 | ||
| 6655 | When used with C<Z>, C<*> results in the addition of a trailing null | |
| 6656 | byte (so the packed result will be one longer than the byte C<length> | |
| 6657 | of the item). | |
| 10925 | 6658 | |
| 10926 | 6659 | =end original |
| 10927 | 6660 | |
| 10928 | C< | |
| 6661 | C<*> が C<Z> と共に使われた場合、末尾にヌルバイトをつけます | |
| 6662 | (従ってパックされた結果は要素の C<length> の値より 1 大きくなります)。 | |
| 10929 | 6663 | |
| 10930 | =item * | |
| 10931 | ||
| 10932 | 6664 | =begin original |
| 10933 | 6665 | |
| 10934 | <.>, where it means relative to the start of the string. | |
| 10935 | ||
| 10936 | =end original | |
| 10937 | ||
| 10938 | <.> では文字列の先頭からの相対位置を意味します。 | |
| 10939 | ||
| 10940 | =item * | |
| 10941 | ||
| 10942 | =begin original | |
| 10943 | ||
| 10944 | C<u>, where it is equivalent to 1 (or 45, which here is equivalent). | |
| 10945 | ||
| 10946 | =end original | |
| 10947 | ||
| 10948 | C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。 | |
| 10949 | ||
| 10950 | =back | |
| 10951 | ||
| 10952 | =begin original | |
| 10953 | ||
| 10954 | One can replace a numeric repeat count with a template letter enclosed in | |
| 10955 | brackets to use the packed byte length of the bracketed template for the | |
| 10956 | repeat count. | |
| 10957 | ||
| 10958 | =end original | |
| 10959 | ||
| 10960 | このテンプレートでパックされたバイト長を繰り返し数として使うために、 | |
| 10961 | 大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが | |
| 10962 | できます。 | |
| 10963 | ||
| 10964 | =begin original | |
| 10965 | ||
| 10966 | For example, the template C<x[L]> skips as many bytes as in a packed long, | |
| 10967 | and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when | |
| 10968 | variable-expanded) unpacks. If the template in brackets contains alignment | |
| 10969 | commands (such as C<x![d]>), its packed length is calculated as if the | |
| 10970 | start of the template had the maximal possible alignment. | |
| 10971 | ||
| 10972 | =end original | |
| 10973 | ||
| 10974 | 例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、 | |
| 10975 | テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を | |
| 10976 | unpack したものの 2 倍を unpack します。 | |
| 10977 | (C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、 | |
| 10978 | パックされた長さは、テンプレートの先頭で最大限可能なアライメントを | |
| 10979 | 持っているものとして計算されます。 | |
| 10980 | ||
| 10981 | =begin original | |
| 10982 | ||
| 10983 | When used with C<Z>, a C<*> as the repeat count is guaranteed to add a | |
| 10984 | trailing null byte, so the resulting string is always one byte longer than | |
| 10985 | the byte length of the item itself. | |
| 10986 | ||
| 10987 | =end original | |
| 10988 | ||
| 10989 | C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが | |
| 10990 | 保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト | |
| 10991 | 長くなります。 | |
| 10992 | ||
| 10993 | =begin original | |
| 10994 | ||
| 10995 | When used with C<@>, the repeat count represents an offset from the start | |
| 10996 | of the innermost C<()> group. | |
| 10997 | ||
| 10998 | =end original | |
| 10999 | ||
| 11000 | C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを | |
| 11001 | 表現します。 | |
| 11002 | ||
| 11003 | =begin original | |
| 11004 | ||
| 11005 | When used with C<.>, the repeat count determines the starting position to | |
| 11006 | calculate the value offset as follows: | |
| 11007 | ||
| 11008 | =end original | |
| 11009 | ||
| 11010 | C<.> で使われると、繰り返し数は以下のようにして、 | |
| 11011 | 値のオフセットを計算するための開始位置を決定するために使われます。 | |
| 11012 | ||
| 11013 | =over | |
| 11014 | ||
| 11015 | =item * | |
| 11016 | ||
| 11017 | =begin original | |
| 11018 | ||
| 11019 | If the repeat count is C<0>, it's relative to the current position. | |
| 11020 | ||
| 11021 | =end original | |
| 11022 | ||
| 11023 | 繰り返し数が C<0> なら、現在位置からの相対位置となります。 | |
| 11024 | ||
| 11025 | =item * | |
| 11026 | ||
| 11027 | =begin original | |
| 11028 | ||
| 11029 | If the repeat count is C<*>, the offset is relative to the start of the | |
| 11030 | packed string. | |
| 11031 | ||
| 11032 | =end original | |
| 11033 | ||
| 11034 | 繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの | |
| 11035 | 相対位置です。 | |
| 11036 | ||
| 11037 | =item * | |
| 11038 | ||
| 11039 | =begin original | |
| 11040 | ||
| 11041 | And if it's an integer I<n>, the offset is relative to the start of the | |
| 11042 | I<n>th innermost C<( )> group, or to the start of the string if I<n> is | |
| 11043 | bigger then the group level. | |
| 11044 | ||
| 11045 | =end original | |
| 11046 | ||
| 11047 | そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの | |
| 11048 | 先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの | |
| 11049 | 相対位置です。 | |
| 11050 | ||
| 11051 | =back | |
| 11052 | ||
| 11053 | =begin original | |
| 11054 | ||
| 11055 | 6666 | The repeat count for C<u> is interpreted as the maximal number of bytes |
| 11056 | to encode per line of output, with 0 | |
| 6667 | to encode per line of output, with 0 and 1 replaced by 45. | |
| 11057 | count should not be more than 65. | |
| 11058 | 6668 | |
| 11059 | 6669 | =end original |
| 11060 | 6670 | |
| 11061 | 6671 | C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを |
| 11062 | 示します | |
| 6672 | 示します。0 と 1 は 45 として扱われます。 | |
| 11063 | 繰り返し数は 65 を超えてはなりません。 | |
| 11064 | 6673 | |
| 11065 | 6674 | =item * |
| 11066 | 6675 | |
| 11067 | 6676 | =begin original |
| 11068 | 6677 | |
| 11069 | 6678 | The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a |
| 11070 | string of length count, padding with nulls or spaces as nee | |
| 6679 | string of length count, padding with nulls or spaces as necessary. When | |
| 11071 | unpacking, C<A> strips trailing | |
| 6680 | unpacking, C<A> strips trailing spaces and nulls, C<Z> strips everything | |
| 11072 | after the first null, and C<a> returns data | |
| 6681 | after the first null, and C<a> returns data verbatim. When packing, | |
| 6682 | C<a>, and C<Z> are equivalent. | |
| 11073 | 6683 | |
| 11074 | 6684 | =end original |
| 11075 | 6685 | |
| 11076 | 6686 | C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、 |
| 11077 | 6687 | 繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か |
| 11078 | 6688 | スペース文字を付け足します。 |
| 11079 | unpack するとき、C<A> は後続の | |
| 6689 | unpack するとき、C<A> は後続のスペース文字やヌル文字を取り除きます。 | |
| 11080 | ヌル文字以降の全てを取り除きます | |
| 6690 | C<Z>は最初のヌル文字以降の全てを取り除きます。 | |
| 11081 | そのまま返します。 | |
| 6691 | C<a>はデータをそのまま返します。 | |
| 6692 | pack するときは、 C<a> と C<Z> は等価です。 | |
| 11082 | 6693 | |
| 11083 | 6694 | =begin original |
| 11084 | 6695 | |
| 11085 | If the value | |
| 6696 | If the value-to-pack is too long, it is truncated. If too long and an | |
| 11086 | ||
| 6697 | explicit count is provided, C<Z> packs only C<$count-1> bytes, followed | |
| 11087 | ||
| 6698 | by a null byte. Thus C<Z> always packs a trailing null byte under | |
| 11088 | ||
| 6699 | all circumstances. | |
| 11089 | 6700 | |
| 11090 | 6701 | =end original |
| 11091 | 6702 | |
| 11092 | pack する値が長すぎる場合、 | |
| 6703 | pack する値が長すぎる場合、切り詰められます。 | |
| 11093 | 6704 | 長すぎてかつ明示的に個数が指定されている場合、 |
| 11094 | 6705 | C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。 |
| 11095 | 従って、C<Z> は | |
| 6706 | 従って、C<Z> はどのような状態でも常に末尾にヌルバイトがつきます。 | |
| 11096 | つきます。 | |
| 11097 | 6707 | |
| 11098 | 6708 | =item * |
| 11099 | 6709 | |
| 11100 | 6710 | =begin original |
| 11101 | 6711 | |
| 11102 | Likewise, the C<b> and C<B> f | |
| 6712 | Likewise, the C<b> and C<B> fields pack a string that many bits long. | |
| 11103 | Each | |
| 6713 | Each byte of the input field of pack() generates 1 bit of the result. | |
| 11104 | b | |
| 6714 | Each result bit is based on the least-significant bit of the corresponding | |
| 6715 | input byte, i.e., on C<ord($byte)%2>. In particular, bytes C<"0"> and | |
| 6716 | C<"1"> generate bits 0 and 1, as do bytes C<"\0"> and C<"\1">. | |
| 11105 | 6717 | |
| 11106 | 6718 | =end original |
| 11107 | 6719 | |
| 11108 | 6720 | 同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。 |
| 11109 | ||
| 6721 | pack() の入力フィールドの各バイトは結果の 1 ビットを生成します。 | |
| 11110 | ||
| 6722 | 結果ビットのそれぞれは対応する入力バイトの最下位ビットを基にします | |
| 6723 | (つまり C<ord($byte)%2>)。 | |
| 6724 | 特に、バイト C<"0"> と C<"1"> は | |
| 6725 | バイト C<"\0"> と C<"\1"> と同様に、ビット 0 と 1 を生成します。 | |
| 11111 | 6726 | |
| 11112 | 6727 | =begin original |
| 11113 | 6728 | |
| 11114 | ||
| 6729 | Starting from the beginning of the input string of pack(), each 8-tuple | |
| 11115 | ||
| 6730 | of bytes is converted to 1 byte of output. With format C<b> | |
| 11116 | ||
| 6731 | the first byte of the 8-tuple determines the least-significant bit of a | |
| 6732 | byte, and with format C<B> it determines the most-significant bit of | |
| 6733 | a byte. | |
| 11117 | 6734 | |
| 11118 | 6735 | =end original |
| 11119 | 6736 | |
| 11120 | ||
| 6737 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 バイトの出力に | |
| 11121 | ||
| 6738 | 変換されます。 | |
| 11122 | ||
| 6739 | C<b> フォーマットでは 8 タプルの最初のバイトが出力の最下位ビットとなり、 | |
| 11123 | ビット 0 と 1 を生成します。 | |
| 11124 | ||
| 11125 | =begin original | |
| 11126 | ||
| 11127 | Starting from the beginning of the input string, each 8-tuple | |
| 11128 | of characters is converted to 1 character of output. With format C<b>, | |
| 11129 | the first character of the 8-tuple determines the least-significant bit of a | |
| 11130 | character; with format C<B>, it determines the most-significant bit of | |
| 11131 | a character. | |
| 11132 | ||
| 11133 | =end original | |
| 11134 | ||
| 11135 | pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。 | |
| 11136 | C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります; | |
| 11137 | 6740 | C<B> フォーマットでは出力の最上位ビットとなります。 |
| 11138 | 6741 | |
| 11139 | 6742 | =begin original |
| 11140 | 6743 | |
| 11141 | If the length of the input string is not e | |
| 6744 | If the length of the input string is not exactly divisible by 8, the | |
| 11142 | remainder is packed as if the input string were padded by null | |
| 6745 | remainder is packed as if the input string were padded by null bytes | |
| 11143 | at the end. Similarly during unpacking | |
| 6746 | at the end. Similarly, during unpack()ing the "extra" bits are ignored. | |
| 11144 | 6747 | |
| 11145 | 6748 | =end original |
| 11146 | 6749 | |
| 11147 | 6750 | もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の |
| 11148 | 最後にヌル | |
| 6751 | 最後にヌルバイトがパッディングされているものとしてパックされます。 | |
| 11149 | 同様に、unpack 中は「余分な」ビットは無視されます。 | |
| 6752 | 同様に、unpack() 中は「余分な」ビットは無視されます。 | |
| 11150 | 6753 | |
| 11151 | 6754 | =begin original |
| 11152 | 6755 | |
| 11153 | If the input string is longer than needed, | |
| 6756 | If the input string of pack() is longer than needed, extra bytes are ignored. | |
| 6757 | A C<*> for the repeat count of pack() means to use all the bytes of | |
| 6758 | the input field. On unpack()ing the bits are converted to a string | |
| 6759 | of C<"0">s and C<"1">s. | |
| 11154 | 6760 | |
| 11155 | 6761 | =end original |
| 11156 | 6762 | |
| 11157 | 入力文字列が必要な分よりも長い場合、余分な | |
| 6763 | pack() の入力文字列が必要な分よりも長い場合、余分な部分は無視されます。 | |
| 6764 | pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての | |
| 6765 | バイト列がが使われます。 | |
| 6766 | unpack() 時にはビット列は C<"0"> と C<"1"> の文字列に変換されます。 | |
| 11158 | 6767 | |
| 11159 | =begin original | |
| 11160 | ||
| 11161 | A C<*> for the repeat count uses all characters of the input field. | |
| 11162 | On unpacking, bits are converted to a string of C<0>s and C<1>s. | |
| 11163 | ||
| 11164 | =end original | |
| 11165 | ||
| 11166 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
| 11167 | unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。 | |
| 11168 | ||
| 11169 | 6768 | =item * |
| 11170 | 6769 | |
| 11171 | 6770 | =begin original |
| 11172 | 6771 | |
| 11173 | The C<h> and C<H> f | |
| 6772 | The C<h> and C<H> fields pack a string that many nybbles (4-bit groups, | |
| 11174 | representable as hexadecimal digits, | |
| 6773 | representable as hexadecimal digits, 0-9a-f) long. | |
| 11175 | 6774 | |
| 11176 | 6775 | =end original |
| 11177 | 6776 | |
| 11178 | C<h> や C<H> は、多ニブル長(16 進文字である | |
| 6777 | C<h> や C<H> は、多ニブル長(16 進文字である 0-9a-f で表現可能な | |
| 11179 | ||
| 6778 | 4 ビットグループ)のニブル列に pack します。 | |
| 11180 | 6779 | |
| 11181 | 6780 | =begin original |
| 11182 | 6781 | |
| 11183 | ||
| 6782 | Each byte of the input field of pack() generates 4 bits of the result. | |
| 11184 | ||
| 6783 | For non-alphabetical bytes the result is based on the 4 least-significant | |
| 11185 | bits of the input | |
| 6784 | bits of the input byte, i.e., on C<ord($byte)%16>. In particular, | |
| 11186 | ||
| 6785 | bytes C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes | |
| 11187 | C<"\0 | |
| 6786 | C<"\0"> and C<"\1">. For bytes C<"a".."f"> and C<"A".."F"> the result | |
| 11188 | 6787 | is compatible with the usual hexadecimal digits, so that C<"a"> and |
| 11189 | C<"A"> both generate the nybble C<0x | |
| 6788 | C<"A"> both generate the nybble C<0xa==10>. The result for bytes | |
| 11190 | ||
| 6789 | C<"g".."z"> and C<"G".."Z"> is not well-defined. | |
| 11191 | 6790 | |
| 11192 | 6791 | =end original |
| 11193 | 6792 | |
| 11194 | ||
| 6793 | pack() の入力フィールドの各バイトは結果の 4 ビットを生成します。 | |
| 11195 | 結果の 4 ビットを | |
| 6794 | 英字でないバイトの場合、結果は入力バイトの下位 4 ビットを | |
| 11196 | ||
| 6795 | 基にします(つまり C<ord($byte)%16>)。 | |
| 11197 | ||
| 6796 | 特に、バイト C<"0"> と C<"1"> はバイト C<"\0"> と C<"\1"> と同様に | |
| 11198 | 特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に | |
| 11199 | 6797 | ニブル 0 と 1 を生成します。 |
| 11200 | ||
| 6798 | バイト C<"a".."f"> と C<"A".."F"> の場合は結果は通常の | |
| 11201 | な | |
| 6799 | 16 進数と同じ結果になりますので、C<"a"> と C<"A"> はどちらも | |
| 11202 | ||
| 6800 | ニブル C<0xa==10> を生成します。 | |
| 6801 | バイト C<"g".."z"> と C<"G".."Z"> に対する結果は未定義です。 | |
| 11203 | 6802 | |
| 11204 | 6803 | =begin original |
| 11205 | 6804 | |
| 11206 | Starting from the beginning of the | |
| 6805 | Starting from the beginning of the input string of pack(), each pair | |
| 11207 | ||
| 6806 | of bytes is converted to 1 byte of output. With format C<h> the | |
| 11208 | ||
| 6807 | first byte of the pair determines the least-significant nybble of the | |
| 11209 | ||
| 6808 | output byte, and with format C<H> it determines the most-significant | |
| 11210 | output character; with format C<H>, it determines the most-significant | |
| 11211 | 6809 | nybble. |
| 11212 | 6810 | |
| 11213 | 6811 | =end original |
| 11214 | 6812 | |
| 11215 | ||
| 6813 | pack() の入力文字列の先頭から始めて、2 バイト毎に 1 バイトの出力に | |
| 11216 | ||
| 6814 | 変換されます。 | |
| 11217 | C<h> フォーマットでは 1 | |
| 6815 | C<h> フォーマットでは 1 バイト目が出力の最下位ニブルとなり、 | |
| 11218 | 6816 | C<H> フォーマットでは出力の最上位ニブルとなります。 |
| 11219 | 6817 | |
| 11220 | 6818 | =begin original |
| 11221 | 6819 | |
| 11222 | If the length of the input string is not even, it behaves as if padded | |
| 6820 | If the length of the input string is not even, it behaves as if padded | |
| 11223 | a null | |
| 6821 | by a null byte at the end. Similarly, during unpack()ing the "extra" | |
| 11224 | ||
| 6822 | nybbles are ignored. | |
| 11225 | 6823 | |
| 11226 | 6824 | =end original |
| 11227 | 6825 | |
| 11228 | 入力文字列の長さが偶数でない場合、最後にヌル | |
| 6826 | 入力文字列の長さが偶数でない場合、最後にヌルバイトでパッディングされて | |
| 11229 | 6827 | いるかのように振る舞います。 |
| 11230 | 同様に、unpack 中は「余分な」ニブルは無視されます。 | |
| 6828 | 同様に、unpack() 中は「余分な」ニブルは無視されます。 | |
| 11231 | 6829 | |
| 11232 | 6830 | =begin original |
| 11233 | 6831 | |
| 11234 | If the input string is longer than needed, extra | |
| 6832 | If the input string of pack() is longer than needed, extra bytes are ignored. | |
| 6833 | A C<*> for the repeat count of pack() means to use all the bytes of | |
| 6834 | the input field. On unpack()ing the bits are converted to a string | |
| 6835 | of hexadecimal digits. | |
| 11235 | 6836 | |
| 11236 | 6837 | =end original |
| 11237 | 6838 | |
| 11238 | 入力文字列が必要な分より長い場合、余分な部分は無視されます。 | |
| 6839 | pack() の入力文字列が必要な分より長い場合、余分な部分は無視されます。 | |
| 6840 | pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての | |
| 6841 | バイト列がが使われます。 | |
| 6842 | unpack() 時にはビット列は 16 進数の文字列に変換されます。 | |
| 11239 | 6843 | |
| 11240 | =begin original | |
| 11241 | ||
| 11242 | A C<*> for the repeat count uses all characters of the input field. For | |
| 11243 | L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of | |
| 11244 | hexadecimal digits. | |
| 11245 | ||
| 11246 | =end original | |
| 11247 | ||
| 11248 | 繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。 | |
| 11249 | L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に | |
| 11250 | 変換されます。 | |
| 11251 | ||
| 11252 | 6844 | =item * |
| 11253 | 6845 | |
| 11254 | 6846 | =begin original |
| 11255 | 6847 | |
| 11256 | The C<p> | |
| 6848 | The C<p> type packs a pointer to a null-terminated string. You are | |
| 11257 | responsible for ensuring th | |
| 6849 | responsible for ensuring the string is not a temporary value (which can | |
| 11258 | ||
| 6850 | potentially get deallocated before you get around to using the packed result). | |
| 11259 | ||
| 6851 | The C<P> type packs a pointer to a structure of the size indicated by the | |
| 11260 | ||
| 6852 | length. A NULL pointer is created if the corresponding value for C<p> or | |
| 11261 | C< | |
| 6853 | C<P> is C<undef>, similarly for unpack(). | |
| 11262 | L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into | |
| 11263 | L<C<undef>|/undef EXPR>. | |
| 11264 | 6854 | |
| 11265 | 6855 | =end original |
| 11266 | 6856 | |
| 11267 | C<p> | |
| 6857 | C<p>は、ヌル文字終端文字列へのポインタを pack します。 | |
| 11268 | 6858 | 文字列が一時的な値でない(つまり pack された結果を使う前に文字列が |
| 11269 | 解放されない) ことに責任を持つ必要があります | |
| 6859 | 解放されない) ことに責任を持つ必要があります | |
| 11270 | 6860 | C<P> は、指定した長さの構造体へのポインタを pack します。 |
| 11271 | C<p> | |
| 6861 | C<p>またはC<P>に対応する値が C<undef> だった場合、 | |
| 11272 | ヌルポインタが作成されます | |
| 6862 | unpack() と同様にヌルポインタが作成されます。 | |
| 11273 | unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。 | |
| 11274 | 6863 | |
| 11275 | =begin original | |
| 11276 | ||
| 11277 | If your system has a strange pointer size--meaning a pointer is neither as | |
| 11278 | big as an int nor as big as a long--it may not be possible to pack or | |
| 11279 | unpack pointers in big- or little-endian byte order. Attempting to do | |
| 11280 | so raises an exception. | |
| 11281 | ||
| 11282 | =end original | |
| 11283 | ||
| 11284 | システムのポインタが変わったサイズの場合--つまり、int の大きさでも | |
| 11285 | long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの | |
| 11286 | バイト順で pack や unpack することはできません。 | |
| 11287 | そうしようとすると例外が発生します。 | |
| 11288 | ||
| 11289 | 6864 | =item * |
| 11290 | 6865 | |
| 11291 | 6866 | =begin original |
| 11292 | 6867 | |
| 11293 | The C</> template character allows packing and unpacking of | |
| 6868 | The C</> template character allows packing and unpacking of strings where | |
| 11294 | ||
| 6869 | the packed structure contains a byte count followed by the string itself. | |
| 11295 | ||
| 6870 | You write I<length-item>C</>I<string-item>. | |
| 11296 | unpacking has encoded the sizes or repeat counts for some of its fields | |
| 11297 | within the structure itself as separate fields. | |
| 11298 | 6871 | |
| 11299 | 6872 | =end original |
| 11300 | 6873 | |
| 11301 | C</> テンプレート文字は、 | |
| 6874 | C</> テンプレート文字は、文字列の長さを示すバイト列の後に | |
| 11302 | ||
| 6875 | 文字列そのものが入っている形の文字列を pack 及び unpack します。 | |
| 11303 | ||
| 6876 | I<length-item>C</>I<string-item> の形になります。 | |
| 11304 | 独立したフィールドとしてエンコードされている場合に有効です。 | |
| 11305 | 6877 | |
| 11306 | 6878 | =begin original |
| 11307 | 6879 | |
| 11308 | ||
| 6880 | The I<length-item> can be any C<pack> template letter, | |
| 11309 | ||
| 6881 | and describes how the length value is packed. | |
| 11310 | ||
| 6882 | The ones likely to be of most use are integer-packing ones like | |
| 11311 | ||
| 6883 | C<n> (for Java strings), C<w> (for ASN.1 or SNMP) | |
| 11312 | ||
| 6884 | and C<N> (for Sun XDR). | |
| 11313 | 6885 | |
| 11314 | 6886 | =end original |
| 11315 | 6887 | |
| 11316 | ||
| 6888 | I<length-item> には任意の C<pack> テンプレート文字が利用でき、 | |
| 11317 | ||
| 6889 | 長さの値がどのようにパックされているかを指定します。 | |
| 11318 | ||
| 6890 | もっともよく使われるのは C<n>(Java 文字列), C<w>(SNMP), C<N>(Sun XDR) と | |
| 11319 | ||
| 6891 | いった整数型です。 | |
| 11320 | C<w>、Sun XDR のための C<N> といった整数型です。 | |
| 11321 | 6892 | |
| 11322 | 6893 | =begin original |
| 11323 | 6894 | |
| 11324 | ||
| 6895 | The I<string-item> must, at present, be C<"A*">, C<"a*"> or C<"Z*">. | |
| 11325 | ||
| 6896 | For C<unpack> the length of the string is obtained from the I<length-item>, | |
| 11326 | t | |
| 6897 | but if you put in the '*' it will be ignored. | |
| 11327 | for I<length-item>. If it has no repeat count or uses a '*', the number | |
| 11328 | of available items is used. | |
| 11329 | 6898 | |
| 11330 | 6899 | =end original |
| 11331 | 6900 | |
| 11332 | ||
| 6901 | I<string-item> は現在のところ C<"A*">, C<"a*">, C<"Z*"> のいずれかで | |
| 11333 | ||
| 6902 | なければなりません。 | |
| 11334 | I<length-item> | |
| 6903 | C<unpack> の場合は文字列の長さは I<length-item> から得られますが、 | |
| 11335 | ||
| 6904 | '*' を置くと無視されます。 | |
| 11336 | 6905 | |
| 11337 | ||
| 6906 | unpack 'C/a', "\04Gurusamy"; gives 'Guru' | |
| 6907 | unpack 'a3/A* A*', '007 Bond J '; gives (' Bond','J') | |
| 6908 | pack 'n/a* w/a*','hello,','world'; gives "\000\006hello,\005world" | |
| 11338 | 6909 | |
| 11339 | For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer | |
| 11340 | arguments unpacked so far is | |
| 11341 | used. You write C</>I<sequence-item> and the repeat count is obtained by | |
| 11342 | popping off the last element from the stack. The I<sequence-item> must not | |
| 11343 | have a repeat count. | |
| 11344 | ||
| 11345 | =end original | |
| 11346 | ||
| 11347 | L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の | |
| 11348 | 内部スタックが使われます。 | |
| 11349 | C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を | |
| 11350 | 取り出すことで得ます。 | |
| 11351 | I<sequence-item> は繰り返し数を持っていてはいけません。 | |
| 11352 | ||
| 11353 | 6910 | =begin original |
| 11354 | 6911 | |
| 11355 | ||
| 6912 | The I<length-item> is not returned explicitly from C<unpack>. | |
| 11356 | the I<length-item> is the string length, not the number of strings. With | |
| 11357 | an explicit repeat count for pack, the packed string is adjusted to that | |
| 11358 | length. For example: | |
| 11359 | 6913 | |
| 11360 | 6914 | =end original |
| 11361 | 6915 | |
| 11362 | I< | |
| 6916 | I<length-item> は C<unpack> から明示的には返されません。 | |
| 11363 | I<length-item> は文字列の数ではなく、文字列の長さです。 | |
| 11364 | pack で明示的な繰り返し数があると、pack された文字列は与えられた | |
| 11365 | 長さに調整されます。 | |
| 11366 | 例えば: | |
| 11367 | 6917 | |
| 11368 | This code: gives this result: | |
| 11369 | ||
| 11370 | unpack("W/a", "\004Gurusamy") ("Guru") | |
| 11371 | unpack("a3/A A*", "007 Bond J ") (" Bond", "J") | |
| 11372 | unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".") | |
| 11373 | ||
| 11374 | pack("n/a* w/a","hello,","world") "\000\006hello,\005world" | |
| 11375 | pack("a/W2", ord("a") .. ord("z")) "2ab" | |
| 11376 | ||
| 11377 | 6918 | =begin original |
| 11378 | 6919 | |
| 11379 | ||
| 6920 | Adding a count to the I<length-item> letter is unlikely to do anything | |
| 11380 | ||
| 6921 | useful, unless that letter is C<A>, C<a> or C<Z>. Packing with a | |
| 6922 | I<length-item> of C<a> or C<Z> may introduce C<"\000"> characters, | |
| 6923 | which Perl does not regard as legal in numeric strings. | |
| 11381 | 6924 | |
| 11382 | 6925 | =end original |
| 11383 | 6926 | |
| 11384 | I<length-item> | |
| 6927 | I<length-item> 文字に繰り返し数をつけるのは | |
| 11385 | 返されません。 | |
| 11386 | ||
| 11387 | =begin original | |
| 11388 | ||
| 11389 | Supplying a count to the I<length-item> format letter is only useful with | |
| 11390 | C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may | |
| 11391 | introduce C<"\000"> characters, which Perl does not regard as legal in | |
| 11392 | numeric strings. | |
| 11393 | ||
| 11394 | =end original | |
| 11395 | ||
| 11396 | I<length-item> 文字に繰り返し数をつけるのは、 | |
| 11397 | 6928 | 文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。 |
| 11398 | C<a> や C<Z> を I<length-item> として | |
| 6929 | C<a> や C<Z> を I<length-item> としてパックすると C<"\000"> 文字が | |
| 11399 | 6930 | 出力されることがあり、Perl はこれを有効な数値文字列として認識しません。 |
| 11400 | 6931 | |
| 11401 | 6932 | =item * |
| 11402 | 6933 | |
| 11403 | 6934 | =begin original |
| 11404 | 6935 | |
| 11405 | 6936 | The integer types C<s>, C<S>, C<l>, and C<L> may be |
| 11406 | followed by a C<!> | |
| 6937 | immediately followed by a C<!> suffix to signify native shorts or | |
| 11407 | longs | |
| 6938 | longs--as you can see from above for example a bare C<l> does mean | |
| 11408 | exactly 32 bits, | |
| 6939 | exactly 32 bits, the native C<long> (as seen by the local C compiler) | |
| 11409 | may be larger. This is | |
| 6940 | may be larger. This is an issue mainly in 64-bit platforms. You can | |
| 11410 | see whether using C<!> makes any difference | |
| 6941 | see whether using C<!> makes any difference by | |
| 11411 | 6942 | |
| 11412 | 6943 | =end original |
| 11413 | 6944 | |
| 11414 | C<s>, C<S>, C<l>, C<L> の整数タイプに | |
| 6945 | C<s>, C<S>, C<l>, C<L> の整数タイプの直後に接尾辞として C<!> を | |
| 11415 | つけることで、ネイティブの short や long を指定できます | |
| 6946 | つけることで、ネイティブの short や long を指定できます -- | |
| 11416 | 上述のように、C<l> は正確に 32 ビットで | |
| 6947 | 上述のように、例えば C<l> は正確に 32 ビットであり、ネイティブな | |
| 11417 | 6948 | (ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。 |
| 11418 | 6949 | これは主に 64 ビットプラットフォームで意味があります。 |
| 11419 | 6950 | C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます: |
| 11420 | 6951 | |
| 11421 | ||
| 6952 | print length(pack("s")), " ", length(pack("s!")), "\n"; | |
| 11422 | length | |
| 6953 | print length(pack("l")), " ", length(pack("l!")), "\n"; | |
| 11423 | 6954 | |
| 11424 | printf "format l is %d, l! is %d\n", | |
| 11425 | length pack("l"), length pack("l!"); | |
| 11426 | ||
| 11427 | 6955 | =begin original |
| 11428 | 6956 | |
| 11429 | C<i!> and C<I!> a | |
| 6957 | C<i!> and C<I!> also work but only because of completeness; | |
| 11430 | 6958 | they are identical to C<i> and C<I>. |
| 11431 | 6959 | |
| 11432 | 6960 | =end original |
| 11433 | 6961 | |
| 11434 | 6962 | C<i!> と C<I!> も動作しますが、単に完全性のためだけです; |
| 11435 | 6963 | これは C<i> 及び C<I> と同じです。 |
| 11436 | 6964 | |
| 11437 | 6965 | =begin original |
| 11438 | 6966 | |
| 11439 | 6967 | The actual sizes (in bytes) of native shorts, ints, longs, and long |
| 11440 | longs on the platform where Perl was built are also available | |
| 6968 | longs on the platform where Perl was built are also available via | |
| 11441 | ||
| 6969 | L<Config>: | |
| 11442 | 6970 | |
| 11443 | 6971 | =end original |
| 11444 | 6972 | |
| 11445 | 6973 | Perl がビルドされたプラットフォームでの short, int, long, long long の |
| 11446 | 実際の(バイト数での)サイズは | |
| 6974 | 実際の(バイト数での)サイズは L<Config> でも得られます。 | |
| 11447 | 6975 | |
| 11448 | $ perl -V:{short,int,long{,long}}size | |
| 11449 | shortsize='2'; | |
| 11450 | intsize='4'; | |
| 11451 | longsize='4'; | |
| 11452 | longlongsize='8'; | |
| 11453 | ||
| 11454 | =begin original | |
| 11455 | ||
| 11456 | or programmatically via the L<C<Config>|Config> module: | |
| 11457 | ||
| 11458 | =end original | |
| 11459 | ||
| 11460 | あるいは L<C<Config>|Config> モジュールからプログラムで: | |
| 11461 | ||
| 11462 | 6976 | use Config; |
| 11463 | 6977 | print $Config{shortsize}, "\n"; |
| 11464 | 6978 | print $Config{intsize}, "\n"; |
| 11465 | 6979 | print $Config{longsize}, "\n"; |
| 11466 | 6980 | print $Config{longlongsize}, "\n"; |
| 11467 | 6981 | |
| 11468 | 6982 | =begin original |
| 11469 | 6983 | |
| 11470 | C<$Config{longlongsize}> i | |
| 6984 | (The C<$Config{longlongsize}> will be undefine if your system does | |
| 11471 | ||
| 6985 | not support long longs.) | |
| 11472 | 6986 | |
| 11473 | 6987 | =end original |
| 11474 | 6988 | |
| 11475 | システムが long long に対応していない場合は C<$Config{longlongsize}> は | |
| 6989 | (システムが long long に対応していない場合は C<$Config{longlongsize}> は | |
| 11476 | 未定義値になります。 | |
| 6990 | 未定義値になります。) | |
| 11477 | 6991 | |
| 11478 | 6992 | =item * |
| 11479 | 6993 | |
| 11480 | 6994 | =begin original |
| 11481 | 6995 | |
| 11482 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, | |
| 6996 | The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, and C<L> | |
| 11483 | inherently non-portable between processors and operating systems | |
| 6997 | are inherently non-portable between processors and operating systems | |
| 11484 | they obey native byteorder and endianness. For example | |
| 6998 | because they obey the native byteorder and endianness. For example a | |
| 11485 | 0x12345678 (305419896 decimal) | |
| 6999 | 4-byte integer 0x12345678 (305419896 decimal) be ordered natively | |
| 11486 | handled by the CPU registers) into bytes as | |
| 7000 | (arranged in and handled by the CPU registers) into bytes as | |
| 11487 | 7001 | |
| 11488 | 7002 | =end original |
| 11489 | 7003 | |
| 11490 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L> | |
| 7004 | 整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L> は | |
| 11491 | 7005 | ネイティブなバイト順序とエンディアンに従っているため、 |
| 11492 | 7006 | 本質的にプロセッサ間や OS 間で移植性がありません。 |
| 11493 | 7007 | 例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は |
| 11494 | 7008 | 内部では(CPU レジスタによって変換され扱われる形では) |
| 11495 | 7009 | 以下のようなバイト列に並べられます: |
| 11496 | 7010 | |
| 11497 | | |
| 7011 | 0x12 0x34 0x56 0x78 # big-endian | |
| 11498 | | |
| 7012 | 0x78 0x56 0x34 0x12 # little-endian | |
| 11499 | 7013 | |
| 11500 | 7014 | =begin original |
| 11501 | 7015 | |
| 11502 | Basically, Intel and VAX CPUs are little-endian, while everybody | |
| 7016 | Basically, the Intel and VAX CPUs are little-endian, while everybody | |
| 11503 | ||
| 7017 | else, for example Motorola m68k/88k, PPC, Sparc, HP PA, Power, and | |
| 11504 | big-endian. Alpha and MIPS can be either: Digital/Compaq | |
| 7018 | Cray are big-endian. Alpha and MIPS can be either: Digital/Compaq | |
| 11505 | them in little-endian mode | |
| 7019 | used/uses them in little-endian mode; SGI/Cray uses them in big-endian mode. | |
| 11506 | 7020 | |
| 11507 | 7021 | =end original |
| 11508 | 7022 | |
| 11509 | 基本的に、Intel と VAX の CPU はリトルエンディアンです | |
| 7023 | 基本的に、Intel と VAX の CPU はリトルエンディアンです。 | |
| 11510 | Motorola m68k/88k, PPC, Sparc, HP PA, Power, | |
| 7024 | 一方それ以外、例えば Motorola m68k/88k, PPC, Sparc, HP PA, Power, | |
| 11511 | ビッグエンディアンです。 | |
| 7025 | Cray などはビッグエンディアンです。 | |
| 11512 | Alpha と MIPS は両方ともあります: | |
| 7026 | Alpha と MIPS は両方ともあります: | |
| 11513 | ||
| 7027 | Digital/Compaq はリトルエンディアンモードで使っています(いました); | |
| 11514 | 使っています。 | |
| 7028 | SGI/Cray はビッグエンディアンモードで使っています。 | |
| 11515 | 7029 | |
| 11516 | 7030 | =begin original |
| 11517 | 7031 | |
| 11518 | The names | |
| 7032 | The names `big-endian' and `little-endian' are comic references to | |
| 11519 | e | |
| 7033 | the classic "Gulliver's Travels" (via the paper "On Holy Wars and a | |
| 11520 | ||
| 7034 | Plea for Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980) and | |
| 11521 | ||
| 7035 | the egg-eating habits of the Lilliputians. | |
| 11522 | Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980. | |
| 11523 | 7036 | |
| 11524 | 7037 | =end original |
| 11525 | 7038 | |
| 11526 | ||
| 7039 | 「ビッグエンディアン」と「リトルエンディアン」の名前は | |
| 11527 | ||
| 7040 | 古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から | |
| 11528 | 小さい方からむくリリパット国と大きい方からむくブレフスキュ国から | |
| 11529 | 7041 | 取られています。 |
| 11530 | "On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137, | |
| 11531 | April 1, 1980 の文書からコンピュータ用語として取り入れられました。 | |
| 11532 | 7042 | |
| 11533 | 7043 | =begin original |
| 11534 | 7044 | |
| 11535 | 7045 | Some systems may have even weirder byte orders such as |
| 11536 | 7046 | |
| 11537 | 7047 | =end original |
| 11538 | 7048 | |
| 11539 | 7049 | 以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません: |
| 11540 | 7050 | |
| 11541 | | |
| 7051 | 0x56 0x78 0x12 0x34 | |
| 11542 | | |
| 7052 | 0x34 0x12 0x78 0x56 | |
| 11543 | 7053 | |
| 11544 | 7054 | =begin original |
| 11545 | 7055 | |
| 11546 | ||
| 7056 | You can see your system's preference with | |
| 11547 | 7057 | |
| 11548 | 7058 | =end original |
| 11549 | 7059 | |
| 11550 | ||
| 7060 | システムの設定は以下のようにして見ることができます: | |
| 11551 | 呼ばれます。 | |
| 11552 | 7061 | |
| 11553 | ||
| 7062 | print join(" ", map { sprintf "%#02x", $_ } | |
| 7063 | unpack("C*",pack("L",0x12345678))), "\n"; | |
| 11554 | 7064 | |
| 11555 | You can determine your system endianness with this incantation: | |
| 11556 | ||
| 11557 | =end original | |
| 11558 | ||
| 11559 | システムの設定は以下のようにして調べられます: | |
| 11560 | ||
| 11561 | printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678); | |
| 11562 | ||
| 11563 | 7065 | =begin original |
| 11564 | 7066 | |
| 11565 | 7067 | The byteorder on the platform where Perl was built is also available |
| 11566 | 7068 | via L<Config>: |
| 11567 | 7069 | |
| 11568 | 7070 | =end original |
| 11569 | 7071 | |
| 11570 | 7072 | Perl がビルドされたプラットフォームでのバイト順序は |
| 11571 | L<Config> | |
| 7073 | L<Config> でも知ることができます: | |
| 11572 | 7074 | |
| 11573 | ||
| 7075 | use Config; | |
| 11574 | ||
| 7076 | print $Config{byteorder}, "\n"; | |
| 11575 | 7077 | |
| 11576 | 7078 | =begin original |
| 11577 | 7079 | |
| 11578 | or | |
| 7080 | Byteorders C<'1234'> and C<'12345678'> are little-endian, C<'4321'> | |
| 7081 | and C<'87654321'> are big-endian. | |
| 11579 | 7082 | |
| 11580 | 7083 | =end original |
| 11581 | 7084 | |
| 11582 | ||
| 7085 | C<'1234'> と C<'12345678'> はリトルエンディアン、 | |
| 7086 | C<'4321'> と C<'87654321'> はビッグエンディアンです。 | |
| 11583 | 7087 | |
| 11584 | $ perl -V:byteorder | |
| 11585 | ||
| 11586 | 7088 | =begin original |
| 11587 | 7089 | |
| 11588 | ||
| 7090 | If you want portable packed integers use the formats C<n>, C<N>, | |
| 11589 | and C< | |
| 7091 | C<v>, and C<V>, their byte endianness and size is known. | |
| 11590 | ||
| 7092 | See also L<perlport>. | |
| 11591 | one must use runtime probing. | |
| 11592 | 7093 | |
| 11593 | 7094 | =end original |
| 11594 | 7095 | |
| 11595 | C<"1234"> と C<"12345678"> はリトルエンディアンです; | |
| 11596 | C<"4321"> と C<"87654321"> はビッグエンディアンです。 | |
| 11597 | マルチアーキテクチャバイナリを持つシステムは | |
| 11598 | C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が | |
| 11599 | あることを示します。 | |
| 11600 | ||
| 11601 | =begin original | |
| 11602 | ||
| 11603 | For portably packed integers, either use the formats C<n>, C<N>, C<v>, | |
| 11604 | and C<V> or else use the C<< > >> and C<< < >> modifiers described | |
| 11605 | immediately below. See also L<perlport>. | |
| 11606 | ||
| 11607 | =end original | |
| 11608 | ||
| 11609 | 7096 | 移植性のあるパック化された整数がほしい場合は、 |
| 11610 | C<n>, C<N>, C<v>, C<V> | |
| 7097 | C<n>, C<N>, C<v>, C<V> を使ってください。 | |
| 11611 | ||
| 7098 | これらはバイトエンディアンとサイズが固定されています。 | |
| 11612 | L<perlport> も参照して | |
| 7099 | L<perlport> も参照して下さい。 | |
| 11613 | 7100 | |
| 11614 | 7101 | =item * |
| 11615 | 7102 | |
| 11616 | 7103 | =begin original |
| 11617 | 7104 | |
| 11618 | ||
| 7105 | Real numbers (floats and doubles) are in the native machine format only; | |
| 11619 | ||
| 7106 | due to the multiplicity of floating formats around, and the lack of a | |
| 11620 | ||
| 7107 | standard "network" representation, no facility for interchange has been | |
| 11621 | es | |
| 7108 | made. This means that packed floating point data written on one machine | |
| 11622 | ||
| 7109 | may not be readable on another - even if both use IEEE floating point | |
| 11623 | ||
| 7110 | arithmetic (as the endian-ness of the memory representation is not part | |
| 11624 | ||
| 11625 | =end original | |
| 11626 | ||
| 11627 | また、浮動小数点数にもエンディアンがあります。 | |
| 11628 | 通常は(但し常にではありません)これは整数のエンディアンと同じです。 | |
| 11629 | 最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも | |
| 11630 | 関わらず、(特に long double 関連で) 相違点があります。 | |
| 11631 | C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>, | |
| 11632 | C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、 | |
| 11633 | 順序値です。 | |
| 11634 | ||
| 11635 | =begin original | |
| 11636 | ||
| 11637 | Portability-wise the best option is probably to keep to the IEEE 754 | |
| 11638 | 64-bit doubles, and of agreed-upon endianness. Another possibility | |
| 11639 | is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>. | |
| 11640 | ||
| 11641 | =end original | |
| 11642 | ||
| 11643 | 移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した | |
| 11644 | エンディアンを維持することです。 | |
| 11645 | もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の | |
| 11646 | C<"%a"> 型式です。 | |
| 11647 | ||
| 11648 | =item * | |
| 11649 | ||
| 11650 | =begin original | |
| 11651 | ||
| 11652 | Starting with Perl 5.10.0, integer and floating-point formats, along with | |
| 11653 | the C<p> and C<P> formats and C<()> groups, may all be followed by the | |
| 11654 | C<< > >> or C<< < >> endianness modifiers to respectively enforce big- | |
| 11655 | or little-endian byte-order. These modifiers are especially useful | |
| 11656 | given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers, | |
| 11657 | 64-bit integers, or floating-point values. | |
| 11658 | ||
| 11659 | =end original | |
| 11660 | ||
| 11661 | Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、 | |
| 11662 | 全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の | |
| 11663 | エンディアン修飾子をつけることで、それぞれ | |
| 11664 | ビッグエンディアンとリトルエンディアンに強制させることができます。 | |
| 11665 | C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に | |
| 11666 | 対応していないので、これは特に有用です。 | |
| 11667 | ||
| 11668 | =begin original | |
| 11669 | ||
| 11670 | Here are some concerns to keep in mind when using an endianness modifier: | |
| 11671 | ||
| 11672 | =end original | |
| 11673 | ||
| 11674 | エンディアン修飾子を使うときに心に留めておくべきことを記します: | |
| 11675 | ||
| 11676 | =over | |
| 11677 | ||
| 11678 | =item * | |
| 11679 | ||
| 11680 | =begin original | |
| 11681 | ||
| 11682 | Exchanging signed integers between different platforms works only | |
| 11683 | when all platforms store them in the same format. Most platforms store | |
| 11684 | signed integers in two's-complement notation, so usually this is not an issue. | |
| 11685 | ||
| 11686 | =end original | |
| 11687 | ||
| 11688 | 異なったプラットフォームで符号付き整数を交換することは、全ての | |
| 11689 | プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。 | |
| 11690 | ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、 | |
| 11691 | 普通はこれは問題になりません。 | |
| 11692 | ||
| 11693 | =item * | |
| 11694 | ||
| 11695 | =begin original | |
| 11696 | ||
| 11697 | The C<< > >> or C<< < >> modifiers can only be used on floating-point | |
| 11698 | formats on big- or little-endian machines. Otherwise, attempting to | |
| 11699 | use them raises an exception. | |
| 11700 | ||
| 11701 | =end original | |
| 11702 | ||
| 11703 | C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの | |
| 11704 | マシンでの浮動小数点フォーマットでのみ使えます。 | |
| 11705 | それ以外では、そのようなことをすると例外が発生します。 | |
| 11706 | ||
| 11707 | =item * | |
| 11708 | ||
| 11709 | =begin original | |
| 11710 | ||
| 11711 | Forcing big- or little-endian byte-order on floating-point values for | |
| 11712 | data exchange can work only if all platforms use the same | |
| 11713 | binary representation such as IEEE floating-point. Even if all | |
| 11714 | platforms are using IEEE, there may still be subtle differences. Being able | |
| 11715 | to use C<< > >> or C<< < >> on floating-point values can be useful, | |
| 11716 | but also dangerous if you don't know exactly what you're doing. | |
| 11717 | It is not a general way to portably store floating-point values. | |
| 11718 | ||
| 11719 | =end original | |
| 11720 | ||
| 11721 | データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル | |
| 11722 | エンディアンに強制することは、全てのプラットフォームが | |
| 11723 | IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ | |
| 11724 | うまくいきます。 | |
| 11725 | たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが | |
| 11726 | あるかもしれません。 | |
| 11727 | 浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、 | |
| 11728 | もし自分が何をしているかを正確に理解していなければ、危険です。 | |
| 11729 | 移植性のある浮動小数点数の保存のための一般的な方法はありません。 | |
| 11730 | ||
| 11731 | =item * | |
| 11732 | ||
| 11733 | =begin original | |
| 11734 | ||
| 11735 | When using C<< > >> or C<< < >> on a C<()> group, this affects | |
| 11736 | all types inside the group that accept byte-order modifiers, | |
| 11737 | including all subgroups. It is silently ignored for all other | |
| 11738 | types. You are not allowed to override the byte-order within a group | |
| 11739 | that already has a byte-order modifier suffix. | |
| 11740 | ||
| 11741 | =end original | |
| 11742 | ||
| 11743 | C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを | |
| 11744 | 含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。 | |
| 11745 | その他の型については沈黙のうちに無視されます。 | |
| 11746 | 既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは | |
| 11747 | できません。 | |
| 11748 | ||
| 11749 | =back | |
| 11750 | ||
| 11751 | =item * | |
| 11752 | ||
| 11753 | =begin original | |
| 11754 | ||
| 11755 | Real numbers (floats and doubles) are in native machine format only. | |
| 11756 | Due to the multiplicity of floating-point formats and the lack of a | |
| 11757 | standard "network" representation for them, no facility for interchange has been | |
| 11758 | made. This means that packed floating-point data written on one machine | |
| 11759 | may not be readable on another, even if both use IEEE floating-point | |
| 11760 | arithmetic (because the endianness of the memory representation is not part | |
| 11761 | 7111 | of the IEEE spec). See also L<perlport>. |
| 11762 | 7112 | |
| 11763 | 7113 | =end original |
| 11764 | 7114 | |
| 11765 | 7115 | 実数 (float と double) は、機種依存のフォーマットしかありません。 |
| 11766 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
| 7116 | いろんな浮動小数点数のフォーマットが在り、標準的な | |
| 11767 | ないため、データ交換のための機能は | |
| 7117 | "network" 表現といったものがないため、データ交換のための機能は | |
| 7118 | 用意してありません。 | |
| 11768 | 7119 | つまり、あるマシンで pack した浮動小数点数は、別のマシンでは |
| 11769 | 読めないかもしれないということです | |
| 7120 | 読めないかもしれないということです。 | |
| 11770 | 浮動小数点数演算を行なっていてもです | |
| 7121 | たとえ双方で IEEE フォーマットの浮動小数点数演算を行なっていてもです | |
| 11771 | バイト順序までは、 | |
| 7122 | (IEEE の仕様では、メモリ表現上のバイト順序までは、 | |
| 7123 | 規定されていないからです)。 | |
| 11772 | 7124 | L<perlport> も参照してください。 |
| 11773 | 7125 | |
| 11774 | 7126 | =begin original |
| 11775 | 7127 | |
| 11776 | ||
| 7128 | Note that Perl uses doubles internally for all numeric calculation, and | |
| 11777 | ||
| 7129 | converting from double into float and thence back to double again will | |
| 7130 | lose precision (i.e., C<unpack("f", pack("f", $foo)>) will not in general | |
| 7131 | equal $foo). | |
| 11778 | 7132 | |
| 11779 | 7133 | =end original |
| 11780 | 7134 | |
| 11781 | ||
| 7135 | Perl では、すべての数値演算のために、内部的に double を使用しています。 | |
| 11782 | ||
| 7136 | double から float へ変換し、それから再び double に戻すと | |
| 11783 | ||
| 7137 | 精度が落ちることになります (つまり、C<unpack("f", pack("f", $foo)>) は、 | |
| 7138 | 一般には $foo と同じではないということです)。 | |
| 11784 | 7139 | |
| 11785 | =begin original | |
| 11786 | ||
| 11787 | Because Perl uses doubles (or long doubles, if configured) internally for | |
| 11788 | all numeric calculation, converting from double into float and thence | |
| 11789 | to double again loses precision, so C<unpack("f", pack("f", $foo)>) | |
| 11790 | will not in general equal $foo. | |
| 11791 | ||
| 11792 | =end original | |
| 11793 | ||
| 11794 | Perl では、すべての数値演算のために、内部的に double (または設定によっては | |
| 11795 | long double) を使用しているので、double から float へ変換し、それから再び | |
| 11796 | double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、 | |
| 11797 | 一般には $foo と同じではありません。 | |
| 11798 | ||
| 11799 | 7140 | =item * |
| 11800 | 7141 | |
| 11801 | 7142 | =begin original |
| 11802 | 7143 | |
| 11803 | ||
| 7144 | If the pattern begins with a C<U>, the resulting string will be treated | |
| 11804 | ||
| 7145 | as Unicode-encoded. You can force UTF8 encoding on in a string with an | |
| 11805 | ||
| 7146 | initial C<U0>, and the bytes that follow will be interpreted as Unicode | |
| 11806 | ||
| 7147 | characters. If you don't want this to happen, you can begin your pattern | |
| 11807 | ||
| 7148 | with C<C0> (or anything else) to force Perl not to UTF8 encode your | |
| 11808 | ||
| 7149 | string, and then follow this with a C<U*> somewhere in your pattern. | |
| 11809 | C<C0> or C<U0> in the format. This mode remains in effect until the next | |
| 11810 | mode change, or until the end of the C<()> group it (directly) applies to. | |
| 11811 | 7150 | |
| 11812 | 7151 | =end original |
| 11813 | 7152 | |
| 11814 | ||
| 7153 | パターンが C<U> で始まっている場合、結果の文字列は Unicode で | |
| 11815 | ||
| 7154 | エンコードされているものとして扱われます。 | |
| 11816 | ||
| 7155 | 先頭に C<U0> を持つ文字列で UTF8 エンコーディングを強制でき、 | |
| 11817 | ||
| 7156 | 引き続くバイト列は Unicode 文字列として解釈されます。 | |
| 11818 | ||
| 7157 | このようなことが起きてほしくない場合は、 | |
| 11819 | ||
| 7158 | パターンを C<C0> (か他のもの)で始めることによって、 | |
| 11820 | ||
| 7159 | Perl に文字列を UTF8 エンコードさせないように強制でき、 | |
| 11821 | ||
| 7160 | その後にパターンのどこかに C<U*> を置きます。 | |
| 11822 | 7161 | |
| 11823 | =begin original | |
| 11824 | ||
| 11825 | Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode | |
| 11826 | bytes is not necessarily obvious. Probably only the first of these | |
| 11827 | is what you want: | |
| 11828 | ||
| 11829 | =end original | |
| 11830 | ||
| 11831 | Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに | |
| 11832 | C<U0> を使うというのは必ずしも明白ではありません。 | |
| 11833 | おそらく、これらのうち最初のものだけが望みのものでしょう: | |
| 11834 | ||
| 11835 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 11836 | perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)' | |
| 11837 | 03B1.03C9 | |
| 11838 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 11839 | perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' | |
| 11840 | CE.B1.CF.89 | |
| 11841 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 11842 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)' | |
| 11843 | CE.B1.CF.89 | |
| 11844 | $ perl -CS -E 'say "\x{3B1}\x{3C9}"' | | |
| 11845 | perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)' | |
| 11846 | C3.8E.C2.B1.C3.8F.C2.89 | |
| 11847 | ||
| 11848 | =begin original | |
| 11849 | ||
| 11850 | Those examples also illustrate that you should not try to use | |
| 11851 | L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a | |
| 11852 | substitute for the L<Encode> module. | |
| 11853 | ||
| 11854 | =end original | |
| 11855 | ||
| 11856 | これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/ | |
| 11857 | L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして | |
| 11858 | 使おうとするべきではないということも示しています。 | |
| 11859 | ||
| 11860 | 7162 | =item * |
| 11861 | 7163 | |
| 11862 | 7164 | =begin original |
| 11863 | 7165 | |
| 11864 | You must yourself do any alignment or padding by inserting | |
| 7166 | You must yourself do any alignment or padding by inserting for example | |
| 11865 | enough C< | |
| 7167 | enough C<'x'>es while packing. There is no way to pack() and unpack() | |
| 11866 | ||
| 7168 | could know where the bytes are going to or coming from. Therefore | |
| 11867 | ||
| 7169 | C<pack> (and C<unpack>) handle their output and input as flat | |
| 11868 | ||
| 7170 | sequences of bytes. | |
| 11869 | 7171 | |
| 11870 | 7172 | =end original |
| 11871 | 7173 | |
| 11872 | ||
| 7174 | パックするときに、例えば十分な数の C<'x'> を挿入することによって | |
| 11873 | 7175 | アライメントやパッディングを行うのは全て自分でしなければなりません。 |
| 11874 | ||
| 7176 | バイト列がどこへ行くか・どこから来たかを pack() や unpack() が | |
| 11875 | ||
| 7177 | 知る方法はありません。 | |
| 11876 | ||
| 7178 | 従って C<pack> (と C<unpack>) は出力と入力をフラットなバイト列として | |
| 7179 | 扱います。 | |
| 11877 | 7180 | |
| 11878 | 7181 | =item * |
| 11879 | 7182 | |
| 11880 | 7183 | =begin original |
| 11881 | 7184 | |
| 11882 | A | |
| 7185 | A comment in a TEMPLATE starts with C<#> and goes to the end of line. | |
| 11883 | take a repeat count either as postfix, or for | |
| 11884 | L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</> | |
| 11885 | template character. Within each repetition of a group, positioning with | |
| 11886 | C<@> starts over at 0. Therefore, the result of | |
| 11887 | 7186 | |
| 11888 | 7187 | =end original |
| 11889 | 7188 | |
| 11890 | C<()> のグループはかっこで囲われた副テンプレートです。 | |
| 11891 | グループは繰り返し数を取ることができます; 接尾辞によるか、 | |
| 11892 | L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。 | |
| 11893 | グループの繰り返し毎に、C<@> の位置は 0 になります。 | |
| 11894 | 従って、以下の結果は: | |
| 11895 | ||
| 11896 | pack("@1A((@2A)@3A)", qw[X Y Z]) | |
| 11897 | ||
| 11898 | =begin original | |
| 11899 | ||
| 11900 | is the string C<"\0X\0\0YZ">. | |
| 11901 | ||
| 11902 | =end original | |
| 11903 | ||
| 11904 | 文字列 C<"\0X\0\0YZ"> です。 | |
| 11905 | ||
| 11906 | =item * | |
| 11907 | ||
| 11908 | =begin original | |
| 11909 | ||
| 11910 | C<x> and C<X> accept the C<!> modifier to act as alignment commands: they | |
| 11911 | jump forward or back to the closest position aligned at a multiple of C<count> | |
| 11912 | characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or | |
| 11913 | L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like | |
| 11914 | ||
| 11915 | =end original | |
| 11916 | ||
| 11917 | C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます: | |
| 11918 | これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。 | |
| 11919 | 例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または | |
| 11920 | L<C<unpack>|/unpack TEMPLATE,EXPR> するには | |
| 11921 | ||
| 11922 | struct { | |
| 11923 | char c; /* one signed, 8-bit character */ | |
| 11924 | double d; | |
| 11925 | char cc[2]; | |
| 11926 | } | |
| 11927 | ||
| 11928 | =begin original | |
| 11929 | ||
| 11930 | one may need to use the template C<c x![d] d c[2]>. This assumes that | |
| 11931 | doubles must be aligned to the size of double. | |
| 11932 | ||
| 11933 | =end original | |
| 11934 | ||
| 11935 | C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。 | |
| 11936 | これは double が double のサイズでアライメントされていることを | |
| 11937 | 仮定しています。 | |
| 11938 | ||
| 11939 | =begin original | |
| 11940 | ||
| 11941 | For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1; | |
| 11942 | both are no-ops. | |
| 11943 | ||
| 11944 | =end original | |
| 11945 | ||
| 11946 | アライメントコマンドに対しては、C<count> に 0 を指定するのは | |
| 11947 | C<count> に 1 を指定するのと等価です; どちらも何もしません。 | |
| 11948 | ||
| 11949 | =item * | |
| 11950 | ||
| 11951 | =begin original | |
| 11952 | ||
| 11953 | C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to | |
| 11954 | represent signed 16-/32-bit integers in big-/little-endian order. | |
| 11955 | This is portable only when all platforms sharing packed data use the | |
| 11956 | same binary representation for signed integers; for example, when all | |
| 11957 | platforms use two's-complement representation. | |
| 11958 | ||
| 11959 | =end original | |
| 11960 | ||
| 11961 | C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または | |
| 11962 | 32 ビット整数で表現するための C<!> 修飾子を受け入れます。 | |
| 11963 | これは pack されたデータを共有する全てのプラットフォームが | |
| 11964 | 符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります; | |
| 11965 | 例えば、全てのプラットフォームで 2 の補数表現を使う場合です。 | |
| 11966 | ||
| 11967 | =item * | |
| 11968 | ||
| 11969 | =begin original | |
| 11970 | ||
| 11971 | Comments can be embedded in a TEMPLATE using C<#> through the end of line. | |
| 11972 | White space can separate pack codes from each other, but modifiers and | |
| 11973 | repeat counts must follow immediately. Breaking complex templates into | |
| 11974 | individual line-by-line components, suitably annotated, can do as much to | |
| 11975 | improve legibility and maintainability of pack/unpack formats as C</x> can | |
| 11976 | for complicated pattern matches. | |
| 11977 | ||
| 11978 | =end original | |
| 11979 | ||
| 11980 | 7189 | TEMPLATE の中の C<#> から行末まではコメントです。 |
| 11981 | 空白は pack コードをそれぞれ分けるために使えますが、修飾子と | |
| 11982 | 繰り返し数は直後に置かなければなりません。 | |
| 11983 | 複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、 | |
| 11984 | 複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack | |
| 11985 | フォーマットの読みやすさと保守性が向上します。 | |
| 11986 | 7190 | |
| 11987 | 7191 | =item * |
| 11988 | 7192 | |
| 11989 | 7193 | =begin original |
| 11990 | 7194 | |
| 11991 | If TEMPLATE requires more arguments than | |
| 7195 | If TEMPLATE requires more arguments to pack() than actually given, pack() | |
| 11992 | ||
| 7196 | assumes additional C<""> arguments. If TEMPLATE requires less arguments | |
| 11993 | ||
| 7197 | to pack() than actually given, extra arguments are ignored. | |
| 11994 | than given, extra arguments are ignored. | |
| 11995 | 7198 | |
| 11996 | 7199 | =end original |
| 11997 | 7200 | |
| 11998 | TEMPLATE が要求する引数の数が | |
| 7201 | TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、 | |
| 11999 | ||
| 7202 | 追加の C<""> 引数があるものと仮定します。 | |
| 12000 | L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。 | |
| 12001 | 7203 | TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。 |
| 12002 | 7204 | |
| 12003 | =item * | |
| 12004 | ||
| 12005 | =begin original | |
| 12006 | ||
| 12007 | Attempting to pack the special floating point values C<Inf> and C<NaN> | |
| 12008 | (infinity, also in negative, and not-a-number) into packed integer values | |
| 12009 | (like C<"L">) is a fatal error. The reason for this is that there simply | |
| 12010 | isn't any sensible mapping for these special values into integers. | |
| 12011 | ||
| 12012 | =end original | |
| 12013 | ||
| 12014 | 特殊浮動小数点値 C<Inf> と C<NaN> | |
| 12015 | ((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると | |
| 12016 | 致命的エラーとなります。 | |
| 12017 | この理由は、単に特殊値を整数に割り当てられないからです。 | |
| 12018 | ||
| 12019 | 7205 | =back |
| 12020 | 7206 | |
| 12021 | 7207 | =begin original |
| 12022 | 7208 | |
| 12023 | 7209 | Examples: |
| 12024 | 7210 | |
| 12025 | 7211 | =end original |
| 12026 | 7212 | |
| 12027 | 7213 | 例: |
| 12028 | 7214 | |
| 12029 | $foo = pack(" | |
| 7215 | $foo = pack("CCCC",65,66,67,68); | |
| 12030 | 7216 | # foo eq "ABCD" |
| 12031 | $foo = pack(" | |
| 7217 | $foo = pack("C4",65,66,67,68); | |
| 12032 | 7218 | # same thing |
| 12033 | $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9); | |
| 12034 | # same thing with Unicode circled letters. | |
| 12035 | 7219 | $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9); |
| 12036 | # same thing with Unicode circled letters | |
| 7220 | # same thing with Unicode circled letters | |
| 12037 | # UTF-8 bytes because the U at the start of the format caused | |
| 12038 | # a switch to U0-mode, so the UTF-8 bytes get joined into | |
| 12039 | # characters | |
| 12040 | $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9); | |
| 12041 | # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9" | |
| 12042 | # This is the UTF-8 encoding of the string in the | |
| 12043 | # previous example | |
| 12044 | 7221 | |
| 12045 | 7222 | $foo = pack("ccxxcc",65,66,67,68); |
| 12046 | 7223 | # foo eq "AB\0\0CD" |
| 12047 | 7224 | |
| 12048 | # | |
| 7225 | # note: the above examples featuring "C" and "c" are true | |
| 12049 | 7226 | # only on ASCII and ASCII-derived systems such as ISO Latin 1 |
| 12050 | # and UTF-8. | |
| 7227 | # and UTF-8. In EBCDIC the first example would be | |
| 12051 | # | |
| 7228 | # $foo = pack("CCCC",193,194,195,196); | |
| 12052 | 7229 | |
| 12053 | 7230 | $foo = pack("s2",1,2); |
| 12054 | # "\ | |
| 7231 | # "\1\0\2\0" on little-endian | |
| 12055 | # "\0 | |
| 7232 | # "\0\1\0\2" on big-endian | |
| 12056 | 7233 | |
| 12057 | 7234 | $foo = pack("a4","abcd","x","y","z"); |
| 12058 | 7235 | # "abcd" |
| 12059 | 7236 | |
| 12060 | 7237 | $foo = pack("aaaa","abcd","x","y","z"); |
| 12061 | 7238 | # "axyz" |
| 12062 | 7239 | |
| 12063 | 7240 | $foo = pack("a14","abcdefg"); |
| 12064 | 7241 | # "abcdefg\0\0\0\0\0\0\0" |
| 12065 | 7242 | |
| 12066 | 7243 | $foo = pack("i9pl", gmtime); |
| 12067 | 7244 | # a real struct tm (on my system anyway) |
| 12068 | 7245 | |
| 12069 | 7246 | $utmp_template = "Z8 Z8 Z16 L"; |
| 12070 | 7247 | $utmp = pack($utmp_template, @utmp1); |
| 12071 | 7248 | # a struct utmp (BSDish) |
| 12072 | 7249 | |
| 12073 | 7250 | @utmp2 = unpack($utmp_template, $utmp); |
| 12074 | 7251 | # "@utmp1" eq "@utmp2" |
| 12075 | 7252 | |
| 12076 | 7253 | sub bintodec { |
| 12077 | ||
| 7254 | unpack("N", pack("B32", substr("0" x 32 . shift, -32))); | |
| 12078 | 7255 | } |
| 12079 | 7256 | |
| 12080 | 7257 | $foo = pack('sx2l', 12, 34); |
| 12081 | 7258 | # short 12, two zero bytes padding, long 34 |
| 12082 | 7259 | $bar = pack('s@4l', 12, 34); |
| 12083 | 7260 | # short 12, zero fill to position 4, long 34 |
| 12084 | 7261 | # $foo eq $bar |
| 12085 | $baz = pack('s.l', 12, 4, 34); | |
| 12086 | # short 12, zero fill to position 4, long 34 | |
| 12087 | 7262 | |
| 12088 | $foo = pack('nN', 42, 4711); | |
| 12089 | # pack big-endian 16- and 32-bit unsigned integers | |
| 12090 | $foo = pack('S>L>', 42, 4711); | |
| 12091 | # exactly the same | |
| 12092 | $foo = pack('s<l<', -42, 4711); | |
| 12093 | # pack little-endian 16- and 32-bit signed integers | |
| 12094 | $foo = pack('(sl)<', -42, 4711); | |
| 12095 | # exactly the same | |
| 12096 | ||
| 12097 | 7263 | =begin original |
| 12098 | 7264 | |
| 12099 | The same template may generally also be used in | |
| 7265 | The same template may generally also be used in unpack(). | |
| 12100 | L<C<unpack>|/unpack TEMPLATE,EXPR>. | |
| 12101 | 7266 | |
| 12102 | 7267 | =end original |
| 12103 | 7268 | |
| 12104 | 一般 | |
| 7269 | 一般には、pack で使用したものと同じテンプレートが、 | |
| 12105 | 使用できます。 | |
| 7270 | unpack 関数でも使用できます。 | |
| 12106 | 7271 | |
| 12107 | 7272 | =item package NAMESPACE |
| 12108 | 7273 | |
| 12109 | =item package | |
| 7274 | =item package | |
| 12110 | X<package> X<module> X<namespace> X<version> | |
| 12111 | 7275 | |
| 12112 | =item package NAMESPACE BLOCK | |
| 12113 | ||
| 12114 | =item package NAMESPACE VERSION BLOCK | |
| 12115 | X<package> X<module> X<namespace> X<version> | |
| 12116 | ||
| 12117 | =for Pod::Functions declare a separate global namespace | |
| 12118 | ||
| 12119 | 7276 | =begin original |
| 12120 | 7277 | |
| 12121 | Declares the | |
| 7278 | Declares the compilation unit as being in the given namespace. The scope | |
| 12122 | ||
| 7279 | of the package declaration is from the declaration itself through the end | |
| 12123 | ||
| 7280 | of the enclosing block, file, or eval (the same as the C<my> operator). | |
| 12124 | ||
| 7281 | All further unqualified dynamic identifiers will be in this namespace. | |
| 12125 | ||
| 7282 | A package statement affects only dynamic variables--including those | |
| 12126 | o | |
| 7283 | you've used C<local> on--but I<not> lexical variables, which are created | |
| 12127 | ||
| 7284 | with C<my>. Typically it would be the first declaration in a file to | |
| 12128 | ||
| 7285 | be included by the C<require> or C<use> operator. You can switch into a | |
| 12129 | ||
| 7286 | package in more than one place; it merely influences which symbol table | |
| 12130 | ||
| 7287 | is used by the compiler for the rest of that block. You can refer to | |
| 12131 | ||
| 7288 | variables and filehandles in other packages by prefixing the identifier | |
| 12132 | ||
| 7289 | with the package name and a double colon: C<$Package::Variable>. | |
| 7290 | If the package name is null, the C<main> package as assumed. That is, | |
| 7291 | C<$::sail> is equivalent to C<$main::sail> (as well as to C<$main'sail>, | |
| 7292 | still seen in older code). | |
| 12133 | 7293 | |
| 12134 | 7294 | =end original |
| 12135 | 7295 | |
| 12136 | ||
| 7296 | 与えられた名前空間でのコンパイル単位を宣言します。 | |
| 12137 | パッケージ宣言のスコープは | |
| 7297 | パッケージ宣言のスコープは、宣言自体から、閉じたブロック、ファイル、 | |
| 12138 | ||
| 7298 | eval の終わりまでです(C<my> 演算子と同じです)。 | |
| 12139 | ||
| 7299 | 全てのさらなる修飾されてない動的識別子はこの名前空間になります。 | |
| 12140 | ||
| 7300 | package 文は動的変数にのみ影響します -- C<local> で使ったものも | |
| 12141 | ||
| 7301 | 含みます -- が、C<my> で作成されたレキシカル変数には I<影響しません>。 | |
| 12142 | ||
| 7302 | 典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの | |
| 12143 | C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に | |
| 12144 | 割り当てられる特殊変数でない限り、指定された | |
| 12145 | 名前空間になります。 | |
| 12146 | ||
| 12147 | =begin original | |
| 12148 | ||
| 12149 | A package statement affects dynamic variables only, including those | |
| 12150 | you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped | |
| 12151 | variables, which are created with L<C<my>|/my VARLIST>, | |
| 12152 | L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it | |
| 12153 | would be the first declaration in a file included by | |
| 12154 | L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>. | |
| 12155 | You can switch into a | |
| 12156 | package in more than one place, since this only determines which default | |
| 12157 | symbol table the compiler uses for the rest of that block. You can refer to | |
| 12158 | identifiers in other packages than the current one by prefixing the identifier | |
| 12159 | with the package name and a double colon, as in C<$SomePack::var> | |
| 12160 | or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main> | |
| 12161 | package as assumed. That is, C<$::sail> is equivalent to | |
| 12162 | C<$main::sail> (as well as to C<$main'sail>, still seen in ancient | |
| 12163 | code, mostly from Perl 4). | |
| 12164 | ||
| 12165 | =end original | |
| 12166 | ||
| 12167 | package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも | |
| 12168 | 含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, | |
| 12169 | L<C<our>|/our VARLIST> のいずれかで作成された | |
| 12170 | レキシカルなスコープの変数には I<影響しません>。 | |
| 12171 | 典型的にはこれは L<C<require>|/require VERSION> や | |
| 12172 | L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの | |
| 12173 | 7303 | 最初に宣言されます。 |
| 12174 | 7304 | パッケージを複数の場所で切り替えることができます; |
| 12175 | ||
| 7305 | これは単にコンパイラがこのブロックの残りに対してどのシンボルテーブルを | |
| 12176 | ||
| 7306 | 使うかにのみ影響します。 | |
| 12177 | 他のパッケージの識別子 | |
| 7307 | 他のパッケージの変数やファイルハンドルは、識別子にパッケージ名と | |
| 12178 | C< | |
| 7308 | コロン 2 つをつけることで参照できます(C<$Package::Variable>)。 | |
| 12179 | ||
| 7309 | パッケージ名が空文字列の場合、C<main> パッケージが仮定されます。 | |
| 12180 | ||
| 7310 | つまり、C<$::sail> は C<$main::sail> と等価です(C<$main'sail> も | |
| 12181 | ||
| 7311 | 古いコードではまだ見られます)。 | |
| 12182 | 古いコードでは C<$main'sail> もまだ見られます)。 | |
| 12183 | 7312 | |
| 12184 | 7313 | =begin original |
| 12185 | 7314 | |
| 12186 | If | |
| 7315 | If NAMESPACE is omitted, then there is no current package, and all | |
| 12187 | ||
| 7316 | identifiers must be fully qualified or lexicals. This is stricter | |
| 12188 | ||
| 7317 | than C<use strict>, since it also extends to function names. | |
| 12189 | "strict" style version number as defined by the L<version> module: a positive | |
| 12190 | decimal number (integer or decimal-fraction) without exponentiation or else a | |
| 12191 | dotted-decimal v-string with a leading 'v' character and at least three | |
| 12192 | components. You should set C<$VERSION> only once per package. | |
| 12193 | 7318 | |
| 12194 | 7319 | =end original |
| 12195 | 7320 | |
| 12196 | ||
| 7321 | NAMESPACE が省略されると、カレントパッケージはなくなるので、 | |
| 12197 | ||
| 7322 | 全ての識別子は完全修飾されるかレキシカルでなければなりません。 | |
| 12198 | ||
| 7323 | これは関数名にも適用されるので、C<use strict> より厳しいです。 | |
| 12199 | VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で | |
| 12200 | なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 | |
| 12201 | さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から | |
| 12202 | 構成されるドット付き 10 進v-文字列です。 | |
| 12203 | C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。 | |
| 12204 | 7324 | |
| 12205 | 7325 | =begin original |
| 12206 | 7326 | |
| 12207 | 7327 | See L<perlmod/"Packages"> for more information about packages, modules, |
| 12208 | 7328 | and classes. See L<perlsub> for other scoping issues. |
| 12209 | 7329 | |
| 12210 | 7330 | =end original |
| 12211 | 7331 | |
| 12212 | 7332 | パッケージ、モジュール、クラスに関するさらなる情報については |
| 12213 | 7333 | L<perlmod/"Packages"> を参照してください。 |
| 12214 | 7334 | その他のスコープに関する話題については L<perlsub> を参照してください。 |
| 12215 | 7335 | |
| 12216 | =item __PACKAGE__ | |
| 12217 | X<__PACKAGE__> | |
| 12218 | ||
| 12219 | =for Pod::Functions +5.004 the current package | |
| 12220 | ||
| 12221 | =begin original | |
| 12222 | ||
| 12223 | A special token that returns the name of the package in which it occurs. | |
| 12224 | ||
| 12225 | =end original | |
| 12226 | ||
| 12227 | これが書いてあるパッケージの名前を返す特殊トークン。 | |
| 12228 | ||
| 12229 | 7336 | =item pipe READHANDLE,WRITEHANDLE |
| 12230 | X<pipe> | |
| 12231 | 7337 | |
| 12232 | =for Pod::Functions open a pair of connected filehandles | |
| 12233 | ||
| 12234 | 7338 | =begin original |
| 12235 | 7339 | |
| 12236 | 7340 | Opens a pair of connected pipes like the corresponding system call. |
| 12237 | 7341 | Note that if you set up a loop of piped processes, deadlock can occur |
| 12238 | 7342 | unless you are very careful. In addition, note that Perl's pipes use |
| 12239 | ||
| 7343 | stdio buffering, so you may need to set C<$|> to flush your WRITEHANDLE | |
| 12240 | ||
| 7344 | after each command, depending on the application. | |
| 12241 | application. | |
| 12242 | 7345 | |
| 12243 | 7346 | =end original |
| 12244 | 7347 | |
| 12245 | 対応するシステムコールと同じように、 | |
| 7348 | 対応するシステムコールと同じように、 | |
| 7349 | 接続されたパイプのペアをオープンします。 | |
| 12246 | 7350 | パイプでプロセスをループにするときには、よほど気を付けないと、 |
| 12247 | 7351 | デッドロックが起こり得ます。 |
| 12248 | さらに、Perl のパイプでは、 | |
| 7352 | さらに、Perl のパイプでは、stdio のバッファリングを使いますから、 | |
| 12249 | 7353 | アプリケーションによっては、コマンドごとに WRITEHANDLE を |
| 12250 | フラッシュするように、 | |
| 7354 | フラッシュするように、C<$|> を設定することが必要になるかもしれません。 | |
| 12251 | 必要になるかもしれません。 | |
| 12252 | 7355 | |
| 12253 | 7356 | =begin original |
| 12254 | 7357 | |
| 12255 | ||
| 7358 | See L<IPC::Open2>, L<IPC::Open3>, and L<perlipc/"Bidirectional Communication"> | |
| 12256 | ||
| 12257 | =end original | |
| 12258 | ||
| 12259 | 成功時には真を返します。 | |
| 12260 | ||
| 12261 | =begin original | |
| 12262 | ||
| 12263 | See L<IPC::Open2>, L<IPC::Open3>, and | |
| 12264 | L<perlipc/"Bidirectional Communication with Another Process"> | |
| 12265 | 7359 | for examples of such things. |
| 12266 | 7360 | |
| 12267 | 7361 | =end original |
| 12268 | 7362 | |
| 12269 | 7363 | これらに関する例については、L<IPC::Open2>, L<IPC::Open3>, |
| 12270 | L<perlipc/"Bidirectional Communication | |
| 7364 | L<perlipc/"Bidirectional Communication"> を参照して下さい。 | |
| 12271 | 参照してください。 | |
| 12272 | 7365 | |
| 12273 | 7366 | =begin original |
| 12274 | 7367 | |
| 12275 | On systems that support a close-on-exec flag on files, th | |
| 7368 | On systems that support a close-on-exec flag on files, the flag will be set | |
| 12276 | o | |
| 7369 | for the newly opened file descriptors as determined by the value of $^F. | |
| 12277 | ||
| 7370 | See L<perlvar/$^F>. | |
| 12278 | L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>. | |
| 12279 | 7371 | |
| 12280 | 7372 | =end original |
| 12281 | 7373 | |
| 12282 | 7374 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 12283 | 新しくオープンされたファイル記述子 | |
| 7375 | フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して | |
| 12284 | ||
| 7376 | セットされます。 | |
| 12285 | (デフォルトでは C<STDERR> の 2) | |
| 12286 | I<よりも大きい> ものに対してフラグがセットされます。 | |
| 12287 | 7377 | L<perlvar/$^F> を参照してください。 |
| 12288 | 7378 | |
| 12289 | 7379 | =item pop ARRAY |
| 12290 | X<pop> X<stack> | |
| 12291 | 7380 | |
| 12292 | 7381 | =item pop |
| 12293 | 7382 | |
| 12294 | =for Pod::Functions remove the last element from an array and return it | |
| 12295 | ||
| 12296 | 7383 | =begin original |
| 12297 | 7384 | |
| 12298 | 7385 | Pops and returns the last value of the array, shortening the array by |
| 12299 | one element. | |
| 7386 | one element. Has an effect similar to | |
| 12300 | 7387 | |
| 12301 | 7388 | =end original |
| 12302 | 7389 | |
| 12303 | 7390 | 配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。 |
| 7391 | これは、以下と同じ効果があります。 | |
| 12304 | 7392 | |
| 12305 | ||
| 7393 | $ARRAY[$#ARRAY--] | |
| 12306 | 7394 | |
| 12307 | Returns the undefined value if the array is empty, although this may | |
| 12308 | also happen at other times. If ARRAY is omitted, pops the | |
| 12309 | L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the | |
| 12310 | L<C<@_>|perlvar/@_> array in subroutines, just like | |
| 12311 | L<C<shift>|/shift ARRAY>. | |
| 12312 | ||
| 12313 | =end original | |
| 12314 | ||
| 12315 | 指定された配列に要素がなければ未定義値が返されますが、 | |
| 12316 | しかしこれは他の場合にも起こり得ます。 | |
| 12317 | ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは | |
| 12318 | L<C<@ARGV>|perlvar/@ARGV> が使われますが、 | |
| 12319 | サブルーチンでは L<C<@_>|perlvar/@_> が使われます。 | |
| 12320 | ||
| 12321 | 7395 | =begin original |
| 12322 | 7396 | |
| 12323 | ||
| 7397 | If there are no elements in the array, returns the undefined value | |
| 12324 | ||
| 7398 | (although this may happen at other times as well). If ARRAY is | |
| 12325 | ||
| 7399 | omitted, pops the C<@ARGV> array in the main program, and the C<@_> | |
| 12326 | r | |
| 7400 | array in subroutines, just like C<shift>. | |
| 12327 | 7401 | |
| 12328 | 7402 | =end original |
| 12329 | 7403 | |
| 12330 | ||
| 7404 | 指定された配列に要素がなければ、未定義値が返されます | |
| 12331 | ||
| 7405 | (しかしこれは他の場合にも起こり得ます)。 | |
| 12332 | ||
| 7406 | ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV>が、 | |
| 7407 | サブルーチンでは C<@_> が使われます。 | |
| 12333 | 7408 | |
| 12334 | 7409 | =item pos SCALAR |
| 12335 | X<pos> X<match, position> | |
| 12336 | 7410 | |
| 12337 | 7411 | =item pos |
| 12338 | 7412 | |
| 12339 | =for Pod::Functions find or set the offset for the last/next m//g search | |
| 12340 | ||
| 12341 | 7413 | =begin original |
| 12342 | 7414 | |
| 12343 | Returns the offset of where the last C<m//g> search left off for the | |
| 7415 | Returns the offset of where the last C<m//g> search left off for the variable | |
| 12344 | ||
| 7416 | in question (C<$_> is used when the variable is not specified). May be | |
| 12345 | ||
| 7417 | modified to change that offset. Such modification will also influence | |
| 12346 | ||
| 7418 | the C<\G> zero-width assertion in regular expressions. See L<perlre> and | |
| 12347 | ||
| 7419 | L<perlop>. | |
| 12348 | L<C<undef>|/undef EXPR> indicates | |
| 12349 | that the search position is reset (usually due to match failure, but | |
| 12350 | can also be because no match has yet been run on the scalar). | |
| 12351 | 7420 | |
| 12352 | 7421 | =end original |
| 12353 | 7422 | |
| 12354 | 7423 | 対象の変数に対して、前回の C<m//g> が終了した場所の |
| 12355 | オフセットを返します(変数が指定されなかった場合は | |
| 7424 | オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。 | |
| 12356 | ||
| 7425 | そのオフセットを変えるために、変更することができます。 | |
| 12357 | ||
| 7426 | そのような変更は正規表現における C<\G> ゼロ幅アサートにも | |
| 12358 | ||
| 7427 | 影響を与えます。 | |
| 12359 | 0 は有効なマッチオフセットであることに注意してください。 | |
| 12360 | L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は | |
| 12361 | マッチ失敗が原因ですが、このスカラ値にまだマッチングが | |
| 12362 | 行われていないためかもしれません)。 | |
| 12363 | ||
| 12364 | =begin original | |
| 12365 | ||
| 12366 | L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp | |
| 12367 | engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will | |
| 12368 | change that offset, and so will also influence the C<\G> zero-width | |
| 12369 | assertion in regular expressions. Both of these effects take place for | |
| 12370 | the next match, so you can't affect the position with | |
| 12371 | L<C<pos>|/pos SCALAR> during the current match, such as in | |
| 12372 | C<(?{pos() = 5})> or C<s//pos() = 5/e>. | |
| 12373 | ||
| 12374 | =end original | |
| 12375 | ||
| 12376 | L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を | |
| 12377 | 直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、 | |
| 12378 | そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。 | |
| 12379 | これらの効果の両方は次のマッチングのために行われるので、 | |
| 12380 | C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の | |
| 12381 | L<C<pos>|/pos SCALAR> の位置には影響を与えません。 | |
| 12382 | ||
| 12383 | =begin original | |
| 12384 | ||
| 12385 | Setting L<C<pos>|/pos SCALAR> also resets the I<matched with | |
| 12386 | zero-length> flag, described | |
| 12387 | under L<perlre/"Repeated Patterns Matching a Zero-length Substring">. | |
| 12388 | ||
| 12389 | =end original | |
| 12390 | ||
| 12391 | L<C<pos>|/pos SCALAR> を設定すると、 | |
| 12392 | L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に | |
| 12393 | 記述されている、I<長さ 0 でマッチング> フラグもリセットされます。 | |
| 12394 | ||
| 12395 | =begin original | |
| 12396 | ||
| 12397 | Because a failed C<m//gc> match doesn't reset the offset, the return | |
| 12398 | from L<C<pos>|/pos SCALAR> won't change either in this case. See | |
| 12399 | L<perlre> and L<perlop>. | |
| 12400 | ||
| 12401 | =end original | |
| 12402 | ||
| 12403 | C<m//gc> マッチに失敗してもオフセットはリセットしないので、 | |
| 12404 | L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。 | |
| 12405 | 7428 | L<perlre> と L<perlop> を参照してください。 |
| 12406 | 7429 | |
| 12407 | 7430 | =item print FILEHANDLE LIST |
| 12408 | X<print> | |
| 12409 | 7431 | |
| 12410 | =item print FILEHANDLE | |
| 12411 | ||
| 12412 | 7432 | =item print LIST |
| 12413 | 7433 | |
| 12414 | 7434 | =item print |
| 12415 | 7435 | |
| 12416 | =for Pod::Functions output a list to a filehandle | |
| 12417 | ||
| 12418 | 7436 | =begin original |
| 12419 | 7437 | |
| 12420 | 7438 | Prints a string or a list of strings. Returns true if successful. |
| 12421 | FILEHANDLE may be a scalar variable | |
| 7439 | FILEHANDLE may be a scalar variable name, in which case the variable | |
| 12422 | to the filehandle, thus introducing | |
| 7440 | contains the name of or a reference to the filehandle, thus introducing | |
| 12423 | FILEHANDLE is a variable and | |
| 7441 | one level of indirection. (NOTE: If FILEHANDLE is a variable and | |
| 12424 | ||
| 7442 | the next token is a term, it may be misinterpreted as an operator | |
| 12425 | parentheses around the arguments.) | |
| 7443 | unless you interpose a C<+> or put parentheses around the arguments.) | |
| 12426 | ||
| 7444 | If FILEHANDLE is omitted, prints by default to standard output (or | |
| 12427 | ||
| 7445 | to the last selected output channel--see L</select>). If LIST is | |
| 12428 | ||
| 7446 | also omitted, prints C<$_> to the currently selected output channel. | |
| 12429 | ||
| 7447 | To set the default output channel to something other than STDOUT | |
| 12430 | ||
| 7448 | use the select operation. The current value of C<$,> (if any) is | |
| 12431 | t | |
| 7449 | printed between each LIST item. The current value of C<$\> (if | |
| 7450 | any) is printed after the entire LIST has been printed. Because | |
| 7451 | print takes a LIST, anything in the LIST is evaluated in list | |
| 7452 | context, and any subroutine that you call will have one or more of | |
| 7453 | its expressions evaluated in list context. Also be careful not to | |
| 7454 | follow the print keyword with a left parenthesis unless you want | |
| 7455 | the corresponding right parenthesis to terminate the arguments to | |
| 7456 | the print--interpose a C<+> or put parentheses around all the | |
| 7457 | arguments. | |
| 12432 | 7458 | |
| 12433 | 7459 | =end original |
| 12434 | 7460 | |
| 12435 | 7461 | 文字列か文字列のリストを出力します。 |
| 12436 | 成功時には真を返します。 | |
| 7462 | 成功時には、真を返します。FILEHANDLE は、 | |
| 12437 | ||
| 7463 | スカラ変数名でもよく、その場合には、その変数にファイル | |
| 12438 | ||
| 7464 | ハンドル名またはそのリファレンスが | |
| 7465 | 入っているものとして扱われますから、一段階の間接指定が行なえます。 | |
| 12439 | 7466 | (注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、 |
| 12440 | 7467 | 間に C<+> を置くか、引数の前後を括弧で括らなければ、 |
| 12441 | 7468 | 誤って解釈されることがあります。) |
| 12442 | FILEHANDLE を省略した場合には、 | |
| 7469 | FILEHANDLE を省略した場合には、標準出力 (か、 | |
| 12443 | ||
| 7470 | 最後に選択された出力チャネル --- L</select>を参照) に出力します。 | |
| 12444 | LIST | |
| 7471 | LIST も省略すると、C<$_> を現在選択されている出力チャネルに | |
| 12445 | 出力 | |
| 7472 | 出力することになります。 | |
| 12446 | ||
| 7473 | デフォルトの出力チャネルを STDOUT 以外にしたければ、select 演算子を | |
| 12447 | C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
| 12448 | ファイルハンドルを使わなければなりません。 | |
| 12449 | デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を | |
| 12450 | 7474 | 使ってください。 |
| 7475 | C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。 | |
| 7476 | print の引数は LIST なので、LISTの中のものは、 | |
| 7477 | すべてリストコンテキストで評価されます。 | |
| 7478 | サブルーチンの呼び出しがあれば、リストコンテキストでは、 | |
| 7479 | 複数の値を返すかもしれません。また、すべての | |
| 7480 | 引数を括弧で括るのでなければ、print というキーワードの | |
| 7481 | 次に開き括弧を書いてはいけません。 | |
| 7482 | "print" と引数の間に C<+> を書くか、 | |
| 7483 | すべての引数を括弧で括ってください。 | |
| 12451 | 7484 | |
| 12452 | 7485 | =begin original |
| 12453 | 7486 | |
| 12454 | ||
| 7487 | Note that if you're storing FILEHANDLES in an array or other expression, | |
| 12455 | ||
| 7488 | you will have to use a block returning its value instead: | |
| 12456 | printed after the entire LIST has been printed. Because print takes a | |
| 12457 | LIST, anything in the LIST is evaluated in list context, including any | |
| 12458 | subroutines whose return lists you pass to | |
| 12459 | L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print | |
| 12460 | keyword with a left | |
| 12461 | parenthesis unless you want the corresponding right parenthesis to | |
| 12462 | terminate the arguments to the print; put parentheses around all arguments | |
| 12463 | (or interpose a C<+>, but that doesn't look as good). | |
| 12464 | 7489 | |
| 12465 | 7490 | =end original |
| 12466 | 7491 | |
| 12467 | ||
| 7492 | もし FILESHANDLES を配列やその他の表現に保存している場合は、 | |
| 12468 | ||
| 7493 | 代わりにその値を返すブロックを使う必要があります: | |
| 12469 | 出力されます。 | |
| 12470 | print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで | |
| 12471 | 評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す | |
| 12472 | サブルーチンも含みます。 | |
| 12473 | また、すべての引数を括弧で括るのでなければ、print というキーワードの | |
| 12474 | 次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください | |
| 12475 | (あるいは "print" と引数の間に C<+> を書きますが、これはあまり | |
| 12476 | よくありません)。 | |
| 12477 | 7494 | |
| 12478 | =begin original | |
| 12479 | ||
| 12480 | If you're storing handles in an array or hash, or in general whenever | |
| 12481 | you're using any expression more complex than a bareword handle or a plain, | |
| 12482 | unsubscripted scalar variable to retrieve it, you will have to use a block | |
| 12483 | returning the filehandle value instead, in which case the LIST may not be | |
| 12484 | omitted: | |
| 12485 | ||
| 12486 | =end original | |
| 12487 | ||
| 12488 | もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや | |
| 12489 | 普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す | |
| 12490 | ブロックを使う必要があります; この場合 LIST は省略できません: | |
| 12491 | ||
| 12492 | 7495 | print { $files[$i] } "stuff\n"; |
| 12493 | print { $OK ? | |
| 7496 | print { $OK ? STDOUT : STDERR } "stuff\n"; | |
| 12494 | 7497 | |
| 12495 | =begin original | |
| 12496 | ||
| 12497 | Printing to a closed pipe or socket will generate a SIGPIPE signal. See | |
| 12498 | L<perlipc> for more on signal handling. | |
| 12499 | ||
| 12500 | =end original | |
| 12501 | ||
| 12502 | 閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。 | |
| 12503 | さらなるシグナル操作については L<perlipc> を参照してください。 | |
| 12504 | ||
| 12505 | 7498 | =item printf FILEHANDLE FORMAT, LIST |
| 12506 | X<printf> | |
| 12507 | 7499 | |
| 12508 | =item printf FILEHANDLE | |
| 12509 | ||
| 12510 | 7500 | =item printf FORMAT, LIST |
| 12511 | 7501 | |
| 12512 | =item printf | |
| 12513 | ||
| 12514 | =for Pod::Functions output a formatted list to a filehandle | |
| 12515 | ||
| 12516 | 7502 | =begin original |
| 12517 | 7503 | |
| 12518 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that | |
| 7504 | Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\> | |
| 12519 | ||
| 7505 | (the output record separator) is not appended. The first argument | |
| 12520 | ||
| 7506 | of the list will be interpreted as the C<printf> format. If C<use locale> is | |
| 12521 | ar | |
| 7507 | in effect, the character used for the decimal point in formatted real numbers | |
| 12522 | ||
| 7508 | is affected by the LC_NUMERIC locale. See L<perllocale>. | |
| 12523 | C<printf(@_)> will use C<$_[0]> as the format. See | |
| 12524 | L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format | |
| 12525 | argument. If C<use locale> (including C<use locale ':not_characters'>) | |
| 12526 | is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been | |
| 12527 | called, the character used for the decimal separator in formatted | |
| 12528 | floating-point numbers is affected by the C<LC_NUMERIC> locale setting. | |
| 12529 | See L<perllocale> and L<POSIX>. | |
| 12530 | 7509 | |
| 12531 | 7510 | =end original |
| 12532 | 7511 | |
| 12533 | ||
| 7512 | C<$\>(出力レコードセパレータ)を追加しないことを除けば、 | |
| 12534 | 7513 | C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。 |
| 12535 | ||
| 7514 | リストの最初の要素は、C<printf> フォーマットと解釈されます。 | |
| 12536 | ||
| 7515 | C<use locale>が効力をもっていれば、小数点に使われる文字は | |
| 12537 | ||
| 7516 | LC_NUMERIC ロケールの影響を受けます。 | |
| 12538 | ||
| 7517 | L<perllocale> を参照してください。 | |
| 12539 | フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を | |
| 12540 | 参照してください。 | |
| 12541 | (C<use locale ':not_characters'> を含む) C<use locale> が有効で、 | |
| 12542 | L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、 | |
| 12543 | 小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。 | |
| 12544 | L<perllocale> と L<POSIX> を参照してください。 | |
| 12545 | 7518 | |
| 12546 | 7519 | =begin original |
| 12547 | 7520 | |
| 12548 | ||
| 7521 | Don't fall into the trap of using a C<printf> when a simple | |
| 12549 | u | |
| 7522 | C<print> would do. The C<print> is more efficient and less | |
| 12550 | ||
| 7523 | error prone. | |
| 12551 | C<FH>, not an indirect one like C<$fh>. However, this will rarely do what | |
| 12552 | you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be | |
| 12553 | replaced with the empty string and a warning will be emitted if | |
| 12554 | L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if | |
| 12555 | you want to print the contents of L<C<$_>|perlvar/$_>. | |
| 12556 | 7524 | |
| 12557 | 7525 | =end original |
| 12558 | 7526 | |
| 12559 | ||
| 7527 | 単純な C<print> を使うべきところで C<printf> を使ってしまう | |
| 12560 | L<C<$_>|perlvar/$_> が使われます; | |
| 12561 | リストなしで FILEHANDLE を使用するには、C<$fh> のような | |
| 12562 | 間接ファイルハンドルではなく、C<FH> のような裸の単語の | |
| 12563 | ファイルハンドルを使わなければなりません。 | |
| 12564 | しかし、これがあなたが求めていることをすることはまれです; | |
| 12565 | L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、 | |
| 12566 | L<warnings> が有効なら警告が出力されます。 | |
| 12567 | L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に | |
| 12568 | L<C<print>|/print FILEHANDLE LIST> を使ってください。 | |
| 12569 | ||
| 12570 | =begin original | |
| 12571 | ||
| 12572 | Don't fall into the trap of using a | |
| 12573 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple | |
| 12574 | L<C<print>|/print FILEHANDLE LIST> would do. The | |
| 12575 | L<C<print>|/print FILEHANDLE LIST> is more efficient and less error | |
| 12576 | prone. | |
| 12577 | ||
| 12578 | =end original | |
| 12579 | ||
| 12580 | 単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで | |
| 12581 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう | |
| 12582 | 7528 | 罠にかからないようにしてください。 |
| 12583 | ||
| 7529 | C<print> はより効率的で、間違いが起こりにくいです。 | |
| 12584 | 7530 | |
| 12585 | 7531 | =item prototype FUNCTION |
| 12586 | X<prototype> | |
| 12587 | 7532 | |
| 12588 | =item prototype | |
| 12589 | ||
| 12590 | =for Pod::Functions +5.002 get the prototype (if any) of a subroutine | |
| 12591 | ||
| 12592 | 7533 | =begin original |
| 12593 | 7534 | |
| 12594 | Returns the prototype of a function as a string (or | |
| 7535 | Returns the prototype of a function as a string (or C<undef> if the | |
| 12595 | L<C<undef>|/undef EXPR> if the | |
| 12596 | 7536 | function has no prototype). FUNCTION is a reference to, or the name of, |
| 12597 | the function whose prototype you want to retrieve. | |
| 7537 | the function whose prototype you want to retrieve. | |
| 12598 | L<C<$_>|perlvar/$_> is used. | |
| 12599 | 7538 | |
| 12600 | 7539 | =end original |
| 12601 | 7540 | |
| 12602 | 7541 | 関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は |
| 12603 | ||
| 7542 | C<undef> を返します)。 | |
| 12604 | 7543 | FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。 |
| 12605 | FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。 | |
| 12606 | 7544 | |
| 12607 | 7545 | =begin original |
| 12608 | 7546 | |
| 12609 | 7547 | If FUNCTION is a string starting with C<CORE::>, the rest is taken as a |
| 12610 | name for | |
| 7548 | name for Perl builtin. If the builtin is not I<overridable> (such as | |
| 12611 | cannot be | |
| 7549 | C<qw//>) or its arguments cannot be expressed by a prototype (such as | |
| 12612 | ||
| 7550 | C<system>) returns C<undef> because the builtin does not really behave | |
| 12613 | ||
| 7551 | like a Perl function. Otherwise, the string describing the equivalent | |
| 12614 | ||
| 7552 | prototype is returned. | |
| 12615 | describing the equivalent prototype is returned. | |
| 12616 | 7553 | |
| 12617 | 7554 | =end original |
| 12618 | 7555 | |
| 12619 | 7556 | FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として |
| 12620 | 7557 | 扱われます。 |
| 12621 | このビルドイン | |
| 7558 | このビルドインが(C<qw//> のように) I<オーバーライド可能> でない、 | |
| 12622 | ||
| 7559 | またはこの引数が(C<system> のように)プロトタイプとして記述できない場合、 | |
| 12623 | ||
| 7560 | C<undef> を返します。 | |
| 12624 | 7561 | なぜならビルドインは実際に Perl 関数のように振舞わないからです。 |
| 12625 | 7562 | それ以外では、等価なプロトタイプを表現した文字列が返されます。 |
| 12626 | 7563 | |
| 12627 | 7564 | =item push ARRAY,LIST |
| 12628 | X<push> X<stack> | |
| 12629 | 7565 | |
| 12630 | =for Pod::Functions append one or more elements to an array | |
| 12631 | ||
| 12632 | 7566 | =begin original |
| 12633 | 7567 | |
| 12634 | Treats ARRAY as a stack | |
| 7568 | Treats ARRAY as a stack, and pushes the values of LIST | |
| 12635 | ARRAY. The length of ARRAY increases by the length of | |
| 7569 | onto the end of ARRAY. The length of ARRAY increases by the length of | |
| 12636 | effect as | |
| 7570 | LIST. Has the same effect as | |
| 12637 | 7571 | |
| 12638 | ||
| 7572 | for $value (LIST) { | |
| 7573 | $ARRAY[++$#ARRAY] = $value; | |
| 12640 | ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。 | |
| 12641 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。 | |
| 12642 | これは、 | |
| 12643 | ||
| 12644 | for my $value (LIST) { | |
| 12645 | $ARRAY[++$#ARRAY] = $value; | |
| 12646 | 7574 | } |
| 12647 | 7575 | |
| 12648 | ||
| 7576 | but is more efficient. Returns the new number of elements in the array. | |
| 12649 | 7577 | |
| 12650 | but is more efficient. Returns the number of elements in the array following | |
| 12651 | the completed L<C<push>|/push ARRAY,LIST>. | |
| 12652 | ||
| 12653 | 7578 | =end original |
| 12654 | 7579 | |
| 12655 | と | |
| 7580 | ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりにプッシュします。 | |
| 12656 | ||
| 7581 | ARRAY の大きさは、LIST の長さ分だけ大きくなります。これは、 | |
| 12657 | 7582 | |
| 12658 | ||
| 7583 | for $value (LIST) { | |
| 7584 | $ARRAY[++$#ARRAY] = $value; | |
| 7585 | } | |
| 12659 | 7586 | |
| 12660 | ||
| 7587 | とするのと同じ効果がありますが、より効率的です。 | |
| 12661 | ||
| 7588 | 変更後の配列の要素数を返します。 | |
| 12662 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 12663 | removed as of Perl 5.24. | |
| 12664 | 7589 | |
| 12665 | =end original | |
| 12666 | ||
| 12667 | Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという | |
| 12668 | 実験的機能がありました。 | |
| 12669 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 12670 | ||
| 12671 | 7590 | =item q/STRING/ |
| 12672 | 7591 | |
| 12673 | =for Pod::Functions singly quote a string | |
| 12674 | ||
| 12675 | 7592 | =item qq/STRING/ |
| 12676 | 7593 | |
| 12677 | = | |
| 7594 | =item qr/STRING/ | |
| 12678 | 7595 | |
| 12679 | =item qw/STRING/ | |
| 12680 | ||
| 12681 | =for Pod::Functions quote a list of words | |
| 12682 | ||
| 12683 | 7596 | =item qx/STRING/ |
| 12684 | 7597 | |
| 12685 | = | |
| 7598 | =item qw/STRING/ | |
| 12686 | 7599 | |
| 12687 | 7600 | =begin original |
| 12688 | 7601 | |
| 12689 | Generalized quotes. See L<perlop/"Quote-Like Operators">. | |
| 7602 | Generalized quotes. See L<perlop/"Regexp Quote-Like Operators">. | |
| 12690 | 7603 | |
| 12691 | 7604 | =end original |
| 12692 | 7605 | |
| 12693 | 7606 | 汎用のクォートです。 |
| 12694 | L<perlop/"Quote-Like Operators"> | |
| 7607 | L<perlop/"Regexp Quote-Like Operators">を参照してください。 | |
| 12695 | 7608 | |
| 12696 | =item qr/STRING/ | |
| 12697 | ||
| 12698 | =for Pod::Functions +5.005 compile pattern | |
| 12699 | ||
| 12700 | =begin original | |
| 12701 | ||
| 12702 | Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">. | |
| 12703 | ||
| 12704 | =end original | |
| 12705 | ||
| 12706 | 正規表現風のクォートです。 | |
| 12707 | L<perlop/"Regexp Quote-Like Operators"> を参照してください。 | |
| 12708 | ||
| 12709 | 7609 | =item quotemeta EXPR |
| 12710 | X<quotemeta> X<metacharacter> | |
| 12711 | 7610 | |
| 12712 | 7611 | =item quotemeta |
| 12713 | 7612 | |
| 12714 | =for Pod::Functions quote regular expression magic characters | |
| 12715 | ||
| 12716 | 7613 | =begin original |
| 12717 | 7614 | |
| 12718 | Returns the value of EXPR with all | |
| 7615 | Returns the value of EXPR with all non-"word" | |
| 12719 | characters backslashed. (That is, all | |
| 7616 | characters backslashed. (That is, all characters not matching | |
| 12720 | 7617 | C</[A-Za-z_0-9]/> will be preceded by a backslash in the |
| 12721 | 7618 | returned string, regardless of any locale settings.) |
| 12722 | 7619 | This is the internal function implementing |
| 12723 | 7620 | the C<\Q> escape in double-quoted strings. |
| 12724 | (See below for the behavior on non-ASCII code points.) | |
| 12725 | 7621 | |
| 12726 | 7622 | =end original |
| 12727 | 7623 | |
| 12728 | EXPR の中のすべての | |
| 7624 | EXPR の中のすべての非英数字キャラクタをバックスラッシュで | |
| 12729 | エスケープしたものを返します | |
| 7625 | エスケープしたものを返します | |
| 12730 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての | |
| 7626 | (つまり、C</[A-Za-z_0-9]/> にマッチしない全ての文字の前には | |
| 12731 | ロケールに関わらずバックスラッシュが前置されます | |
| 7627 | ロケールに関わらずバックスラッシュが前置されます)。 | |
| 12732 | これは、ダブルクォート文字列での C<\Q> エスケープを | |
| 7628 | これは、ダブルクォート文字列での C<\Q> エスケープを | |
| 12733 | 内部関数です。 | |
| 7629 | 実装するための内部関数です。 | |
| 12734 | (非 ASCII 符号位置での振る舞いについては以下を参照してください。) | |
| 12735 | 7630 | |
| 12736 | 7631 | =begin original |
| 12737 | 7632 | |
| 12738 | If EXPR is omitted, uses | |
| 7633 | If EXPR is omitted, uses C<$_>. | |
| 12739 | 7634 | |
| 12740 | 7635 | =end original |
| 12741 | 7636 | |
| 12742 | EXPR が省略されると、 | |
| 7637 | EXPR が省略されると、C<$_> を使います。 | |
| 12743 | 7638 | |
| 12744 | =begin original | |
| 12745 | ||
| 12746 | quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into | |
| 12747 | regular expressions, because by default an interpolated variable will be | |
| 12748 | considered a mini-regular expression. For example: | |
| 12749 | ||
| 12750 | =end original | |
| 12751 | ||
| 12752 | クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに | |
| 12753 | 便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として | |
| 12754 | 扱われるからです。 | |
| 12755 | 例えば: | |
| 12756 | ||
| 12757 | my $sentence = 'The quick brown fox jumped over the lazy dog'; | |
| 12758 | my $substring = 'quick.*?fox'; | |
| 12759 | $sentence =~ s{$substring}{big bad wolf}; | |
| 12760 | ||
| 12761 | =begin original | |
| 12762 | ||
| 12763 | Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>. | |
| 12764 | ||
| 12765 | =end original | |
| 12766 | ||
| 12767 | とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。 | |
| 12768 | ||
| 12769 | =begin original | |
| 12770 | ||
| 12771 | On the other hand: | |
| 12772 | ||
| 12773 | =end original | |
| 12774 | ||
| 12775 | 一方: | |
| 12776 | ||
| 12777 | my $sentence = 'The quick brown fox jumped over the lazy dog'; | |
| 12778 | my $substring = 'quick.*?fox'; | |
| 12779 | $sentence =~ s{\Q$substring\E}{big bad wolf}; | |
| 12780 | ||
| 12781 | =begin original | |
| 12782 | ||
| 12783 | Or: | |
| 12784 | ||
| 12785 | =end original | |
| 12786 | ||
| 12787 | あるいは: | |
| 12788 | ||
| 12789 | my $sentence = 'The quick brown fox jumped over the lazy dog'; | |
| 12790 | my $substring = 'quick.*?fox'; | |
| 12791 | my $quoted_substring = quotemeta($substring); | |
| 12792 | $sentence =~ s{$quoted_substring}{big bad wolf}; | |
| 12793 | ||
| 12794 | =begin original | |
| 12795 | ||
| 12796 | Will both leave the sentence as is. | |
| 12797 | Normally, when accepting literal string input from the user, | |
| 12798 | L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used. | |
| 12799 | ||
| 12800 | =end original | |
| 12801 | ||
| 12802 | とすると、両方ともそのままです。 | |
| 12803 | 普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、 | |
| 12804 | 必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。 | |
| 12805 | ||
| 12806 | =begin original | |
| 12807 | ||
| 12808 | In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded | |
| 12809 | strings, but not quoted in UTF-8 strings. | |
| 12810 | ||
| 12811 | =end original | |
| 12812 | ||
| 12813 | Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた | |
| 12814 | 文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。 | |
| 12815 | ||
| 12816 | =begin original | |
| 12817 | ||
| 12818 | Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for | |
| 12819 | quoting non-ASCII characters; the quoting of ASCII characters is | |
| 12820 | unchanged. | |
| 12821 | ||
| 12822 | =end original | |
| 12823 | ||
| 12824 | Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で | |
| 12825 | 定義された戦略を採用しました; ASCII 文字のクォートは変わりません。 | |
| 12826 | ||
| 12827 | =begin original | |
| 12828 | ||
| 12829 | Also unchanged is the quoting of non-UTF-8 strings when outside the | |
| 12830 | scope of a | |
| 12831 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>, | |
| 12832 | which is to quote all | |
| 12833 | characters in the upper Latin1 range. This provides complete backwards | |
| 12834 | compatibility for old programs which do not use Unicode. (Note that | |
| 12835 | C<unicode_strings> is automatically enabled within the scope of a | |
| 12836 | S<C<use v5.12>> or greater.) | |
| 12837 | ||
| 12838 | =end original | |
| 12839 | ||
| 12840 | また、 | |
| 12841 | L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の | |
| 12842 | 範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の | |
| 12843 | 全ての文字をクォートします。 | |
| 12844 | これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。 | |
| 12845 | (C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは | |
| 12846 | 自動的に有効になることに注意してください。) | |
| 12847 | ||
| 12848 | =begin original | |
| 12849 | ||
| 12850 | Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code | |
| 12851 | points | |
| 12852 | are quoted whether the string is encoded as UTF-8 or not. As mentioned | |
| 12853 | above, locale does not affect the quoting of ASCII-range characters. | |
| 12854 | This protects against those locales where characters such as C<"|"> are | |
| 12855 | considered to be word characters. | |
| 12856 | ||
| 12857 | =end original | |
| 12858 | ||
| 12859 | L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は | |
| 12860 | 文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。 | |
| 12861 | 上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。 | |
| 12862 | これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。 | |
| 12863 | ||
| 12864 | =begin original | |
| 12865 | ||
| 12866 | Otherwise, Perl quotes non-ASCII characters using an adaptation from | |
| 12867 | Unicode (see L<http://www.unicode.org/reports/tr31/>). | |
| 12868 | The only code points that are quoted are those that have any of the | |
| 12869 | Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space, | |
| 12870 | Default_Ignorable_Code_Point, or General_Category=Control. | |
| 12871 | ||
| 12872 | =end original | |
| 12873 | ||
| 12874 | さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします | |
| 12875 | (L<http://www.unicode.org/reports/tr31/> 参照)。 | |
| 12876 | クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです: | |
| 12877 | Pattern_Syntax, Pattern_White_Space, White_Space, | |
| 12878 | Default_Ignorable_Code_Point, or General_Category=Control。 | |
| 12879 | ||
| 12880 | =begin original | |
| 12881 | ||
| 12882 | Of these properties, the two important ones are Pattern_Syntax and | |
| 12883 | Pattern_White_Space. They have been set up by Unicode for exactly this | |
| 12884 | purpose of deciding which characters in a regular expression pattern | |
| 12885 | should be quoted. No character that can be in an identifier has these | |
| 12886 | properties. | |
| 12887 | ||
| 12888 | =end original | |
| 12889 | ||
| 12890 | これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。 | |
| 12891 | これらはまさに正規表現中パターン中のどの文字をクォートするべきかを | |
| 12892 | 決定するという目的のために Unicode によって設定されています。 | |
| 12893 | 識別子になる文字はこれらの特性はありません。 | |
| 12894 | ||
| 12895 | =begin original | |
| 12896 | ||
| 12897 | Perl promises, that if we ever add regular expression pattern | |
| 12898 | metacharacters to the dozen already defined | |
| 12899 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the | |
| 12900 | Pattern_Syntax property. Perl also promises, that if we ever add | |
| 12901 | characters that are considered to be white space in regular expressions | |
| 12902 | (currently mostly affected by C</x>), they will all have the | |
| 12903 | Pattern_White_Space property. | |
| 12904 | ||
| 12905 | =end original | |
| 12906 | ||
| 12907 | Perl は、正規表現メタ文字として既に定義されている | |
| 12908 | (C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、 | |
| 12909 | Pattern_Syntax 特性を持つものだけを使うことを約束します。 | |
| 12910 | Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と | |
| 12911 | 考えられる文字に追加するときは、Pattern_White_Space 特性を | |
| 12912 | 持つものであることを約束します。 | |
| 12913 | ||
| 12914 | =begin original | |
| 12915 | ||
| 12916 | Unicode promises that the set of code points that have these two | |
| 12917 | properties will never change, so something that is not quoted in v5.16 | |
| 12918 | will never need to be quoted in any future Perl release. (Not all the | |
| 12919 | code points that match Pattern_Syntax have actually had characters | |
| 12920 | assigned to them; so there is room to grow, but they are quoted | |
| 12921 | whether assigned or not. Perl, of course, would never use an | |
| 12922 | unassigned code point as an actual metacharacter.) | |
| 12923 | ||
| 12924 | =end original | |
| 12925 | ||
| 12926 | Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを | |
| 12927 | 約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも | |
| 12928 | クォートする必要はありません。 | |
| 12929 | (Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている | |
| 12930 | 文字を持っているわけではありません; したがって拡張する余地がありますが、 | |
| 12931 | 割り当てられているかどうかに関わらずクォートされます。 | |
| 12932 | Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは | |
| 12933 | ありません。) | |
| 12934 | ||
| 12935 | =begin original | |
| 12936 | ||
| 12937 | Quoting characters that have the other 3 properties is done to enhance | |
| 12938 | the readability of the regular expression and not because they actually | |
| 12939 | need to be quoted for regular expression purposes (characters with the | |
| 12940 | White_Space property are likely to be indistinguishable on the page or | |
| 12941 | screen from those with the Pattern_White_Space property; and the other | |
| 12942 | two properties contain non-printing characters). | |
| 12943 | ||
| 12944 | =end original | |
| 12945 | ||
| 12946 | その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために | |
| 12947 | 行われ、実際には正規表現の目的でクォートする必要があるからではありません | |
| 12948 | (White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と | |
| 12949 | おそらく区別が付かないでしょう; そして残りの | |
| 12950 | 二つの特性は非表示文字を含んでいます). | |
| 12951 | ||
| 12952 | 7639 | =item rand EXPR |
| 12953 | X<rand> X<random> | |
| 12954 | 7640 | |
| 12955 | 7641 | =item rand |
| 12956 | 7642 | |
| 12957 | =for Pod::Functions retrieve the next pseudorandom number | |
| 12958 | ||
| 12959 | 7643 | =begin original |
| 12960 | 7644 | |
| 12961 | 7645 | Returns a random fractional number greater than or equal to C<0> and less |
| 12962 | 7646 | than the value of EXPR. (EXPR should be positive.) If EXPR is |
| 12963 | omitted, the value C<1> is used. | |
| 7647 | omitted, the value C<1> is used. Automatically calls C<srand> unless | |
| 12964 | ||
| 7648 | C<srand> has already been called. See also C<srand>. | |
| 12965 | and is subject to change in future versions of Perl). Automatically calls | |
| 12966 | L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been | |
| 12967 | called. See also L<C<srand>|/srand EXPR>. | |
| 12968 | 7649 | |
| 12969 | 7650 | =end original |
| 12970 | 7651 | |
| 12971 | 7652 | C<0> 以上 EXPR の値未満の小数の乱数値を返します。 |
| 12972 | (EXPR | |
| 7653 | (EXPRは正の数である必要があります。) | |
| 12973 | EXPR | |
| 7654 | EXPR を省略すると、C<1> とみなします。 | |
| 12974 | ||
| 7655 | C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を | |
| 12975 | ||
| 7656 | 呼び出します。 | |
| 12976 | ||
| 7657 | C<srand> も参照してください。 | |
| 12977 | L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に | |
| 12978 | L<C<srand>|/srand EXPR> 関数を呼び出します。 | |
| 12979 | L<C<srand>|/srand EXPR> も参照してください。 | |
| 12980 | 7658 | |
| 12981 | 7659 | =begin original |
| 12982 | 7660 | |
| 12983 | Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR> | |
| 12984 | if you want random integers instead of random fractional numbers. For | |
| 12985 | example, | |
| 12986 | ||
| 12987 | =end original | |
| 12988 | ||
| 12989 | ランダムな小数ではなく、ランダムな整数がほしい場合は、 | |
| 12990 | L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を | |
| 12991 | 適用してください。 | |
| 12992 | 例えば: | |
| 12993 | ||
| 12994 | int(rand(10)) | |
| 12995 | ||
| 12996 | =begin original | |
| 12997 | ||
| 12998 | returns a random integer between C<0> and C<9>, inclusive. | |
| 12999 | ||
| 13000 | =end original | |
| 13001 | ||
| 13002 | これは C<0> から C<9> の値をランダムに返します。 | |
| 13003 | ||
| 13004 | =begin original | |
| 13005 | ||
| 13006 | 7661 | (Note: If your rand function consistently returns numbers that are too |
| 13007 | 7662 | large or too small, then your version of Perl was probably compiled |
| 13008 | 7663 | with the wrong number of RANDBITS.) |
| 13009 | 7664 | |
| 13010 | 7665 | =end original |
| 13011 | 7666 | |
| 13012 | 7667 | (注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを |
| 13013 | 7668 | 返すようなら、お使いになっている Perl が、 |
| 13014 | 7669 | 良くない RANDBITS を使ってコンパイルされている可能性があります。) |
| 13015 | 7670 | |
| 13016 | =begin original | |
| 13017 | ||
| 13018 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
| 13019 | on it in security-sensitive situations.> As of this writing, a | |
| 13020 | number of third-party CPAN modules offer random number generators | |
| 13021 | intended by their authors to be cryptographically secure, | |
| 13022 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
| 13023 | and L<Math::TrulyRandom>. | |
| 13024 | ||
| 13025 | =end original | |
| 13026 | ||
| 13027 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
| 13028 | セキュリティ的に重要な状況でこれに頼るべきではありません。> | |
| 13029 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが | |
| 13030 | 作者によって暗号学的に安全であることを目的とした乱数生成器を | |
| 13031 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
| 13032 | L<Math::TrulyRandom> などです。 | |
| 13033 | ||
| 13034 | 7671 | =item read FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 13035 | X<read> X<file, read> | |
| 13036 | 7672 | |
| 13037 | 7673 | =item read FILEHANDLE,SCALAR,LENGTH |
| 13038 | 7674 | |
| 13039 | =for Pod::Functions fixed-length buffered input from a filehandle | |
| 13040 | ||
| 13041 | 7675 | =begin original |
| 13042 | 7676 | |
| 13043 | Attempts to read LENGTH | |
| 7677 | Attempts to read LENGTH bytes of data into variable SCALAR from the | |
| 13044 | ||
| 7678 | specified FILEHANDLE. Returns the number of bytes actually read, C<0> | |
| 13045 | a | |
| 7679 | at end of file, or undef if there was an error. SCALAR will be grown | |
| 13046 | ||
| 7680 | or shrunk to the length actually read. If SCALAR needs growing, the | |
| 13047 | ||
| 7681 | new bytes will be zero bytes. An OFFSET may be specified to place | |
| 13048 | ||
| 7682 | the read data into some other place in SCALAR than the beginning. | |
| 13049 | ||
| 7683 | The call is actually implemented in terms of stdio's fread(3) call. | |
| 7684 | To get a true read(2) system call, see C<sysread>. | |
| 13050 | 7685 | |
| 13051 | 7686 | =end original |
| 13052 | 7687 | |
| 13053 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH | |
| 7688 | 指定した FILEHANDLE から、変数 SCALAR に LENGTH バイトの | |
| 13054 | 読み込みます。 | |
| 7689 | データを読み込みます。 | |
| 13055 | 実際に読み込まれた | |
| 7690 | 実際に読み込まれたバイト数、 | |
| 13056 | ||
| 7691 | ファイル終端の場合は C<0>、エラーの場合は undef のいずれかを返します。 | |
| 13057 | SCALAR は | |
| 7692 | SCALAR は、実際に読み込んだ長さに応じて、伸び縮みします。 | |
| 13058 | ||
| 7693 | SCALAR が伸びた場合、伸びた部分はバイト 0 になります。 | |
| 7694 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 | |
| 7695 | 読み込みを行なうことができます。 | |
| 7696 | この関数は、stdio ライブラリの fread(3) 関数を使って実装しています。 | |
| 7697 | 本当の read(2) システムコールを利用するには、C<sysread> を参照してください。 | |
| 13059 | 7698 | |
| 13060 | =begin original | |
| 13061 | ||
| 13062 | An OFFSET may be specified to place the read data at some place in the | |
| 13063 | string other than the beginning. A negative OFFSET specifies | |
| 13064 | placement at that many characters counting backwards from the end of | |
| 13065 | the string. A positive OFFSET greater than the length of SCALAR | |
| 13066 | results in the string being padded to the required size with C<"\0"> | |
| 13067 | bytes before the result of the read is appended. | |
| 13068 | ||
| 13069 | =end original | |
| 13070 | ||
| 13071 | OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。 | |
| 13072 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで | |
| 13073 | 位置を指定します。 | |
| 13074 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が | |
| 13075 | 追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。 | |
| 13076 | ||
| 13077 | =begin original | |
| 13078 | ||
| 13079 | The call is implemented in terms of either Perl's or your system's native | |
| 13080 | L<fread(3)> library function. To get a true L<read(2)> system call, see | |
| 13081 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>. | |
| 13082 | ||
| 13083 | =end original | |
| 13084 | ||
| 13085 | この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って | |
| 13086 | 実装しています。 | |
| 13087 | 本当の L<read(2)> システムコールを利用するには、 | |
| 13088 | L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。 | |
| 13089 | ||
| 13090 | =begin original | |
| 13091 | ||
| 13092 | Note the I<characters>: depending on the status of the filehandle, | |
| 13093 | either (8-bit) bytes or characters are read. By default, all | |
| 13094 | filehandles operate on bytes, but for example if the filehandle has | |
| 13095 | been opened with the C<:utf8> I/O layer (see | |
| 13096 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> | |
| 13097 | pragma), the I/O will operate on UTF8-encoded Unicode | |
| 13098 | characters, not bytes. Similarly for the C<:encoding> layer: | |
| 13099 | in that case pretty much any characters can be read. | |
| 13100 | ||
| 13101 | =end original | |
| 13102 | ||
| 13103 | I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか | |
| 13104 | 文字が読み込まれます。 | |
| 13105 | デフォルトでは全てのファイルハンドルはバイトを処理しますが、 | |
| 13106 | 例えばファイルハンドルが C<:utf8> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>, | |
| 13107 | L<open> プラグマを参照してください) で開かれた場合、I/O はバイトではなく、 | |
| 13108 | UTF8 エンコードされた Unicode 文字を操作します。 | |
| 13109 | C<:encoding> 層も同様です: | |
| 13110 | この場合、ほとんど大体全ての文字が読み込めます。 | |
| 13111 | ||
| 13112 | 7699 | =item readdir DIRHANDLE |
| 13113 | X<readdir> | |
| 13114 | 7700 | |
| 13115 | =for Pod::Functions get a directory from a directory handle | |
| 13116 | ||
| 13117 | 7701 | =begin original |
| 13118 | 7702 | |
| 13119 | Returns the next directory entry for a directory opened by | |
| 7703 | Returns the next directory entry for a directory opened by C<opendir>. | |
| 13120 | L<C<opendir>|/opendir DIRHANDLE,EXPR>. | |
| 13121 | 7704 | If used in list context, returns all the rest of the entries in the |
| 13122 | directory. If there are no more entries, returns | |
| 7705 | directory. If there are no more entries, returns an undefined value in | |
| 13123 | scalar context a | |
| 7706 | scalar context or a null list in list context. | |
| 13124 | 7707 | |
| 13125 | 7708 | =end original |
| 13126 | 7709 | |
| 13127 | ||
| 7710 | C<opendir> でオープンしたディレクトリで、 | |
| 13128 | ディレクトリエントリを返します。 | |
| 7711 | 次のディレクトリエントリを返します。 | |
| 13129 | リストコンテキストで用いると、 | |
| 7712 | リストコンテキストで用いると、 | |
| 13130 | 返します。 | |
| 7713 | そのディレクトリの残りのエントリを、すべて返します。 | |
| 13131 | 7714 | エントリが残っていない場合には、スカラコンテキストでは未定義値を、 |
| 13132 | 7715 | リストコンテキストでは空リストを返します。 |
| 13133 | 7716 | |
| 13134 | 7717 | =begin original |
| 13135 | 7718 | |
| 13136 | If you're planning to filetest the return values out of a | |
| 7719 | If you're planning to filetest the return values out of a C<readdir>, you'd | |
| 13137 | ||
| 7720 | better prepend the directory in question. Otherwise, because we didn't | |
| 13138 | ||
| 7721 | C<chdir> there, it would have been testing the wrong file. | |
| 13139 | it would have been testing the wrong file. | |
| 13140 | 7722 | |
| 13141 | 7723 | =end original |
| 13142 | 7724 | |
| 13143 | ||
| 7725 | C<readdir> の返り値をファイルテストに使おうと計画しているなら、 | |
| 13144 | ||
| 7726 | 頭にディレクトリをつける必要があります。 | |
| 13145 | さもなければ、ここでは | |
| 7727 | さもなければ、ここでは C<chdir> はしないので、 | |
| 13146 | 7728 | 間違ったファイルをテストしてしまうことになるでしょう。 |
| 13147 | 7729 | |
| 13148 | opendir( | |
| 7730 | opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; | |
| 13149 | | |
| 7731 | @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR); | |
| 13150 | closedir | |
| 7732 | closedir DIR; | |
| 13151 | 7733 | |
| 13152 | =begin original | |
| 13153 | ||
| 13154 | As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a | |
| 13155 | C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration. | |
| 13156 | If either a C<readdir> expression or an explicit assignment of a | |
| 13157 | C<readdir> expression to a scalar is used as a C<while>/C<for> condition, | |
| 13158 | then the condition actually tests for definedness of the expression's | |
| 13159 | value, not for its regular truth value. | |
| 13160 | ||
| 13161 | =end original | |
| 13162 | ||
| 13163 | Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で | |
| 13164 | 使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。 | |
| 13165 | C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が | |
| 13166 | C<while>/C<for> の条件部として使われた場合、 | |
| 13167 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 13168 | テストします。 | |
| 13169 | ||
| 13170 | opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!"; | |
| 13171 | while (readdir $dh) { | |
| 13172 | print "$some_dir/$_\n"; | |
| 13173 | } | |
| 13174 | closedir $dh; | |
| 13175 | ||
| 13176 | =begin original | |
| 13177 | ||
| 13178 | To avoid confusing would-be users of your code who are running earlier | |
| 13179 | versions of Perl with mysterious failures, put this sort of thing at the | |
| 13180 | top of your file to signal that your code will work I<only> on Perls of a | |
| 13181 | recent vintage: | |
| 13182 | ||
| 13183 | =end original | |
| 13184 | ||
| 13185 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
| 13186 | 失敗で混乱することを避けるために、コードが最近のバージョンの Perl で | |
| 13187 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
| 13188 | 書いてください: | |
| 13189 | ||
| 13190 | use 5.012; # so readdir assigns to $_ in a lone while test | |
| 13191 | ||
| 13192 | 7734 | =item readline EXPR |
| 13193 | 7735 | |
| 13194 | =item readline | |
| 13195 | X<readline> X<gets> X<fgets> | |
| 13196 | ||
| 13197 | =for Pod::Functions fetch a record from a file | |
| 13198 | ||
| 13199 | 7736 | =begin original |
| 13200 | 7737 | |
| 13201 | Reads from the filehandle whose typeglob is contained in EXPR | |
| 7738 | Reads from the filehandle whose typeglob is contained in EXPR. In scalar | |
| 13202 | ||
| 7739 | context, each call reads and returns the next line, until end-of-file is | |
| 13203 | re | |
| 7740 | reached, whereupon the subsequent call returns undef. In list context, | |
| 13204 | su | |
| 7741 | reads until end-of-file is reached and returns a list of lines. Note that | |
| 13205 | ||
| 7742 | the notion of "line" used here is however you may have defined it | |
| 13206 | ||
| 7743 | with C<$/> or C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">. | |
| 13207 | L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in | |
| 13208 | L<English>). See L<perlvar/"$/">. | |
| 13209 | 7744 | |
| 13210 | 7745 | =end original |
| 13211 | 7746 | |
| 13212 | ||
| 7747 | typeglob が EXPR に含まれているファイルハンドルから読み込みます。 | |
| 13213 | ||
| 7748 | スカラコンテキストでは、呼び出し毎に一行読み込んで返します。 | |
| 13214 | ||
| 7749 | ファイルの最後まで読み込んだら、以後の呼び出しでは undef を返します。 | |
| 13215 | 最後まで読み込ん | |
| 7750 | リストコンテキストでは、ファイルの最後まで読み込んで、 | |
| 13216 | ||
| 7751 | 行のリストを返します。 | |
| 13217 | ここでの「行」とは、 | |
| 7752 | ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で | |
| 13218 | L< | |
| 7753 | 定義されることに注意してください。L<perlvar/"$/"> も参照して下さい。 | |
| 13219 | 定義されることに注意してください。 | |
| 13220 | L<perlvar/"$/"> を参照してください。 | |
| 13221 | 7754 | |
| 13222 | 7755 | =begin original |
| 13223 | 7756 | |
| 13224 | When | |
| 7757 | When C<$/> is set to C<undef>, when readline() is in scalar | |
| 13225 | ||
| 7758 | context (i.e. file slurp mode), and when an empty file is read, it | |
| 13226 | ||
| 7759 | returns C<''> the first time, followed by C<undef> subsequently. | |
| 13227 | time, followed by L<C<undef>|/undef EXPR> subsequently. | |
| 13228 | 7760 | |
| 13229 | 7761 | =end original |
| 13230 | 7762 | |
| 13231 | ||
| 7763 | C<$/> に C<undef> を設定した場合は、readline() はスカラコンテキスト | |
| 13232 | ||
| 7764 | (つまりファイル吸い込みモード)となり、 | |
| 13233 | ||
| 7765 | 空のファイルを読み込んだ場合は、最初は C<''> を返し、 | |
| 13234 | それ以降は | |
| 7766 | それ以降は C<undef> を返します。 | |
| 13235 | 7767 | |
| 13236 | 7768 | =begin original |
| 13237 | 7769 | |
| 13238 | 7770 | This is the internal function implementing the C<< <EXPR> >> |
| 13239 | 7771 | operator, but you can use it directly. The C<< <EXPR> >> |
| 13240 | 7772 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
| 13241 | 7773 | |
| 13242 | 7774 | =end original |
| 13243 | 7775 | |
| 13244 | 7776 | これは C<< <EXPR> >> 演算子を実装している内部関数ですが、 |
| 13245 | 7777 | 直接使うこともできます。 |
| 13246 | 7778 | C<< <EXPR> >> 演算子についてのさらなる詳細については |
| 13247 | 7779 | L<perlop/"I/O Operators"> で議論されています。 |
| 13248 | 7780 | |
| 13249 | | |
| 7781 | $line = <STDIN>; | |
| 13250 | | |
| 7782 | $line = readline(*STDIN); # same thing | |
| 13251 | 7783 | |
| 13252 | =begin original | |
| 13253 | ||
| 13254 | If L<C<readline>|/readline EXPR> encounters an operating system error, | |
| 13255 | L<C<$!>|perlvar/$!> will be set with the corresponding error message. | |
| 13256 | It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from | |
| 13257 | filehandles you don't trust, such as a tty or a socket. The following | |
| 13258 | example uses the operator form of L<C<readline>|/readline EXPR> and dies | |
| 13259 | if the result is not defined. | |
| 13260 | ||
| 13261 | =end original | |
| 13262 | ||
| 13263 | L<C<readline>|/readline EXPR> が OS のシステムエラーになると、 | |
| 13264 | L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。 | |
| 13265 | tty やソケットといった、信頼できないファイルハンドルから読み込む時には | |
| 13266 | L<C<$!>|perlvar/$!> をチェックするのが助けになります。 | |
| 13267 | 以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が | |
| 13268 | 未定義の場合は die します。 | |
| 13269 | ||
| 13270 | while ( ! eof($fh) ) { | |
| 13271 | defined( $_ = readline $fh ) or die "readline failed: $!"; | |
| 13272 | ... | |
| 13273 | } | |
| 13274 | ||
| 13275 | =begin original | |
| 13276 | ||
| 13277 | Note that you have can't handle L<C<readline>|/readline EXPR> errors | |
| 13278 | that way with the C<ARGV> filehandle. In that case, you have to open | |
| 13279 | each element of L<C<@ARGV>|perlvar/@ARGV> yourself since | |
| 13280 | L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently. | |
| 13281 | ||
| 13282 | =end original | |
| 13283 | ||
| 13284 | L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では | |
| 13285 | 扱えないことに注意してください。 | |
| 13286 | この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、 | |
| 13287 | L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。 | |
| 13288 | ||
| 13289 | foreach my $arg (@ARGV) { | |
| 13290 | open(my $fh, $arg) or warn "Can't open $arg: $!"; | |
| 13291 | ||
| 13292 | while ( ! eof($fh) ) { | |
| 13293 | defined( $_ = readline $fh ) | |
| 13294 | or die "readline failed for $arg: $!"; | |
| 13295 | ... | |
| 13296 | } | |
| 13297 | } | |
| 13298 | ||
| 13299 | =begin original | |
| 13300 | ||
| 13301 | Like the C<< <EXPR> >> operator, if a C<readline> expression is | |
| 13302 | used as the condition of a C<while> or C<for> loop, then it will be | |
| 13303 | implicitly assigned to C<$_>. If either a C<readline> expression or | |
| 13304 | an explicit assignment of a C<readline> expression to a scalar is used | |
| 13305 | as a C<while>/C<for> condition, then the condition actually tests for | |
| 13306 | definedness of the expression's value, not for its regular truth value. | |
| 13307 | ||
| 13308 | =end original | |
| 13309 | ||
| 13310 | C<< <EXPR> >> 演算子と同様、 | |
| 13311 | C<readline> 式が C<while> や C<for> ループの条件として使われた場合、 | |
| 13312 | これは暗黙に C<$_> に代入されます。 | |
| 13313 | C<readline> 式または C<readline> 式からスカラへの明示的な代入が | |
| 13314 | C<while>/C<for> の条件部として使われた場合、 | |
| 13315 | 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを | |
| 13316 | テストします。 | |
| 13317 | ||
| 13318 | 7784 | =item readlink EXPR |
| 13319 | X<readlink> | |
| 13320 | 7785 | |
| 13321 | 7786 | =item readlink |
| 13322 | 7787 | |
| 13323 | =for Pod::Functions determine where a symbolic link is pointing | |
| 13324 | ||
| 13325 | 7788 | =begin original |
| 13326 | 7789 | |
| 13327 | 7790 | Returns the value of a symbolic link, if symbolic links are |
| 13328 | implemented. If not, | |
| 7791 | implemented. If not, gives a fatal error. If there is some system | |
| 13329 | error, returns the undefined value and sets | |
| 7792 | error, returns the undefined value and sets C<$!> (errno). If EXPR is | |
| 13330 | ||
| 7793 | omitted, uses C<$_>. | |
| 13331 | 7794 | |
| 13332 | 7795 | =end original |
| 13333 | 7796 | |
| 13334 | シンボリックリンクが実装されていれば、 | |
| 7797 | シンボリックリンクが実装されていれば、 | |
| 13335 | ||
| 7798 | シンボリックリンクの値を返します。 | |
| 13336 | ||
| 7799 | 実装されていないときには、致命的エラーとなります。 | |
| 13337 | ||
| 7800 | 何らかのシステムエラーが検出されると、 | |
| 13338 | ||
| 7801 | 未定義値を返し、C<$!> (errno)を設定します。 | |
| 7802 | EXPR を省略すると、C<$_> を使用します。 | |
| 13339 | 7803 | |
| 13340 | =begin original | |
| 13341 | ||
| 13342 | Portability issues: L<perlport/readlink>. | |
| 13343 | ||
| 13344 | =end original | |
| 13345 | ||
| 13346 | 移植性の問題: L<perlport/readlink>。 | |
| 13347 | ||
| 13348 | 7804 | =item readpipe EXPR |
| 13349 | 7805 | |
| 13350 | =item readpipe | |
| 13351 | X<readpipe> | |
| 13352 | ||
| 13353 | =for Pod::Functions execute a system command and collect standard output | |
| 13354 | ||
| 13355 | 7806 | =begin original |
| 13356 | 7807 | |
| 13357 | 7808 | EXPR is executed as a system command. |
| 13358 | 7809 | The collected standard output of the command is returned. |
| 13359 | 7810 | In scalar context, it comes back as a single (potentially |
| 13360 | 7811 | multi-line) string. In list context, returns a list of lines |
| 13361 | (however you've defined lines with | |
| 7812 | (however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>). | |
| 13362 | C<$INPUT_RECORD_SEPARATOR> in L<English>)). | |
| 13363 | 7813 | This is the internal function implementing the C<qx/EXPR/> |
| 13364 | 7814 | operator, but you can use it directly. The C<qx/EXPR/> |
| 13365 | 7815 | operator is discussed in more detail in L<perlop/"I/O Operators">. |
| 13366 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 13367 | 7816 | |
| 13368 | 7817 | =end original |
| 13369 | 7818 | |
| 13370 | 7819 | EXPR がシステムコマンドとして実行されます。 |
| 13371 | 7820 | コマンドの標準出力の内容が返されます。 |
| 13372 | 7821 | スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。 |
| 13373 | 7822 | リストコンテキストでは、行のリストを返します |
| 13374 | (但し、行は | |
| 7823 | (但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。 | |
| 13375 | C< | |
| 7824 | これは C<qx/EXPR/> 演算子を実装する内部関数ですが、 | |
| 13376 | ||
| 7825 | 直接使うことも出来ます。 | |
| 13377 | C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に | |
| 7826 | C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に | |
| 13378 | ||
| 7827 | 述べられています。 | |
| 13379 | 7828 | |
| 13380 | 7829 | =item recv SOCKET,SCALAR,LENGTH,FLAGS |
| 13381 | X<recv> | |
| 13382 | 7830 | |
| 13383 | =for Pod::Functions receive a message over a Socket | |
| 13384 | ||
| 13385 | 7831 | =begin original |
| 13386 | 7832 | |
| 13387 | Receives a message on a socket. Attempts to receive LENGTH | |
| 7833 | Receives a message on a socket. Attempts to receive LENGTH bytes of | |
| 13388 | ||
| 7834 | data into variable SCALAR from the specified SOCKET filehandle. SCALAR | |
| 13389 | ||
| 7835 | will be grown or shrunk to the length actually read. Takes the same | |
| 13390 | ||
| 7836 | flags as the system call of the same name. Returns the address of the | |
| 13391 | ||
| 7837 | sender if SOCKET's protocol supports this; returns an empty string | |
| 13392 | ||
| 7838 | otherwise. If there's an error, returns the undefined value. This call | |
| 13393 | ||
| 7839 | is actually implemented in terms of recvfrom(2) system call. See | |
| 13394 | ||
| 7840 | L<perlipc/"UDP: Message Passing"> for examples. | |
| 13395 | 7841 | |
| 13396 | 7842 | =end original |
| 13397 | 7843 | |
| 13398 | 7844 | ソケット上のメッセージを受信します。 |
| 13399 | 7845 | 指定されたファイルハンドル SOCKET から、変数 SCALAR に |
| 13400 | LENGTH | |
| 7846 | LENGTH バイトのデータを読み込もうとします。 | |
| 13401 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
| 7847 | SCALAR は、実際に読まれた長さによって、大きくなったり、 | |
| 13402 | ||
| 7848 | 小さくなったりします。 | |
| 7849 | 同名のシステムコールと同じ FLAGS を使います。 | |
| 13403 | 7850 | SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。 |
| 13404 | 7851 | エラー発生時には、未定義値を返します。 |
| 13405 | 実際には、C の | |
| 7852 | 実際には、C のrecvfrom(2) を呼びます。 | |
| 13406 | 例については | |
| 7853 | 例についてはL<perlipc/"UDP: Message Passing">を参照してください。 | |
| 13407 | 7854 | |
| 13408 | =begin original | |
| 13409 | ||
| 13410 | Note that if the socket has been marked as C<:utf8>, C<recv> will | |
| 13411 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
| 13412 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 13413 | ||
| 13414 | =end original | |
| 13415 | ||
| 13416 | ソケットが C<:utf8> としてマークされている場合、 | |
| 13417 | C<recv> は例外を投げることに注意してください。 | |
| 13418 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 13419 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
| 13420 | ||
| 13421 | 7855 | =item redo LABEL |
| 13422 | X<redo> | |
| 13423 | 7856 | |
| 13424 | =item redo EXPR | |
| 13425 | ||
| 13426 | 7857 | =item redo |
| 13427 | 7858 | |
| 13428 | =for Pod::Functions start this loop iteration over again | |
| 13429 | ||
| 13430 | 7859 | =begin original |
| 13431 | 7860 | |
| 13432 | The | |
| 7861 | The C<redo> command restarts the loop block without evaluating the | |
| 13433 | ||
| 7862 | conditional again. The C<continue> block, if any, is not executed. If | |
| 13434 | block, if any, is not executed. If | |
| 13435 | 7863 | the LABEL is omitted, the command refers to the innermost enclosing |
| 13436 | loop. Th | |
| 7864 | loop. This command is normally used by programs that want to lie to | |
| 13437 | ||
| 7865 | themselves about what was just input: | |
| 13438 | LABEL>. Programs that want to lie to themselves about what was just input | |
| 13439 | normally use this command: | |
| 13440 | 7866 | |
| 13441 | 7867 | =end original |
| 13442 | 7868 | |
| 13443 | ||
| 7869 | redo コマンドは、条件を再評価しないで、ループブロックの始めからもう一度 | |
| 13444 | ||
| 7870 | 実行を開始します。 | |
| 13445 | ||
| 7871 | C<continue> ブロックがあっても、実行されません。 | |
| 13446 | LABEL が省略されると、コマンドは | |
| 7872 | LABEL が省略されると、このコマンドは、もっとも内側のループを参照します。 | |
| 13447 | Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が | |
| 13448 | 使えます; それ以外は C<redo LABEL> と同一です。 | |
| 13449 | 7873 | このコマンドは通常、自分への入力を欺くために使用します: |
| 13450 | 7874 | |
| 13451 | 7875 | # a simpleminded Pascal comment stripper |
| 13452 | 7876 | # (warning: assumes no { or } in strings) |
| 13453 | 7877 | LINE: while (<STDIN>) { |
| 13454 | ||
| 7878 | while (s|({.*}.*){.*}|$1 |) {} | |
| 13455 | ||
| 7879 | s|{.*}| |; | |
| 13456 | ||
| 7880 | if (s|{.*| |) { | |
| 13457 | | |
| 7881 | $front = $_; | |
| 13458 | ||
| 7882 | while (<STDIN>) { | |
| 13459 | ||
| 7883 | if (/}/) { # end of comment? | |
| 13460 | ||
| 7884 | s|^|$front\{|; | |
| 13461 | ||
| 7885 | redo LINE; | |
| 13462 | ||
| 7886 | } | |
| 13463 | ||
| 7887 | } | |
| 13464 | ||
| 7888 | } | |
| 13465 | ||
| 7889 | print; | |
| 13466 | 7890 | } |
| 13467 | 7891 | |
| 13468 | 7892 | =begin original |
| 13469 | 7893 | |
| 13470 | ||
| 7894 | C<redo> cannot be used to retry a block which returns a value such as | |
| 13471 | ||
| 7895 | C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit | |
| 13472 | ||
| 7896 | a grep() or map() operation. | |
| 13473 | used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST> | |
| 13474 | operation. | |
| 13475 | 7897 | |
| 13476 | 7898 | =end original |
| 13477 | 7899 | |
| 13478 | ||
| 7900 | C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す | |
| 13479 | ||
| 7901 | ブロックを繰り返すのには使えません。 | |
| 13480 | ||
| 7902 | また、grep() や map() 操作から抜けるのに使うべきではありません。 | |
| 13481 | L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに | |
| 13482 | 使うべきではありません。 | |
| 13483 | 7903 | |
| 13484 | 7904 | =begin original |
| 13485 | 7905 | |
| 13486 | 7906 | Note that a block by itself is semantically identical to a loop |
| 13487 | that executes once. Thus | |
| 7907 | that executes once. Thus C<redo> inside such a block will effectively | |
| 13488 | ||
| 7908 | turn it into a looping construct. | |
| 13489 | 7909 | |
| 13490 | 7910 | =end original |
| 13491 | 7911 | |
| 13492 | 7912 | ブロック自身は一回だけ実行されるループと文法的に同一であることに |
| 13493 | 7913 | 注意してください。 |
| 13494 | 従って、ブロックの中で | |
| 7914 | 従って、ブロックの中で C<redo> を使うことで効果的に | |
| 13495 | 7915 | ループ構造に変換します。 |
| 13496 | 7916 | |
| 13497 | 7917 | =begin original |
| 13498 | 7918 | |
| 13499 | See also L< | |
| 7919 | See also L</continue> for an illustration of how C<last>, C<next>, and | |
| 13500 | ||
| 7920 | C<redo> work. | |
| 13501 | L<C<redo>|/redo LABEL> work. | |
| 13502 | 7921 | |
| 13503 | 7922 | =end original |
| 13504 | 7923 | |
| 13505 | ||
| 7924 | C<last>, C<next>, C<redo> がどのように働くかについては | |
| 13506 | ||
| 7925 | L</continue> を参照して下さい。 | |
| 13507 | 7926 | |
| 13508 | =begin original | |
| 13509 | ||
| 13510 | Unlike most named operators, this has the same precedence as assignment. | |
| 13511 | It is also exempt from the looks-like-a-function rule, so | |
| 13512 | C<redo ("foo")."bar"> will cause "bar" to be part of the argument to | |
| 13513 | L<C<redo>|/redo LABEL>. | |
| 13514 | ||
| 13515 | =end original | |
| 13516 | ||
| 13517 | ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。 | |
| 13518 | また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と | |
| 13519 | すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。 | |
| 13520 | ||
| 13521 | 7927 | =item ref EXPR |
| 13522 | X<ref> X<reference> | |
| 13523 | 7928 | |
| 13524 | 7929 | =item ref |
| 13525 | 7930 | |
| 13526 | =for Pod::Functions find out the type of thing being referenced | |
| 13527 | ||
| 13528 | 7931 | =begin original |
| 13529 | 7932 | |
| 13530 | ||
| 7933 | Returns a true value if EXPR is a reference, false otherwise. If EXPR | |
| 13531 | ||
| 7934 | is not specified, C<$_> will be used. The value returned depends on the | |
| 13532 | ||
| 7935 | type of thing the reference is a reference to. | |
| 7936 | Builtin types include: | |
| 13533 | 7937 | |
| 13534 | 7938 | =end original |
| 13535 | 7939 | |
| 13536 | E | |
| 7940 | EXPR がリファレンスであれば、真を返し、さもなくば、偽を返します。 | |
| 13537 | ||
| 7941 | EXPR が指定されなければ、C<$_> が使われます。 | |
| 13538 | ||
| 7942 | 返される値は、リファレンスが参照するものの型に依存します。 | |
| 13539 | ||
| 7943 | 組み込みの型には、以下のものがあります。 | |
| 13540 | EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。 | |
| 13541 | 7944 | |
| 13542 | ||
| 7945 | SCALAR | |
| 7946 | ARRAY | |
| 7947 | HASH | |
| 7948 | CODE | |
| 7949 | REF | |
| 7950 | GLOB | |
| 7951 | LVALUE | |
| 13543 | 7952 | |
| 13544 | If the operand is not a reference, then the empty string will be returned. | |
| 13545 | An empty string will only be returned in this situation. C<ref> is often | |
| 13546 | useful to just test whether a value is a reference, which can be done | |
| 13547 | by comparing the result to the empty string. It is a common mistake | |
| 13548 | to use the result of C<ref> directly as a truth value: this goes wrong | |
| 13549 | because C<0> (which is false) can be returned for a reference. | |
| 13550 | ||
| 13551 | =end original | |
| 13552 | ||
| 13553 | オペランドがリファレンスでない場合、空文字列が返されます。 | |
| 13554 | 空文字列はこの場合にのみ返されます。 | |
| 13555 | 結果を空文字列を比較することでできるので、 | |
| 13556 | C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。 | |
| 13557 | C<ref> の結果を直接真の値として使うのは良くある誤りです: | |
| 13558 | リファレンスの場合に (偽である) C<0> が返されることがあるので、 | |
| 13559 | これは誤りです。 | |
| 13560 | ||
| 13561 | 7953 | =begin original |
| 13562 | 7954 | |
| 13563 | If the | |
| 7955 | If the referenced object has been blessed into a package, then that package | |
| 13564 | ||
| 7956 | name is returned instead. You can think of C<ref> as a C<typeof> operator. | |
| 13565 | doesn't care what the physical type of the referent is; blessing takes | |
| 13566 | precedence over such concerns. Beware that exact comparison of C<ref> | |
| 13567 | results against a class name doesn't perform a class membership test: | |
| 13568 | a class's members also include objects blessed into subclasses, for | |
| 13569 | which C<ref> will return the name of the subclass. Also beware that | |
| 13570 | class names can clash with the built-in type names (described below). | |
| 13571 | 7957 | |
| 13572 | 7958 | =end original |
| 13573 | 7959 | |
| 13574 | ||
| 7960 | 参照されるオブジェクトが、何らかのパッケージに | |
| 13575 | ||
| 7961 | bless されたものであれば、これらの代わりに、 | |
| 13576 | ||
| 7962 | そのパッケージ名が返されます。 | |
| 13577 | ||
| 7963 | C<ref> は、C<typeof> 演算子のように考えることができます。 | |
| 13578 | C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを | |
| 13579 | 実行しないことに注意してください: | |
| 13580 | C<ref> がサブクラスの名前を返す場合、 | |
| 13581 | あるクラスのメンバはサブクラスに bless されているオブジェクトを | |
| 13582 | 含んでいます。 | |
| 13583 | クラス名は(後述する)組み込みの型名と衝突することにも注意してください。 | |
| 13584 | 7964 | |
| 13585 | ||
| 7965 | if (ref($r) eq "HASH") { | |
| 7966 | print "r is a reference to a hash.\n"; | |
| 7967 | } | |
| 7968 | unless (ref($r)) { | |
| 7969 | print "r is not a reference at all.\n"; | |
| 7970 | } | |
| 7971 | if (UNIVERSAL::isa($r, "HASH")) { # for subclassing | |
| 7972 | print "r is a reference to something that isa hash.\n"; | |
| 7973 | } | |
| 13586 | 7974 | |
| 13587 | If the operand is a reference to an unblessed object, then the return | |
| 13588 | value indicates the type of object. If the unblessed referent is not | |
| 13589 | a scalar, then the return value will be one of the strings C<ARRAY>, | |
| 13590 | C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of | |
| 13591 | object it is. If the unblessed referent is a scalar, then the return | |
| 13592 | value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, | |
| 13593 | C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar | |
| 13594 | currently has. But note that C<qr//> scalars are created already | |
| 13595 | blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that | |
| 13596 | these built-in type names can also be used as | |
| 13597 | class names, so C<ref> returning one of these names doesn't unambiguously | |
| 13598 | indicate that the referent is of the kind to which the name refers. | |
| 13599 | ||
| 13600 | =end original | |
| 13601 | ||
| 13602 | オペランドが bless されていないオブジェクトへのリファレンスの場合、 | |
| 13603 | 返り値はオブジェクトの型を示します。 | |
| 13604 | bless されていないリファレンス先がスカラではない場合、 | |
| 13605 | 返り値はオブジェクトの種類を示す、 | |
| 13606 | C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。 | |
| 13607 | bless されていないリファレンス先がスカラの場合、 | |
| 13608 | 返り値はそのスカラが現在保持している種類に依存して、 | |
| 13609 | C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の | |
| 13610 | いずれかの文字列です。 | |
| 13611 | しかし、C<qr//> は既に bless されて作成されるので、 | |
| 13612 | C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。 | |
| 13613 | これらの組み込み型名はまたクラス名として使われることができるので、 | |
| 13614 | C<ref> がこれらの名前の一つを返すことは、 | |
| 13615 | 明らかにリファレンス先がその名前が示している種類のものであることを | |
| 13616 | 示しているわけではないことに注意してください。 | |
| 13617 | ||
| 13618 | 7975 | =begin original |
| 13619 | 7976 | |
| 13620 | ||
| 7977 | See also L<perlref>. | |
| 13621 | limits the utility of C<ref>. For unambiguous information, use | |
| 13622 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about | |
| 13623 | blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for | |
| 13624 | information about physical types. Use L<the C<isa> method|UNIVERSAL/C<< | |
| 13625 | $obj->isa( TYPE ) >>> for class membership tests, though one must be | |
| 13626 | sure of blessedness before attempting a method call. | |
| 13627 | 7978 | |
| 13628 | 7979 | =end original |
| 13629 | 7980 | |
| 13630 | ||
| 7981 | L<perlref> も参照してください。 | |
| 13631 | 曖昧でない情報のためには、bless に関する情報については | |
| 13632 | L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、 | |
| 13633 | 物理的な型の情報については | |
| 13634 | L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。 | |
| 13635 | クラスの所属メンバテストには | |
| 13636 | L<the C<isa> method|UNIVERSAL/C<< | |
| 13637 | $obj->isa( TYPE ) >>> を使ってください; | |
| 13638 | 但し、メソッド呼び出しを試みる前に bless されていることを | |
| 13639 | 確認しなければなりません。 | |
| 13640 | 7982 | |
| 13641 | =begin original | |
| 13642 | ||
| 13643 | See also L<perlref> and L<perlobj>. | |
| 13644 | ||
| 13645 | =end original | |
| 13646 | ||
| 13647 | L<perlref> と L<perlobj> も参照してください。 | |
| 13648 | ||
| 13649 | 7983 | =item rename OLDNAME,NEWNAME |
| 13650 | X<rename> X<move> X<mv> X<ren> | |
| 13651 | 7984 | |
| 13652 | =for Pod::Functions change a filename | |
| 13653 | ||
| 13654 | 7985 | =begin original |
| 13655 | 7986 | |
| 13656 | 7987 | Changes the name of a file; an existing file NEWNAME will be |
| 13657 | 7988 | clobbered. Returns true for success, false otherwise. |
| 13658 | 7989 | |
| 13659 | 7990 | =end original |
| 13660 | 7991 | |
| 13661 | ファイルの名前を変更します | |
| 7992 | ファイルの名前を変更します。 | |
| 13662 | 上書きされるかもしれません。 | |
| 7993 | NEWNAME というファイルが既に存在した場合、上書きされるかもしれません。 | |
| 13663 | 成功時には真 | |
| 7994 | 成功時には真、失敗時には偽を返します。 | |
| 13664 | 7995 | |
| 13665 | 7996 | =begin original |
| 13666 | 7997 | |
| 13667 | 7998 | Behavior of this function varies wildly depending on your system |
| 13668 | 7999 | implementation. For example, it will usually not work across file system |
| 13669 | 8000 | boundaries, even though the system I<mv> command sometimes compensates |
| 13670 | 8001 | for this. Other restrictions include whether it works on directories, |
| 13671 | 8002 | open files, or pre-existing files. Check L<perlport> and either the |
| 13672 | ||
| 8003 | rename(2) manpage or equivalent system documentation for details. | |
| 13673 | 8004 | |
| 13674 | 8005 | =end original |
| 13675 | 8006 | |
| 13676 | 8007 | この関数の振る舞いはシステムの実装に大きく依存して異なります。 |
| 13677 | ||
| 8008 | 普通はファイルシステムにまたがってパス名を付け替えることはできません。 | |
| 13678 | 8009 | システムの I<mv> がこれを補完している場合でもそうです。 |
| 13679 | 8010 | その他の制限には、ディレクトリ、オープンしているファイル、既に存在している |
| 13680 | 8011 | ファイルに対して使えるか、といったことを含みます。 |
| 13681 | 詳しくは、L<perlport> および | |
| 8012 | 詳しくは、L<perlport> および rename(2) man ページあるいは同様の | |
| 13682 | 8013 | システムドキュメントを参照してください。 |
| 13683 | 8014 | |
| 13684 | =begin original | |
| 13685 | ||
| 13686 | For a platform independent L<C<move>|File::Copy/move> function look at | |
| 13687 | the L<File::Copy> module. | |
| 13688 | ||
| 13689 | =end original | |
| 13690 | ||
| 13691 | プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については | |
| 13692 | L<File::Copy> モジュールを参照してください。 | |
| 13693 | ||
| 13694 | =begin original | |
| 13695 | ||
| 13696 | Portability issues: L<perlport/rename>. | |
| 13697 | ||
| 13698 | =end original | |
| 13699 | ||
| 13700 | 移植性の問題: L<perlport/rename>。 | |
| 13701 | ||
| 13702 | 8015 | =item require VERSION |
| 13703 | X<require> | |
| 13704 | 8016 | |
| 13705 | 8017 | =item require EXPR |
| 13706 | 8018 | |
| 13707 | 8019 | =item require |
| 13708 | 8020 | |
| 13709 | =for Pod::Functions load in external functions from a library at runtime | |
| 13710 | ||
| 13711 | 8021 | =begin original |
| 13712 | 8022 | |
| 13713 | Demands | |
| 8023 | Demands some semantics specified by EXPR, or by C<$_> if EXPR is not | |
| 13714 | s | |
| 8024 | supplied. | |
| 13715 | 8025 | |
| 13716 | 8026 | =end original |
| 13717 | 8027 | |
| 13718 | ||
| 8028 | EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。 | |
| 13719 | EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を | |
| 13720 | 要求します。 | |
| 13721 | 8029 | |
| 13722 | 8030 | =begin original |
| 13723 | 8031 | |
| 13724 | VERSION | |
| 8032 | If a VERSION is specified as a literal of the form v5.6.1, | |
| 13725 | ||
| 8033 | demands that the current version of Perl (C<$^V> or $PERL_VERSION) be | |
| 13726 | ||
| 8034 | at least as recent as that version, at run time. (For compatibility | |
| 13727 | ||
| 8035 | with older versions of Perl, a numeric argument will also be interpreted | |
| 13728 | ||
| 8036 | as VERSION.) Compare with L</use>, which can do a similar check at | |
| 13729 | L<C<use>|/use Module VERSION LIST>, which can do a similar check at | |
| 13730 | 8037 | compile time. |
| 13731 | 8038 | |
| 13732 | 8039 | =end original |
| 13733 | 8040 | |
| 13734 | VERSION | |
| 8041 | VERSION が v5.6.1 の形で指定されると、実行時の | |
| 13735 | ( | |
| 8042 | Perl の現在のバージョン(C<$^V> または $PERL_VERSION)が | |
| 13736 | ||
| 8043 | そのバージョン以降であることを要求します。 | |
| 13737 | ||
| 8044 | (古いバージョンの Perl との互換性のために、数値の引数も | |
| 13738 | VERSION | |
| 8045 | VERSION として解釈されます) | |
| 13739 | L< | |
| 8046 | L</use> と似ていますが、これはコンパイル時にチェックされます。 | |
| 13740 | チェックされます。 | |
| 13741 | 8047 | |
| 13742 | ||
| 8048 | require v5.6.1; # run time version check | |
| 8049 | require 5.6.1; # ditto | |
| 8050 | require 5.005_03; # float version allowed for compatibility | |
| 13743 | 8051 | |
| 13744 | Specifying VERSION as a numeric argument of the form 5.024001 should | |
| 13745 | generally be avoided as older less readable syntax compared to | |
| 13746 | v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric | |
| 13747 | form was the only supported syntax, which is why you might see it in | |
| 13748 | older code. | |
| 13749 | ||
| 13750 | =end original | |
| 13751 | ||
| 13752 | VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; | |
| 13753 | v5.24.1 に比べてより古く読みにくい文法だからです。 | |
| 13754 | (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な | |
| 13755 | 数値形式が唯一対応している文法でした; これが古いコードでこれを | |
| 13756 | 見るかも知れない理由です。 | |
| 13757 | ||
| 13758 | 8052 | =begin original |
| 13759 | 8053 | |
| 13760 | ||
| 8054 | Otherwise, demands that a library file be included if it hasn't already | |
| 13761 | | |
| 8055 | been included. The file is included via the do-FILE mechanism, which is | |
| 13762 | | |
| 8056 | essentially just a variety of C<eval>. Has semantics similar to the following | |
| 13763 | ||
| 8057 | subroutine: | |
| 13764 | 8058 | |
| 13765 | 8059 | =end original |
| 13766 | 8060 | |
| 13767 | ||
| 8061 | それ以外の場合には、既に読み込まれていないときに、 | |
| 13768 | ||
| 8062 | 読み込むライブラリファイルを要求するものとなります。 | |
| 13769 | | |
| 8063 | そのファイルは、基本的には C<eval> の一種である、 | |
| 8064 | do-FILE によって読み込まれます。 | |
| 8065 | 意味的には、次のようなサブルーチンと同じようなものです: | |
| 13770 | 8066 | |
| 13771 | =begin original | |
| 13772 | ||
| 13773 | Otherwise, L<C<require>|/require VERSION> demands that a library file be | |
| 13774 | included if it hasn't already been included. The file is included via | |
| 13775 | the do-FILE mechanism, which is essentially just a variety of | |
| 13776 | L<C<eval>|/eval EXPR> with the | |
| 13777 | caveat that lexical variables in the invoking script will be invisible | |
| 13778 | to the included code. If it were implemented in pure Perl, it | |
| 13779 | would have semantics similar to the following: | |
| 13780 | ||
| 13781 | =end original | |
| 13782 | ||
| 13783 | それ以外の場合には、L<C<require>|/require VERSION> は、既に | |
| 13784 | 読み込まれていないときに読み込むライブラリファイルを要求するものとなります。 | |
| 13785 | そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、 | |
| 13786 | do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は | |
| 13787 | 読み込まれたコードから見えないという欠点があります。 | |
| 13788 | ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと | |
| 13789 | 同じようなものです: | |
| 13790 | ||
| 13791 | use Carp 'croak'; | |
| 13792 | use version; | |
| 13793 | ||
| 13794 | 8067 | sub require { |
| 13795 | ||
| 8068 | my($filename) = @_; | |
| 13796 | ||
| 8069 | return 1 if $INC{$filename}; | |
| 13797 | ||
| 8070 | my($realfilename,$result); | |
| 13798 | | |
| 8071 | ITER: { | |
| 13799 | | |
| 8072 | foreach $prefix (@INC) { | |
| 13800 | | |
| 8073 | $realfilename = "$prefix/$filename"; | |
| 13801 | | |
| 8074 | if (-f $realfilename) { | |
| 13802 | | |
| 8075 | $INC{$filename} = $realfilename; | |
| 8076 | $result = do $realfilename; | |
| 13804 | | |
| 8077 | last ITER; | |
| 13805 | ||
| 8078 | } | |
| 13806 | | |
| 8079 | } | |
| 13807 | | |
| 8080 | die "Can't find $filename in \@INC"; | |
| 8081 | } | |
| 13809 | | |
| 8082 | delete $INC{$filename} if $@ || !$result; | |
| 13810 | | |
| 8083 | die $@ if $@; | |
| 13811 | | |
| 8084 | die "$filename did not return true value" unless $result; | |
| 13812 | | |
| 8085 | return $result; | |
| 13813 | # (see text below about possible appending of .pmc | |
| 13814 | # suffix to $filename) | |
| 13815 | my $realfilename = "$prefix/$filename"; | |
| 13816 | next if ! -e $realfilename || -d _ || -b _; | |
| 13817 | $INC{$filename} = $realfilename; | |
| 13818 | my $result = do($realfilename); | |
| 13819 | # but run in caller's namespace | |
| 13820 | ||
| 13821 | if (!defined $result) { | |
| 13822 | $INC{$filename} = undef; | |
| 13823 | croak $@ ? "$@Compilation failed in require" | |
| 13824 | : "Can't locate $filename: $!\n"; | |
| 13825 | } | |
| 13826 | if (!$result) { | |
| 13827 | delete $INC{$filename}; | |
| 13828 | croak "$filename did not return true value"; | |
| 13829 | } | |
| 13830 | $! = 0; | |
| 13831 | return $result; | |
| 13832 | } | |
| 13833 | croak "Can't locate $filename in \@INC ..."; | |
| 13834 | 8086 | } |
| 13835 | 8087 | |
| 13836 | 8088 | =begin original |
| 13837 | 8089 | |
| 13838 | 8090 | Note that the file will not be included twice under the same specified |
| 13839 | name. | |
| 8091 | name. The file must return true as the last statement to indicate | |
| 13840 | ||
| 13841 | =end original | |
| 13842 | ||
| 13843 | ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。 | |
| 13844 | ||
| 13845 | =begin original | |
| 13846 | ||
| 13847 | The file must return true as the last statement to indicate | |
| 13848 | 8092 | successful execution of any initialization code, so it's customary to |
| 13849 | 8093 | end such a file with C<1;> unless you're sure it'll return true |
| 13850 | 8094 | otherwise. But it's better just to put the C<1;>, in case you add more |
| 13851 | 8095 | statements. |
| 13852 | 8096 | |
| 13853 | 8097 | =end original |
| 13854 | 8098 | |
| 13855 | ||
| 8099 | ファイルは、同じ名前で 2 回読み込まれることはありません。 | |
| 13856 | ||
| 8100 | 初期化コードの実行がうまくいったことを示すために、 | |
| 8101 | ファイルは真を返さなければなりませんから、 | |
| 8102 | 真を返すようになっている自信がある場合を除いては、 | |
| 13857 | 8103 | ファイルの最後に C<1;> と書くのが習慣です。 |
| 13858 | ||
| 8104 | 実行文を追加するような場合に備えて、C<1;> と書いておいた方が | |
| 8105 | 良いでしょう。 | |
| 13859 | 8106 | |
| 13860 | 8107 | =begin original |
| 13861 | 8108 | |
| 13862 | If EXPR is a bareword, | |
| 8109 | If EXPR is a bareword, the require assumes a "F<.pm>" extension and | |
| 13863 | ||
| 8110 | replaces "F<::>" with "F</>" in the filename for you, | |
| 13864 | 8111 | to make it easy to load standard modules. This form of loading of |
| 13865 | modules does not risk altering your namespace | |
| 8112 | modules does not risk altering your namespace. | |
| 13866 | the stash for the required module. | |
| 13867 | 8113 | |
| 13868 | 8114 | =end original |
| 13869 | 8115 | |
| 13870 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
| 8116 | EXPR が裸の単語であるときには、標準モジュールのロードを | |
| 13871 | ||
| 8117 | 簡単にするように、require は拡張子が "F<.pm>" であり、 | |
| 13872 | 変えたものがファイル名であると仮定します。 | |
| 8118 | "F<::>" を "F</>" に変えたものがファイル名であると仮定します。 | |
| 13873 | この形式のモジュールロードは、 | |
| 8119 | この形式のモジュールロードは、 | |
| 13874 | ||
| 8120 | 名前空間を変更してしまう危険はありません。 | |
| 13875 | 8121 | |
| 13876 | 8122 | =begin original |
| 13877 | 8123 | |
| 13878 | 8124 | In other words, if you try this: |
| 13879 | 8125 | |
| 13880 | 8126 | =end original |
| 13881 | 8127 | |
| 13882 | 8128 | 言い換えると、以下のようにすると: |
| 13883 | 8129 | |
| 13884 | require Foo::Bar; | |
| 8130 | require Foo::Bar; # a splendid bareword | |
| 13885 | 8131 | |
| 13886 | 8132 | =begin original |
| 13887 | 8133 | |
| 13888 | The require function will actually look for the F<Foo/Bar.pm> file in the | |
| 8134 | The require function will actually look for the "F<Foo/Bar.pm>" file in the | |
| 13889 | directories specified in the | |
| 8135 | directories specified in the C<@INC> array. | |
| 13890 | autovivify the C<Foo::Bar::> stash at compile time. | |
| 13891 | 8136 | |
| 13892 | =end original | |
| 13893 | ||
| 13894 | require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある | |
| 13895 | F<Foo/Bar.pm> ファイルを探し、コンパイル時に | |
| 13896 | C<Foo::Bar::> のスタッシュを自動有効化します。 | |
| 13897 | ||
| 13898 | =begin original | |
| 13899 | ||
| 13900 | 8137 | But if you try this: |
| 13901 | 8138 | |
| 13902 | 8139 | =end original |
| 13903 | 8140 | |
| 8141 | require 関数は C<@INC> 配列で指定されたディレクトリにある | |
| 8142 | "F<Foo/Bar.pm>" ファイルを探します。 | |
| 8143 | ||
| 13904 | 8144 | しかし、以下のようにすると: |
| 13905 | 8145 | |
| 13906 | | |
| 8146 | $class = 'Foo::Bar'; | |
| 13907 | require $class; | |
| 8147 | require $class; # $class is not a bareword | |
| 13908 | 8148 | #or |
| 13909 | require "Foo::Bar"; | |
| 8149 | require "Foo::Bar"; # not a bareword because of the "" | |
| 13910 | 8150 | |
| 13911 | 8151 | =begin original |
| 13912 | 8152 | |
| 13913 | The require function will look for the F<Foo::Bar> file in the | |
| 8153 | The require function will look for the "F<Foo::Bar>" file in the @INC array and | |
| 13914 | ||
| 8154 | will complain about not finding "F<Foo::Bar>" there. In this case you can do: | |
| 13915 | will complain about not finding F<Foo::Bar> there. In this case you can do: | |
| 13916 | 8155 | |
| 13917 | 8156 | =end original |
| 13918 | 8157 | |
| 13919 | require 関数は | |
| 8158 | require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、 | |
| 13920 | おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。 | |
| 8159 | おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。 | |
| 13921 | このような場合には、以下のように: | |
| 8160 | このような場合には、以下のようにします: | |
| 13922 | 8161 | |
| 13923 | 8162 | eval "require $class"; |
| 13924 | 8163 | |
| 13925 | 8164 | =begin original |
| 13926 | 8165 | |
| 13927 | or you | |
| 8166 | For a yet-more-powerful import facility, see L</use> and L<perlmod>. | |
| 13928 | 8167 | |
| 13929 | 8168 | =end original |
| 13930 | 8169 | |
| 13931 | あるいは次のようにも出来ます | |
| 13932 | ||
| 13933 | require "Foo/Bar.pm"; | |
| 13934 | ||
| 13935 | =begin original | |
| 13936 | ||
| 13937 | Neither of these forms will autovivify any stashes at compile time and | |
| 13938 | only have run time effects. | |
| 13939 | ||
| 13940 | =end original | |
| 13941 | ||
| 13942 | これらのどちらもコンパイル時にスタッシュを自動有効化せず、 | |
| 13943 | 実行時の効果のみを持ちます。 | |
| 13944 | ||
| 13945 | =begin original | |
| 13946 | ||
| 13947 | Now that you understand how L<C<require>|/require VERSION> looks for | |
| 13948 | files with a bareword argument, there is a little extra functionality | |
| 13949 | going on behind the scenes. Before L<C<require>|/require VERSION> looks | |
| 13950 | for a F<.pm> extension, it will first look for a similar filename with a | |
| 13951 | F<.pmc> extension. If this file is found, it will be loaded in place of | |
| 13952 | any file ending in a F<.pm> extension. This applies to both the explicit | |
| 13953 | C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form. | |
| 13954 | ||
| 13955 | =end original | |
| 13956 | ||
| 13957 | 引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを | |
| 13958 | 探すかを理解してください; 水面下でちょっとした追加の機能があります。 | |
| 13959 | L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず | |
| 13960 | 拡張子 F<.pmc> を持つファイルを探します。 | |
| 13961 | このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに | |
| 13962 | 読み込まれます。 | |
| 13963 | これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の | |
| 13964 | 両方に適用されます。 | |
| 13965 | ||
| 13966 | =begin original | |
| 13967 | ||
| 13968 | You can also insert hooks into the import facility by putting Perl code | |
| 13969 | directly into the L<C<@INC>|perlvar/@INC> array. There are three forms | |
| 13970 | of hooks: subroutine references, array references, and blessed objects. | |
| 13971 | ||
| 13972 | =end original | |
| 13973 | ||
| 13974 | L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に | |
| 13975 | フックを挿入できます。 | |
| 13976 | 3 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、 | |
| 13977 | bless されたオブジェクトです。 | |
| 13978 | ||
| 13979 | =begin original | |
| 13980 | ||
| 13981 | Subroutine references are the simplest case. When the inclusion system | |
| 13982 | walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this | |
| 13983 | subroutine gets called with two parameters, the first a reference to | |
| 13984 | itself, and the second the name of the file to be included (e.g., | |
| 13985 | F<Foo/Bar.pm>). The subroutine should return either nothing or else a | |
| 13986 | list of up to four values in the following order: | |
| 13987 | ||
| 13988 | =end original | |
| 13989 | ||
| 13990 | サブルーチンへのリファレンスは一番単純な場合です。 | |
| 13991 | インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに | |
| 13992 | 出会った場合、このサブルーチンは二つの引数と共に呼び出されます; | |
| 13993 | 一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名 | |
| 13994 | (F<Foo/Bar.pm> など)です。 | |
| 13995 | サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。 | |
| 13996 | ||
| 13997 | =over | |
| 13998 | ||
| 13999 | =item 1 | |
| 14000 | ||
| 14001 | =begin original | |
| 14002 | ||
| 14003 | A reference to a scalar, containing any initial source code to prepend to | |
| 14004 | the file or generator output. | |
| 14005 | ||
| 14006 | =end original | |
| 14007 | ||
| 14008 | ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む | |
| 14009 | スカラへのリファレンス。 | |
| 14010 | ||
| 14011 | =item 2 | |
| 14012 | ||
| 14013 | =begin original | |
| 14014 | ||
| 14015 | A filehandle, from which the file will be read. | |
| 14016 | ||
| 14017 | =end original | |
| 14018 | ||
| 14019 | ファイルが読み込まれるファイルハンドル。 | |
| 14020 | ||
| 14021 | =item 3 | |
| 14022 | ||
| 14023 | =begin original | |
| 14024 | ||
| 14025 | A reference to a subroutine. If there is no filehandle (previous item), | |
| 14026 | then this subroutine is expected to generate one line of source code per | |
| 14027 | call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then | |
| 14028 | finally at end of file returning 0. If there is a filehandle, then the | |
| 14029 | subroutine will be called to act as a simple source filter, with the | |
| 14030 | line as read in L<C<$_>|perlvar/$_>. | |
| 14031 | Again, return 1 for each valid line, and 0 after all lines have been | |
| 14032 | returned. | |
| 14033 | For historical reasons the subroutine will receive a meaningless argument | |
| 14034 | (in fact always the numeric value zero) as C<$_[0]>. | |
| 14035 | ||
| 14036 | =end original | |
| 14037 | ||
| 14038 | サブルーチンへのリファレンス。 | |
| 14039 | (一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に | |
| 14040 | 一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を | |
| 14041 | 返し、それから最終的にファイル終端で 0 を返すものと想定されます。 | |
| 14042 | ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして | |
| 14043 | 振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。 | |
| 14044 | 再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。 | |
| 14045 | 歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数 | |
| 14046 | (実際には常に数値 0) を受け取ります。 | |
| 14047 | ||
| 14048 | =item 4 | |
| 14049 | ||
| 14050 | =begin original | |
| 14051 | ||
| 14052 | Optional state for the subroutine. The state is passed in as C<$_[1]>. | |
| 14053 | ||
| 14054 | =end original | |
| 14055 | ||
| 14056 | サブルーチンのための状態(オプション)。 | |
| 14057 | 状態は C<$_[1]> として渡されます。 | |
| 14058 | ||
| 14059 | =back | |
| 14060 | ||
| 14061 | =begin original | |
| 14062 | ||
| 14063 | If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the | |
| 14064 | first 3 values above is returned, then L<C<require>|/require VERSION> | |
| 14065 | looks at the remaining elements of L<C<@INC>|perlvar/@INC>. | |
| 14066 | Note that this filehandle must be a real filehandle (strictly a typeglob | |
| 14067 | or reference to a typeglob, whether blessed or unblessed); tied filehandles | |
| 14068 | will be ignored and processing will stop there. | |
| 14069 | ||
| 14070 | =end original | |
| 14071 | ||
| 14072 | 空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも | |
| 14073 | 一致しないものが返されると、L<C<require>|/require VERSION> は | |
| 14074 | L<C<@INC>|perlvar/@INC> の残りの要素を見ます。 | |
| 14075 | このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの | |
| 14076 | リファレンス、bless されているかに関わらず)でなければなりません; | |
| 14077 | tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。 | |
| 14078 | ||
| 14079 | =begin original | |
| 14080 | ||
| 14081 | If the hook is an array reference, its first element must be a subroutine | |
| 14082 | reference. This subroutine is called as above, but the first parameter is | |
| 14083 | the array reference. This lets you indirectly pass arguments to | |
| 14084 | the subroutine. | |
| 14085 | ||
| 14086 | =end original | |
| 14087 | ||
| 14088 | フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの | |
| 14089 | リファレンスでなければなりません。 | |
| 14090 | このサブルーチンは上述のように呼び出されますが、その最初の引数は | |
| 14091 | 配列のリファレンスです。 | |
| 14092 | これによって、間接的にサブルーチンに引数を渡すことが出来ます。 | |
| 14093 | ||
| 14094 | =begin original | |
| 14095 | ||
| 14096 | In other words, you can write: | |
| 14097 | ||
| 14098 | =end original | |
| 14099 | ||
| 14100 | 言い換えると、以下のように書いたり: | |
| 14101 | ||
| 14102 | push @INC, \&my_sub; | |
| 14103 | sub my_sub { | |
| 14104 | my ($coderef, $filename) = @_; # $coderef is \&my_sub | |
| 14105 | ... | |
| 14106 | } | |
| 14107 | ||
| 14108 | =begin original | |
| 14109 | ||
| 14110 | or: | |
| 14111 | ||
| 14112 | =end original | |
| 14113 | ||
| 14114 | または以下のように書けます: | |
| 14115 | ||
| 14116 | push @INC, [ \&my_sub, $x, $y, ... ]; | |
| 14117 | sub my_sub { | |
| 14118 | my ($arrayref, $filename) = @_; | |
| 14119 | # Retrieve $x, $y, ... | |
| 14120 | my (undef, @parameters) = @$arrayref; | |
| 14121 | ... | |
| 14122 | } | |
| 14123 | ||
| 14124 | =begin original | |
| 14125 | ||
| 14126 | If the hook is an object, it must provide an C<INC> method that will be | |
| 14127 | called as above, the first parameter being the object itself. (Note that | |
| 14128 | you must fully qualify the sub's name, as unqualified C<INC> is always forced | |
| 14129 | into package C<main>.) Here is a typical code layout: | |
| 14130 | ||
| 14131 | =end original | |
| 14132 | ||
| 14133 | フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります; | |
| 14134 | それが、最初の引数をオブジェクト自身として上述のように呼び出されます。 | |
| 14135 | (修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、 | |
| 14136 | サブルーチン名は完全修飾する必要があることに注意してください。) | |
| 14137 | 以下は典型的なコードレイアウトです: | |
| 14138 | ||
| 14139 | # In Foo.pm | |
| 14140 | package Foo; | |
| 14141 | sub new { ... } | |
| 14142 | sub Foo::INC { | |
| 14143 | my ($self, $filename) = @_; | |
| 14144 | ... | |
| 14145 | } | |
| 14146 | ||
| 14147 | # In the main program | |
| 14148 | push @INC, Foo->new(...); | |
| 14149 | ||
| 14150 | =begin original | |
| 14151 | ||
| 14152 | These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry | |
| 14153 | corresponding to the files they have loaded. See L<perlvar/%INC>. | |
| 14154 | ||
| 14155 | =end original | |
| 14156 | ||
| 14157 | これらのフックは、読み込まれるファイルに対応する | |
| 14158 | L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。 | |
| 14159 | L<perlvar/%INC> を参照してください。 | |
| 14160 | ||
| 14161 | =begin original | |
| 14162 | ||
| 14163 | For a yet-more-powerful import facility, see | |
| 14164 | L<C<use>|/use Module VERSION LIST> and L<perlmod>. | |
| 14165 | ||
| 14166 | =end original | |
| 14167 | ||
| 14168 | 8170 | より強力な import 機能については、このドキュメントの |
| 14169 | L< | |
| 8171 | L</use> の項と、L<perlmod> を参照してください。 | |
| 14170 | 8172 | |
| 14171 | 8173 | =item reset EXPR |
| 14172 | X<reset> | |
| 14173 | 8174 | |
| 14174 | 8175 | =item reset |
| 14175 | 8176 | |
| 14176 | =for Pod::Functions clear all variables of a given name | |
| 14177 | ||
| 14178 | 8177 | =begin original |
| 14179 | 8178 | |
| 14180 | Generally used in a | |
| 8179 | Generally used in a C<continue> block at the end of a loop to clear | |
| 14181 | ||
| 8180 | variables and reset C<??> searches so that they work again. The | |
| 14182 | work again. The | |
| 14183 | 8181 | expression is interpreted as a list of single characters (hyphens |
| 14184 | allowed for ranges). All variables | |
| 8182 | allowed for ranges). All variables and arrays beginning with one of | |
| 14185 | in the current package beginning with one of | |
| 14186 | 8183 | those letters are reset to their pristine state. If the expression is |
| 14187 | omitted, one-match searches (C< | |
| 8184 | omitted, one-match searches (C<?pattern?>) are reset to match again. Resets | |
| 14188 | ||
| 8185 | only variables or searches in the current package. Always returns | |
| 14189 | 8186 | 1. Examples: |
| 14190 | 8187 | |
| 14191 | 8188 | =end original |
| 14192 | 8189 | |
| 14193 | 通常、ループの最後に、変数をクリアし、C< | |
| 8190 | 通常、ループの最後に、変数をクリアし、C<??> 検索を再び | |
| 14194 | リセットするため、 | |
| 8191 | 動作するようにリセットするため、C<continue> ブロックで使われます。 | |
| 14195 | 8192 | EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と |
| 14196 | 8193 | 解釈されます。 |
| 14197 | 名前がその文字のいずれかで始まる | |
| 8194 | 名前がその文字のいずれかで始まる変数や配列は、 | |
| 14198 | (スカラ、配列、ハッシュ)は、 | |
| 14199 | 8195 | 最初の状態にリセットされます。 |
| 14200 | EXPR を省略すると、1 回検索 (C< | |
| 8196 | EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように | |
| 14201 | 8197 | リセットできます。 |
| 14202 | 8198 | カレントパッケージの変数もしくは検索だけがリセットされます。 |
| 14203 | 8199 | 常に 1 を返します。 |
| 14204 | 8200 | 例: |
| 14205 | 8201 | |
| 14206 | reset 'X'; | |
| 8202 | reset 'X'; # reset all X variables | |
| 14207 | reset 'a-z'; | |
| 8203 | reset 'a-z'; # reset lower case variables | |
| 14208 | reset; | |
| 8204 | reset; # just reset ?one-time? searches | |
| 14209 | 8205 | |
| 14210 | 8206 | =begin original |
| 14211 | 8207 | |
| 14212 | 8208 | Resetting C<"A-Z"> is not recommended because you'll wipe out your |
| 14213 | ||
| 8209 | C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package | |
| 14214 | ||
| 8210 | variables--lexical variables are unaffected, but they clean themselves | |
| 8211 | up on scope exit anyway, so you'll probably want to use them instead. | |
| 8212 | See L</my>. | |
| 14215 | 8213 | |
| 14216 | 8214 | =end original |
| 14217 | 8215 | |
| 14218 | reset C<"A-Z"> とすると、 | |
| 8216 | reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも | |
| 14219 | ||
| 8217 | なくなってしまいますから、止めた方が良いでしょう。 | |
| 14220 | ||
| 8218 | パッケージ変数だけがリセットされます。 | |
| 8219 | レキシカル変数は、影響を受けませんが、スコープから外れれば、 | |
| 8220 | 自動的に綺麗になりますので、これからは、こちらを使うようにした方が | |
| 8221 | よいでしょう。 | |
| 8222 | L</my> を参照してください。 | |
| 14221 | 8223 | |
| 14222 | =begin original | |
| 14223 | ||
| 14224 | Resets only package variables; lexical variables are unaffected, but | |
| 14225 | they clean themselves up on scope exit anyway, so you'll probably want | |
| 14226 | to use them instead. See L<C<my>|/my VARLIST>. | |
| 14227 | ||
| 14228 | =end original | |
| 14229 | ||
| 14230 | パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、 | |
| 14231 | スコープから外れれば自動的に綺麗になるので、これからはこちらを | |
| 14232 | 使うようにした方がよいでしょう。 | |
| 14233 | L<C<my>|/my VARLIST> を参照してください。 | |
| 14234 | ||
| 14235 | 8224 | =item return EXPR |
| 14236 | X<return> | |
| 14237 | 8225 | |
| 14238 | 8226 | =item return |
| 14239 | 8227 | |
| 14240 | =for Pod::Functions get out of a function early | |
| 14241 | ||
| 14242 | 8228 | =begin original |
| 14243 | 8229 | |
| 14244 | Returns from a subroutine, | |
| 8230 | Returns from a subroutine, C<eval>, or C<do FILE> with the value | |
| 14245 | L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex | |
| 14246 | eval block (but not a L<C<grep>|/grep BLOCK LIST> or | |
| 14247 | L<C<map>|/map BLOCK LIST> block) with the value | |
| 14248 | 8231 | given in EXPR. Evaluation of EXPR may be in list, scalar, or void |
| 14249 | 8232 | context, depending on how the return value will be used, and the context |
| 14250 | may vary from one execution to the next (see | |
| 8233 | may vary from one execution to the next (see C<wantarray>). If no EXPR | |
| 14251 | L<C<wantarray>|/wantarray>). If no EXPR | |
| 14252 | 8234 | is given, returns an empty list in list context, the undefined value in |
| 14253 | scalar context, and (of course) nothing at all in void context. | |
| 8235 | scalar context, and (of course) nothing at all in a void context. | |
| 14254 | 8236 | |
| 14255 | 8237 | =end original |
| 14256 | 8238 | |
| 14257 | サブルーチン, | |
| 8239 | サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、 | |
| 14258 | ||
| 8240 | リターンします。 | |
| 14259 | ||
| 8241 | EXPR の評価は、返り値がどのように使われるかによって | |
| 14260 | ||
| 8242 | リスト、スカラ、無効コンテキストになります。 | |
| 14261 | ||
| 8243 | またコンテキストは実行毎に変わります(C<wantarray> を参照してください)。 | |
| 14262 | EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、 | |
| 14263 | 無効コンテキストになります; またコンテキストは実行毎に変わります | |
| 14264 | (L<C<wantarray>|/wantarray> を参照してください)。 | |
| 14265 | 8244 | EXPR が指定されなかった場合は、リストコンテキストでは空リストを、 |
| 14266 | スカラコンテキストでは未定義値を返します | |
| 8245 | スカラコンテキストでは未定義値を返します。 | |
| 14267 | 無効コンテキストでは何も返しません。 | |
| 8246 | そして(もちろん)無効コンテキストでは何も返しません。 | |
| 14268 | 8247 | |
| 14269 | 8248 | =begin original |
| 14270 | 8249 | |
| 14271 | ( | |
| 8250 | (Note that in the absence of a explicit C<return>, a subroutine, eval, | |
| 14272 | L | |
| 8251 | or do FILE will automatically return the value of the last expression | |
| 14273 | or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression | |
| 14274 | 8252 | evaluated.) |
| 14275 | 8253 | |
| 14276 | 8254 | =end original |
| 14277 | 8255 | |
| 14278 | (サブルーチン, | |
| 8256 | (サブルーチン, eval, do FILE に明示的に C<return> が | |
| 14279 | ||
| 8257 | なければ、最後に評価された値で、自動的にリターンします。) | |
| 14280 | 自動的にリターンします。) | |
| 14281 | 8258 | |
| 14282 | =begin original | |
| 14283 | ||
| 14284 | Unlike most named operators, this is also exempt from the | |
| 14285 | looks-like-a-function rule, so C<return ("foo")."bar"> will | |
| 14286 | cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>. | |
| 14287 | ||
| 14288 | =end original | |
| 14289 | ||
| 14290 | ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも | |
| 14291 | 免れるので、C<return ("foo")."bar"> とすると C<"bar"> は | |
| 14292 | L<C<return>|/return EXPR> への引数の一部となります。 | |
| 14293 | ||
| 14294 | 8259 | =item reverse LIST |
| 14295 | X<reverse> X<rev> X<invert> | |
| 14296 | 8260 | |
| 14297 | =for Pod::Functions flip a string or a list | |
| 14298 | ||
| 14299 | 8261 | =begin original |
| 14300 | 8262 | |
| 14301 | 8263 | In list context, returns a list value consisting of the elements |
| 14302 | 8264 | of LIST in the opposite order. In scalar context, concatenates the |
| 14303 | 8265 | elements of LIST and returns a string value with all characters |
| 14304 | 8266 | in the opposite order. |
| 14305 | 8267 | |
| 14306 | 8268 | =end original |
| 14307 | 8269 | |
| 14308 | 8270 | リストコンテキストでは、LIST を構成する要素を逆順に並べた |
| 14309 | 8271 | リスト値を返します。 |
| 14310 | 8272 | スカラコンテキストでは、LIST の要素を連結して、 |
| 14311 | 8273 | 全ての文字を逆順にした文字列を返します。 |
| 14312 | 8274 | |
| 14313 | print | |
| 8275 | print reverse <>; # line tac, last line first | |
| 14314 | 8276 | |
| 14315 | | |
| 8277 | undef $/; # for efficiency of <> | |
| 8278 | print scalar reverse <>; # character tac, last line tsrif | |
| 14316 | 8279 | |
| 14317 | 8280 | =begin original |
| 14318 | 8281 | |
| 14319 | Used without arguments in scalar context, L<C<reverse>|/reverse LIST> | |
| 14320 | reverses L<C<$_>|perlvar/$_>. | |
| 14321 | ||
| 14322 | =end original | |
| 14323 | ||
| 14324 | スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は | |
| 14325 | L<C<$_>|perlvar/$_> を逆順にします。 | |
| 14326 | ||
| 14327 | $_ = "dlrow ,olleH"; | |
| 14328 | print reverse; # No output, list context | |
| 14329 | print scalar reverse; # Hello, world | |
| 14330 | ||
| 14331 | =begin original | |
| 14332 | ||
| 14333 | Note that reversing an array to itself (as in C<@a = reverse @a>) will | |
| 14334 | preserve non-existent elements whenever possible; i.e., for non-magical | |
| 14335 | arrays or for tied arrays with C<EXISTS> and C<DELETE> methods. | |
| 14336 | ||
| 14337 | =end original | |
| 14338 | ||
| 14339 | (C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、 | |
| 14340 | 存在しない要素は可能なら(つまりマジカルでない配列や | |
| 14341 | C<EXISTS> と C<DELETE> メソッドがある tie された配列) | |
| 14342 | いつでも保存されることに注意してください。 | |
| 14343 | ||
| 14344 | =begin original | |
| 14345 | ||
| 14346 | 8282 | This operator is also handy for inverting a hash, although there are some |
| 14347 | 8283 | caveats. If a value is duplicated in the original hash, only one of those |
| 14348 | 8284 | can be represented as a key in the inverted hash. Also, this has to |
| 14349 | 8285 | unwind one hash and build a whole new one, which may take some time |
| 14350 | 8286 | on a large hash, such as from a DBM file. |
| 14351 | 8287 | |
| 14352 | 8288 | =end original |
| 14353 | 8289 | |
| 14354 | 8290 | この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。 |
| 14355 | 8291 | 元のハッシュで値が重複していると、それらのうち一つだけが |
| 14356 | 8292 | 逆順になったハッシュのキーとして表現されます。 |
| 14357 | 8293 | また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、 |
| 14358 | 8294 | DBM ファイルからのような大きなハッシュでは少し時間がかかります。 |
| 14359 | 8295 | |
| 14360 | | |
| 8296 | %by_name = reverse %by_address; # Invert the hash | |
| 14361 | 8297 | |
| 14362 | 8298 | =item rewinddir DIRHANDLE |
| 14363 | X<rewinddir> | |
| 14364 | 8299 | |
| 14365 | =for Pod::Functions reset directory handle | |
| 14366 | ||
| 14367 | 8300 | =begin original |
| 14368 | 8301 | |
| 14369 | 8302 | Sets the current position to the beginning of the directory for the |
| 14370 | ||
| 8303 | C<readdir> routine on DIRHANDLE. | |
| 14371 | 8304 | |
| 14372 | 8305 | =end original |
| 14373 | 8306 | |
| 14374 | DIRHANDLE に対する | |
| 8307 | DIRHANDLE に対する C<readdir> ルーチンの現在位置を | |
| 14375 | 8308 | ディレクトリの最初に設定します。 |
| 14376 | 8309 | |
| 14377 | =begin original | |
| 14378 | ||
| 14379 | Portability issues: L<perlport/rewinddir>. | |
| 14380 | ||
| 14381 | =end original | |
| 14382 | ||
| 14383 | 移植性の問題: L<perlport/rewinddir>。 | |
| 14384 | ||
| 14385 | 8310 | =item rindex STR,SUBSTR,POSITION |
| 14386 | X<rindex> | |
| 14387 | 8311 | |
| 14388 | 8312 | =item rindex STR,SUBSTR |
| 14389 | 8313 | |
| 14390 | =for Pod::Functions right-to-left substring search | |
| 14391 | ||
| 14392 | 8314 | =begin original |
| 14393 | 8315 | |
| 14394 | Works just like | |
| 8316 | Works just like index() except that it returns the position of the LAST | |
| 14395 | returns the position of the I<last> | |
| 14396 | 8317 | occurrence of SUBSTR in STR. If POSITION is specified, returns the |
| 14397 | last occurrence | |
| 8318 | last occurrence at or before that position. | |
| 14398 | 8319 | |
| 14399 | 8320 | =end original |
| 14400 | 8321 | |
| 14401 | STR 中で | |
| 8322 | STR 中で最後に見つかった SUBSTR の位置を返すことを除いて、 | |
| 14402 | ||
| 8323 | index() と同じように動作します。 | |
| 14403 | POSITION を指定すると、その位置 | |
| 8324 | POSITION を指定すると、その位置より前の、最後の位置を返します。 | |
| 14404 | 最後の位置を返します。 | |
| 14405 | 8325 | |
| 14406 | 8326 | =item rmdir FILENAME |
| 14407 | X<rmdir> X<rd> X<directory, remove> | |
| 14408 | 8327 | |
| 14409 | 8328 | =item rmdir |
| 14410 | 8329 | |
| 14411 | =for Pod::Functions remove a directory | |
| 14412 | ||
| 14413 | 8330 | =begin original |
| 14414 | 8331 | |
| 14415 | Deletes the directory specified by FILENAME if that directory is | |
| 8332 | Deletes the directory specified by FILENAME if that directory is empty. If it | |
| 14416 | ||
| 8333 | succeeds it returns true, otherwise it returns false and sets C<$!> (errno). If | |
| 14417 | ||
| 8334 | FILENAME is omitted, uses C<$_>. | |
| 14418 | L<C<$_>|perlvar/$_>. | |
| 14419 | 8335 | |
| 14420 | 8336 | =end original |
| 14421 | 8337 | |
| 14422 | 8338 | FILENAME で指定したディレクトリが空であれば、 |
| 14423 | 8339 | そのディレクトリを削除します。 |
| 14424 | 成功時には真を返し | |
| 8340 | 成功時には真を返し、失敗時には偽を返し、C<$!> (errno) を設定します。 | |
| 14425 | ||
| 8341 | FILENAMEを省略した場合には、C<$_> を使用します。 | |
| 14426 | FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。 | |
| 14427 | 8342 | |
| 14428 | =begin original | |
| 14429 | ||
| 14430 | To remove a directory tree recursively (C<rm -rf> on Unix) look at | |
| 14431 | the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path> | |
| 14432 | module. | |
| 14433 | ||
| 14434 | =end original | |
| 14435 | ||
| 14436 | ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、 | |
| 14437 | L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を | |
| 14438 | 参照してください。 | |
| 14439 | ||
| 14440 | 8343 | =item s/// |
| 14441 | 8344 | |
| 14442 | =for Pod::Functions replace a pattern with a string | |
| 14443 | ||
| 14444 | 8345 | =begin original |
| 14445 | 8346 | |
| 14446 | The substitution operator. See L<perlop | |
| 8347 | The substitution operator. See L<perlop>. | |
| 14447 | 8348 | |
| 14448 | 8349 | =end original |
| 14449 | 8350 | |
| 14450 | 8351 | 置換演算子。 |
| 14451 | L<perlop | |
| 8352 | L<perlop> を参照してください。 | |
| 14452 | 8353 | |
| 14453 | =item say FILEHANDLE LIST | |
| 14454 | X<say> | |
| 14455 | ||
| 14456 | =item say FILEHANDLE | |
| 14457 | ||
| 14458 | =item say LIST | |
| 14459 | ||
| 14460 | =item say | |
| 14461 | ||
| 14462 | =for Pod::Functions +say output a list to a filehandle, appending a newline | |
| 14463 | ||
| 14464 | =begin original | |
| 14465 | ||
| 14466 | Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a | |
| 14467 | newline. C<say LIST> is simply an abbreviation for | |
| 14468 | C<{ local $\ = "\n"; print LIST }>. To use FILEHANDLE without a LIST to | |
| 14469 | print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword | |
| 14470 | filehandle like C<FH>, not an indirect one like C<$fh>. | |
| 14471 | ||
| 14472 | =end original | |
| 14473 | ||
| 14474 | L<C<print>|/print FILEHANDLE LIST> と同様ですが、暗黙に改行が追加されます。 | |
| 14475 | C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。 | |
| 14476 | L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を | |
| 14477 | 使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような | |
| 14478 | 裸の単語のファイルハンドルを使わなければなりません。 | |
| 14479 | ||
| 14480 | =begin original | |
| 14481 | ||
| 14482 | L<C<say>|/say FILEHANDLE LIST> is available only if the | |
| 14483 | L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is | |
| 14484 | prefixed with C<CORE::>. The | |
| 14485 | L<C<"say"> feature|feature/The 'say' feature> is enabled automatically | |
| 14486 | with a C<use v5.10> (or higher) declaration in the current scope. | |
| 14487 | ||
| 14488 | =end original | |
| 14489 | ||
| 14490 | L<C<say>|/say FILEHANDLE LIST> は | |
| 14491 | L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が | |
| 14492 | 前置されたときにのみ利用可能です。 | |
| 14493 | L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで | |
| 14494 | C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。 | |
| 14495 | ||
| 14496 | 8354 | =item scalar EXPR |
| 14497 | X<scalar> X<context> | |
| 14498 | 8355 | |
| 14499 | =for Pod::Functions force a scalar context | |
| 14500 | ||
| 14501 | 8356 | =begin original |
| 14502 | 8357 | |
| 14503 | 8358 | Forces EXPR to be interpreted in scalar context and returns the value |
| 14504 | 8359 | of EXPR. |
| 14505 | 8360 | |
| 14506 | 8361 | =end original |
| 14507 | 8362 | |
| 14508 | 8363 | EXPR を強制的にスカラコンテキストで解釈されるようにして、 |
| 14509 | 8364 | EXPR の値を返します。 |
| 14510 | 8365 | |
| 14511 | | |
| 8366 | @counts = ( scalar @a, scalar @b, scalar @c ); | |
| 14512 | 8367 | |
| 14513 | 8368 | =begin original |
| 14514 | 8369 | |
| 14515 | 8370 | There is no equivalent operator to force an expression to |
| 14516 | 8371 | be interpolated in list context because in practice, this is never |
| 14517 | 8372 | needed. If you really wanted to do so, however, you could use |
| 14518 | 8373 | the construction C<@{[ (some expression) ]}>, but usually a simple |
| 14519 | 8374 | C<(some expression)> suffices. |
| 14520 | 8375 | |
| 14521 | 8376 | =end original |
| 14522 | 8377 | |
| 14523 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません | |
| 8378 | 式を強制的にリストコンテキストで解釈させるようにする演算子はありません。 | |
| 14524 | 8379 | 理論的には不要だからです。 |
| 14525 | 8380 | それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を |
| 14526 | 使えます | |
| 8381 | 使えます。 | |
| 8382 | しかし、普通は単に C<(some expression)> とすれば十分です。 | |
| 14527 | 8383 | |
| 14528 | 8384 | =begin original |
| 14529 | 8385 | |
| 14530 | Because | |
| 8386 | Because C<scalar> is unary operator, if you accidentally use for EXPR a | |
| 14531 | a | |
| 8387 | parenthesized list, this behaves as a scalar comma expression, evaluating | |
| 14532 | ||
| 8388 | all but the last element in void context and returning the final element | |
| 14533 | evaluatin | |
| 8389 | evaluated in scalar context. This is seldom what you want. | |
| 14534 | element evaluated in scalar context. This is seldom what you want. | |
| 14535 | 8390 | |
| 14536 | 8391 | =end original |
| 14537 | 8392 | |
| 14538 | ||
| 8393 | C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、 | |
| 14539 | ||
| 8394 | これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして | |
| 14540 | ||
| 8395 | 扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。 | |
| 14541 | 結果が返されます。 | |
| 14542 | 8396 | これがあなたの望むものであることはめったにないでしょう。 |
| 14543 | 8397 | |
| 14544 | 8398 | =begin original |
| 14545 | 8399 | |
| 14546 | 8400 | The following single statement: |
| 14547 | 8401 | |
| 14548 | 8402 | =end original |
| 14549 | 8403 | |
| 14550 | 以下の | |
| 8404 | 以下の 1 つの文は: | |
| 14551 | 8405 | |
| 14552 | ||
| 8406 | print uc(scalar(&foo,$bar)),$baz; | |
| 14553 | 8407 | |
| 14554 | 8408 | =begin original |
| 14555 | 8409 | |
| 14556 | 8410 | is the moral equivalent of these two: |
| 14557 | 8411 | |
| 14558 | 8412 | =end original |
| 14559 | 8413 | |
| 14560 | 以下の | |
| 8414 | 以下の 2 つの文と等価です。 | |
| 14561 | 8415 | |
| 14562 | ||
| 8416 | &foo; | |
| 14563 | ||
| 8417 | print(uc($bar),$baz); | |
| 14564 | 8418 | |
| 14565 | 8419 | =begin original |
| 14566 | 8420 | |
| 14567 | See L<perlop> for more details on unary operators and the comma operator | |
| 8421 | See L<perlop> for more details on unary operators and the comma operator. | |
| 14568 | and L<perldata> for details on evaluating a hash in scalar contex. | |
| 14569 | 8422 | |
| 14570 | 8423 | =end original |
| 14571 | 8424 | |
| 14572 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を | |
| 8425 | 単項演算子とカンマ演算子に関する詳細については L<perlop> を参照して下さい。 | |
| 14573 | スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を | |
| 14574 | 参照してください。 | |
| 14575 | 8426 | |
| 14576 | 8427 | =item seek FILEHANDLE,POSITION,WHENCE |
| 14577 | X<seek> X<fseek> X<filehandle, position> | |
| 14578 | 8428 | |
| 14579 | =for Pod::Functions reposition file pointer for random-access I/O | |
| 14580 | ||
| 14581 | 8429 | =begin original |
| 14582 | 8430 | |
| 14583 | Sets FILEHANDLE's position, just like the | |
| 8431 | Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>. | |
| 14584 | 8432 | FILEHANDLE may be an expression whose value gives the name of the |
| 14585 | filehandle. The values for WHENCE are C<0> to set the new position | |
| 8433 | filehandle. The values for WHENCE are C<0> to set the new position to | |
| 14586 | ||
| 8434 | POSITION, C<1> to set it to the current position plus POSITION, and | |
| 14587 | ||
| 8435 | C<2> to set it to EOF plus POSITION (typically negative). For WHENCE | |
| 14588 | ||
| 8436 | you may use the constants C<SEEK_SET>, C<SEEK_CUR>, and C<SEEK_END> | |
| 14589 | ||
| 8437 | (start of the file, current position, end of the file) from the Fcntl | |
| 14590 | ||
| 8438 | module. Returns C<1> upon success, C<0> otherwise. | |
| 14591 | otherwise. | |
| 14592 | 8439 | |
| 14593 | 8440 | =end original |
| 14594 | 8441 | |
| 14595 | C | |
| 8442 | C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の | |
| 14596 | 8443 | ファイルポインタを任意の位置に設定します。 |
| 14597 | 8444 | FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。 |
| 14598 | WHENCE の値が、C<0> ならば、 | |
| 8445 | WHENCE の値が、C<0> ならば、 | |
| 14599 | ||
| 8446 | 新しい位置を POSITION の位置へ、C<1> ならば、現在位置から | |
| 14600 | ||
| 8447 | POSITION 加えた位置へ、C<2> ならば、EOF から POSITION | |
| 14601 | 設定します。 | |
| 8448 | だけ加えた位置へ、新しい位置を設定します。 | |
| 14602 | この値には、 | |
| 8449 | この値には、Fcntl モジュールで使われている C<SEEK_SET>、 | |
| 14603 | C<SEEK_END> | |
| 8450 | C<SEEK_CUR>、C<SEEK_END> | |
| 14604 | 使うこともできます。 | |
| 8451 | (ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。 | |
| 14605 | 成功時には、C<1> を、失敗時には | |
| 8452 | 成功時には、C<1> を、失敗時には C<0> を返します。 | |
| 14606 | 8453 | |
| 14607 | 8454 | =begin original |
| 14608 | 8455 | |
| 14609 | ||
| 8456 | If you want to position file for C<sysread> or C<syswrite>, don't use | |
| 14610 | ||
| 8457 | C<seek>--buffering makes its effect on the file's system position | |
| 14611 | ||
| 8458 | unpredictable and non-portable. Use C<sysseek> instead. | |
| 14612 | L<C<tell>|/tell FILEHANDLE>, and | |
| 14613 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 14614 | family of functions use byte offsets, not character offsets, | |
| 14615 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 14616 | 8459 | |
| 14617 | 8460 | =end original |
| 14618 | 8461 | |
| 14619 | ||
| 8462 | C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、 | |
| 14620 | ファ | |
| 8463 | C<seek> は使えません -- バッファリングのために動作は予測不能で | |
| 14621 | ||
| 8464 | 移植性のないものになってしまいます。 | |
| 14622 | ||
| 8465 | 代わりに C<sysseek> を使ってください。 | |
| 14623 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 14624 | 文字オフセットではなくバイトオフセットを使います; | |
| 14625 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 14626 | 8466 | |
| 14627 | 8467 | =begin original |
| 14628 | 8468 | |
| 14629 | If you want to position the file for | |
| 14630 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
| 14631 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use | |
| 14632 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its | |
| 14633 | effect on the file's read-write position unpredictable and non-portable. | |
| 14634 | Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead. | |
| 14635 | ||
| 14636 | =end original | |
| 14637 | ||
| 14638 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
| 14639 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの | |
| 14640 | 位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は | |
| 14641 | 使えません; なぜならバッファリングのためにファイルの読み込み位置は | |
| 14642 | 動作は予測不能で移植性のないものになってしまいます。 | |
| 14643 | 代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。 | |
| 14644 | ||
| 14645 | =begin original | |
| 14646 | ||
| 14647 | 8469 | Due to the rules and rigors of ANSI C, on some systems you have to do a |
| 14648 | 8470 | seek whenever you switch between reading and writing. Amongst other |
| 14649 | things, this may have the effect of calling stdio's | |
| 8471 | things, this may have the effect of calling stdio's clearerr(3). | |
| 14650 | 8472 | A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position: |
| 14651 | 8473 | |
| 14652 | 8474 | =end original |
| 14653 | 8475 | |
| 14654 | 8476 | ANSI C の規則と困難により、システムによっては読み込みと書き込みを |
| 14655 | 8477 | 切り替える度にシークしなければならない場合があります。 |
| 14656 | その他のことの中で、これは stdio の | |
| 8478 | その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。 | |
| 14657 | 8479 | WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です: |
| 14658 | 8480 | |
| 14659 | seek( | |
| 8481 | seek(TEST,0,1); | |
| 14660 | 8482 | |
| 14661 | 8483 | =begin original |
| 14662 | 8484 | |
| 14663 | 8485 | This is also useful for applications emulating C<tail -f>. Once you hit |
| 14664 | EOF on your read and then sleep for a while, you | |
| 8486 | EOF on your read, and then sleep for a while, you might have to stick in a | |
| 14665 | ||
| 8487 | seek() to reset things. The C<seek> doesn't change the current position, | |
| 14666 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position, | |
| 14667 | 8488 | but it I<does> clear the end-of-file condition on the handle, so that the |
| 14668 | next C< | |
| 8489 | next C<< <FILE> >> makes Perl try again to read something. We hope. | |
| 14669 | 8490 | |
| 14670 | 8491 | =end original |
| 14671 | 8492 | |
| 14672 | 8493 | これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。 |
| 14673 | 8494 | 一度読み込み時に EOF に到達すると、しばらくスリープし、 |
| 14674 | ||
| 8495 | seek() することでリセットする必要があります。 | |
| 14675 | ||
| 8496 | C<seek> は現在の位置を変更しませんが、ハンドルの EOF 状態を | |
| 14676 | ||
| 8497 | I<クリアします> ので、次の C<< <FILE> >> で Perl は再び何かを | |
| 14677 | ||
| 8498 | 読み込もうとします。 | |
| 14678 | ||
| 8499 | そのはずです。 | |
| 14679 | 8500 | |
| 14680 | 8501 | =begin original |
| 14681 | 8502 | |
| 14682 | If that doesn't work (some | |
| 8503 | If that doesn't work (some stdios are particularly cantankerous), then | |
| 14683 | ||
| 8504 | you may need something more like this: | |
| 14684 | 8505 | |
| 14685 | 8506 | =end original |
| 14686 | 8507 | |
| 14687 | これが動かない場合(特に意地の悪い | |
| 8508 | これが動かない場合(特に意地の悪い stdio もあります)、 | |
| 14688 | 8509 | 以下のようなことをする必要があります: |
| 14689 | 8510 | |
| 14690 | 8511 | for (;;) { |
| 14691 | ||
| 8512 | for ($curpos = tell(FILE); $_ = <FILE>; | |
| 14692 | $curpos = tell( | |
| 8513 | $curpos = tell(FILE)) { | |
| 14693 | ||
| 8514 | # search for some stuff and put it into files | |
| 14694 | ||
| 8515 | } | |
| 14695 | ||
| 8516 | sleep($for_a_while); | |
| 14696 | ||
| 8517 | seek(FILE, $curpos, 0); | |
| 14697 | 8518 | } |
| 14698 | 8519 | |
| 14699 | 8520 | =item seekdir DIRHANDLE,POS |
| 14700 | X<seekdir> | |
| 14701 | 8521 | |
| 14702 | =for Pod::Functions reposition directory pointer | |
| 14703 | ||
| 14704 | 8522 | =begin original |
| 14705 | 8523 | |
| 14706 | Sets the current position for the | |
| 8524 | Sets the current position for the C<readdir> routine on DIRHANDLE. POS | |
| 14707 | ||
| 8525 | must be a value returned by C<telldir>. Has the same caveats about | |
| 14708 | ||
| 8526 | possible directory compaction as the corresponding system library | |
| 14709 | ||
| 8527 | routine. | |
| 14710 | corresponding system library routine. | |
| 14711 | 8528 | |
| 14712 | 8529 | =end original |
| 14713 | 8530 | |
| 14714 | DIRHANDLE での | |
| 8531 | DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。 | |
| 14715 | ||
| 8532 | POS は、C<telldir> が返す値でなければなりません。 | |
| 14716 | ||
| 8533 | 同名のシステムライブラリルーチンと同じく、 | |
| 14717 | ||
| 8534 | ディレクトリ縮小時の問題が考えられます。 | |
| 14718 | 同じく、ディレクトリ縮小時の問題が考えられます。 | |
| 14719 | 8535 | |
| 14720 | 8536 | =item select FILEHANDLE |
| 14721 | X<select> X<filehandle, default> | |
| 14722 | 8537 | |
| 14723 | 8538 | =item select |
| 14724 | 8539 | |
| 14725 | =for Pod::Functions reset default output or do I/O multiplexing | |
| 14726 | ||
| 14727 | 8540 | =begin original |
| 14728 | 8541 | |
| 14729 | Returns the currently selected filehandle. | |
| 8542 | Returns the currently selected filehandle. Sets the current default | |
| 14730 | ||
| 8543 | filehandle for output, if FILEHANDLE is supplied. This has two | |
| 14731 | effects: first, a | |
| 8544 | effects: first, a C<write> or a C<print> without a filehandle will | |
| 14732 | FILEHANDLE LIST> without a filehandle | |
| 14733 | 8545 | default to this FILEHANDLE. Second, references to variables related to |
| 14734 | output will refer to this output channel. | |
| 8546 | output will refer to this output channel. For example, if you have to | |
| 8547 | set the top of form format for more than one output channel, you might | |
| 8548 | do the following: | |
| 14735 | 8549 | |
| 14736 | 8550 | =end original |
| 14737 | 8551 | |
| 14738 | 8552 | その時点で、選択されていたファイルハンドルを返します。 |
| 14739 | FILEHANDLE を指定した場合には、その値を出力のデフォルト | |
| 8553 | FILEHANDLE を指定した場合には、その値を出力のデフォルト | |
| 14740 | 設定します。 | |
| 8554 | ファイルハンドルに設定します。 | |
| 14741 | これには、2 つの効果があります | |
| 8555 | これには、2 つの効果があります。 | |
| 14742 | ||
| 8556 | まず、ファイルハンドルを指定しないで | |
| 14743 | 行なった場合のデフォルトが、 | |
| 8557 | C<write> や C<print> を行なった場合のデフォルトが、 | |
| 14744 | ||
| 8558 | この FILEHANDLE になります。 | |
| 14745 | 参照 | |
| 8559 | もう一つは、出力関連の変数への参照は、 | |
| 8560 | この出力チャネルを参照するようになります。 | |
| 8561 | たとえば、複数の出力チャネルに対して、ページ先頭フォーマットを | |
| 8562 | 設定しなければならないのであれば、 | |
| 8563 | 以下のようにしなければならないでしょう。 | |
| 14746 | 8564 | |
| 14747 | =begin original | |
| 14748 | ||
| 14749 | For example, to set the top-of-form format for more than one | |
| 14750 | output channel, you might do the following: | |
| 14751 | ||
| 14752 | =end original | |
| 14753 | ||
| 14754 | 例えば、複数の出力チャネルに対して、ページ先頭フォーマットを | |
| 14755 | 設定するには: | |
| 14756 | ||
| 14757 | 8565 | select(REPORT1); |
| 14758 | 8566 | $^ = 'report1_top'; |
| 14759 | 8567 | select(REPORT2); |
| 14760 | 8568 | $^ = 'report2_top'; |
| 14761 | 8569 | |
| 14762 | 8570 | =begin original |
| 14763 | 8571 | |
| 14764 | 8572 | FILEHANDLE may be an expression whose value gives the name of the |
| 14765 | 8573 | actual filehandle. Thus: |
| 14766 | 8574 | |
| 14767 | 8575 | =end original |
| 14768 | 8576 | |
| 14769 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 | |
| 8577 | FILEHANDLE は、実際のファイルハンドルの名前を示す式でもかまいません。 | |
| 14770 | 8578 | つまり、以下のようなものです: |
| 14771 | 8579 | |
| 14772 | | |
| 8580 | $oldfh = select(STDERR); $| = 1; select($oldfh); | |
| 14773 | 8581 | |
| 14774 | 8582 | =begin original |
| 14775 | 8583 | |
| 14776 | 8584 | Some programmers may prefer to think of filehandles as objects with |
| 14777 | 8585 | methods, preferring to write the last example as: |
| 14778 | 8586 | |
| 14779 | 8587 | =end original |
| 14780 | 8588 | |
| 14781 | ファイルハンドルはメソッドを持ったオブジェクトであると | |
| 8589 | ファイルハンドルはメソッドを持ったオブジェクトであると | |
| 14782 | プログラマもいるかもしれません | |
| 8590 | 考えることを好むプログラマもいるかもしれません。 | |
| 14783 | 以下のようなものです | |
| 8591 | そのような場合のための最後の例は以下のようなものです。 | |
| 14784 | 8592 | |
| 8593 | use IO::Handle; | |
| 14785 | 8594 | STDERR->autoflush(1); |
| 14786 | 8595 | |
| 14787 | =begin original | |
| 14788 | ||
| 14789 | (Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly | |
| 14790 | first.) | |
| 14791 | ||
| 14792 | =end original | |
| 14793 | ||
| 14794 | (Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする | |
| 14795 | 必要があります。) | |
| 14796 | ||
| 14797 | =begin original | |
| 14798 | ||
| 14799 | Portability issues: L<perlport/select>. | |
| 14800 | ||
| 14801 | =end original | |
| 14802 | ||
| 14803 | 移植性の問題: L<perlport/select>。 | |
| 14804 | ||
| 14805 | 8596 | =item select RBITS,WBITS,EBITS,TIMEOUT |
| 14806 | X<select> | |
| 14807 | 8597 | |
| 14808 | 8598 | =begin original |
| 14809 | 8599 | |
| 14810 | This calls the | |
| 8600 | This calls the select(2) system call with the bit masks specified, which | |
| 14811 | can be constructed using | |
| 8601 | can be constructed using C<fileno> and C<vec>, along these lines: | |
| 14812 | L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines: | |
| 14813 | 8602 | |
| 14814 | 8603 | =end original |
| 14815 | 8604 | |
| 14816 | これは、 | |
| 8605 | これは、select(2) システムコールを、指定したビットマスクで呼び出します。 | |
| 14817 | ビットマスクは、 | |
| 8606 | ビットマスクは、C<fileno> と | |
| 14818 | ||
| 8607 | C<vec> を使って、以下のようにして作成できます。 | |
| 14819 | 8608 | |
| 14820 | | |
| 8609 | $rin = $win = $ein = ''; | |
| 14821 | vec($rin, | |
| 8610 | vec($rin,fileno(STDIN),1) = 1; | |
| 14822 | vec($win, | |
| 8611 | vec($win,fileno(STDOUT),1) = 1; | |
| 14823 | 8612 | $ein = $rin | $win; |
| 14824 | 8613 | |
| 14825 | 8614 | =begin original |
| 14826 | 8615 | |
| 14827 | If you want to select on many filehandles | |
| 8616 | If you want to select on many filehandles you might wish to write a | |
| 14828 | subroutine | |
| 8617 | subroutine: | |
| 14829 | 8618 | |
| 14830 | 8619 | =end original |
| 14831 | 8620 | |
| 14832 | 8621 | 複数のファイルハンドルに select を行ないたいのであれば、 |
| 14833 | 以下のようにします | |
| 8622 | 以下のようにします。 | |
| 14834 | 8623 | |
| 14835 | 8624 | sub fhbits { |
| 14836 | ||
| 8625 | my(@fhlist) = split(' ',$_[0]); | |
| 14837 | ||
| 8626 | my($bits); | |
| 14838 | ||
| 8627 | for (@fhlist) { | |
| 14839 | | |
| 8628 | vec($bits,fileno($_),1) = 1; | |
| 14840 | ||
| 8629 | } | |
| 14841 | ||
| 8630 | $bits; | |
| 14842 | 8631 | } |
| 14843 | | |
| 8632 | $rin = fhbits('STDIN TTY SOCK'); | |
| 14844 | 8633 | |
| 14845 | 8634 | =begin original |
| 14846 | 8635 | |
| 14847 | 8636 | The usual idiom is: |
| 14848 | 8637 | |
| 14849 | 8638 | =end original |
| 14850 | 8639 | |
| 14851 | 8640 | 通常は、 |
| 14852 | 8641 | |
| 14853 | | |
| 8642 | ($nfound,$timeleft) = | |
| 14854 | select( | |
| 8643 | select($rout=$rin, $wout=$win, $eout=$ein, $timeout); | |
| 14855 | $timeout); | |
| 14856 | 8644 | |
| 14857 | 8645 | =begin original |
| 14858 | 8646 | |
| 14859 | 8647 | or to block until something becomes ready just do this |
| 14860 | 8648 | |
| 14861 | 8649 | =end original |
| 14862 | 8650 | |
| 14863 | 8651 | のように使い、いずれかの準備が整うまでブロックするには、 |
| 14864 | 8652 | 以下のようにします。 |
| 14865 | 8653 | |
| 14866 | | |
| 8654 | $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef); | |
| 14867 | select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); | |
| 14868 | 8655 | |
| 14869 | 8656 | =begin original |
| 14870 | 8657 | |
| 14871 | Most systems do not bother to return anything useful in | |
| 8658 | Most systems do not bother to return anything useful in $timeleft, so | |
| 14872 | calling | |
| 8659 | calling select() in scalar context just returns $nfound. | |
| 14873 | just returns C<$nfound>. | |
| 14874 | 8660 | |
| 14875 | 8661 | =end original |
| 14876 | 8662 | |
| 14877 | ほとんどのシステムではわざわざ意味のある値を | |
| 8663 | ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、 | |
| 14878 | ||
| 8664 | select() をスカラコンテキストで呼び出すと、単に $nfound を返します。 | |
| 14879 | 呼び出すと、単に C<$nfound> を返します。 | |
| 14880 | 8665 | |
| 14881 | 8666 | =begin original |
| 14882 | 8667 | |
| 14883 | Any of the bit masks can also be | |
| 8668 | Any of the bit masks can also be undef. The timeout, if specified, is | |
| 14884 | if specified, is | |
| 14885 | 8669 | in seconds, which may be fractional. Note: not all implementations are |
| 14886 | capable of returning the | |
| 8670 | capable of returning the$timeleft. If not, they always return | |
| 14887 | ||
| 8671 | $timeleft equal to the supplied $timeout. | |
| 14888 | 8672 | |
| 14889 | 8673 | =end original |
| 14890 | 8674 | |
| 14891 | どのビットマスクにも | |
| 8675 | どのビットマスクにも undef を設定することができます。 | |
| 14892 | 8676 | TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。 |
| 14893 | 注: すべての実装で、 | |
| 8677 | 注: すべての実装で、$timeleft が返せるものではありません。 | |
| 14894 | その場合、 | |
| 8678 | その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。 | |
| 14895 | 8679 | |
| 14896 | 8680 | =begin original |
| 14897 | 8681 | |
| 14898 | 8682 | You can effect a sleep of 250 milliseconds this way: |
| 14899 | 8683 | |
| 14900 | 8684 | =end original |
| 14901 | 8685 | |
| 14902 | 8686 | 250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。 |
| 14903 | 8687 | |
| 14904 | 8688 | select(undef, undef, undef, 0.25); |
| 14905 | 8689 | |
| 14906 | 8690 | =begin original |
| 14907 | 8691 | |
| 14908 | N | |
| 8692 | B<WARNING>: One should not attempt to mix buffered I/O (like C<read> | |
| 14909 | r | |
| 8693 | or <FH>) with C<select>, except as permitted by POSIX, and even | |
| 14910 | ||
| 8694 | then only on POSIX systems. You have to use C<sysread> instead. | |
| 14911 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>. | |
| 14912 | 8695 | |
| 14913 | 8696 | =end original |
| 14914 | 8697 | |
| 14915 | ||
| 8698 | B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select> を | |
| 14916 | 後に再起動するかどうかは実装依存であることに注意してください。 | |
| 14917 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する | |
| 14918 | 注意については L<perlport> も参照してください。 | |
| 14919 | ||
| 14920 | =begin original | |
| 14921 | ||
| 14922 | On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just | |
| 14923 | like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>. | |
| 14924 | ||
| 14925 | =end original | |
| 14926 | ||
| 14927 | エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は | |
| 14928 | L<select(2)> のように振舞います: | |
| 14929 | C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。 | |
| 14930 | ||
| 14931 | =begin original | |
| 14932 | ||
| 14933 | On some Unixes, L<select(2)> may report a socket file descriptor as | |
| 14934 | "ready for reading" even when no data is available, and thus any | |
| 14935 | subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block. | |
| 14936 | This can be avoided if you always use C<O_NONBLOCK> on the socket. See | |
| 14937 | L<select(2)> and L<fcntl(2)> for further details. | |
| 14938 | ||
| 14939 | =end original | |
| 14940 | ||
| 14941 | Unix の中には、実際に利用可能なデータがないために引き続く | |
| 14942 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が | |
| 14943 | ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が | |
| 14944 | 「読み込み準備中」であると報告するものもあります。 | |
| 14945 | これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。 | |
| 14946 | さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。 | |
| 14947 | ||
| 14948 | =begin original | |
| 14949 | ||
| 14950 | The standard L<C<IO::Select>|IO::Select> module provides a | |
| 14951 | user-friendlier interface to | |
| 14952 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does | |
| 14953 | all the bit-mask work for you. | |
| 14954 | ||
| 14955 | =end original | |
| 14956 | ||
| 14957 | 標準の L<C<IO::Select>|IO::Select> モジュールは | |
| 14958 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな | |
| 14959 | インターフェースを提供します; 主な理由はビットマスクの仕事を | |
| 14960 | してくれることです。 | |
| 14961 | ||
| 14962 | =begin original | |
| 14963 | ||
| 14964 | B<WARNING>: One should not attempt to mix buffered I/O (like | |
| 14965 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or | |
| 14966 | L<C<readline>|/readline EXPR>) with | |
| 14967 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by | |
| 14968 | POSIX, and even then only on POSIX systems. You have to use | |
| 14969 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead. | |
| 14970 | ||
| 14971 | =end original | |
| 14972 | ||
| 14973 | B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や | |
| 14974 | L<C<readline>|/readline EXPR>) と | |
| 14975 | L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を | |
| 14976 | 8699 | 混ぜて使ってはいけません(例外: POSIX で認められている形で使い、 |
| 14977 | 8700 | POSIX システムでだけ動かす場合を除きます)。 |
| 14978 | 代わりに | |
| 8701 | 代わりに C<sysread> を使わなければなりません。 | |
| 14979 | 使わなければなりません。 | |
| 14980 | 8702 | |
| 14981 | =begin original | |
| 14982 | ||
| 14983 | Portability issues: L<perlport/select>. | |
| 14984 | ||
| 14985 | =end original | |
| 14986 | ||
| 14987 | 移植性の問題: L<perlport/select>。 | |
| 14988 | ||
| 14989 | 8703 | =item semctl ID,SEMNUM,CMD,ARG |
| 14990 | X<semctl> | |
| 14991 | 8704 | |
| 14992 | =for Pod::Functions SysV semaphore control operations | |
| 14993 | ||
| 14994 | 8705 | =begin original |
| 14995 | 8706 | |
| 14996 | Calls the System V IPC function | |
| 8707 | Calls the System V IPC function C<semctl>. You'll probably have to say | |
| 14997 | 8708 | |
| 14998 | =end original | |
| 14999 | ||
| 15000 | System V IPC 関数 L<semctl(2)> を呼び出します。 | |
| 15001 | 正しい定数定義を得るために、まず | |
| 15002 | ||
| 15003 | 8709 | use IPC::SysV; |
| 15004 | 8710 | |
| 15005 | =begin original | |
| 15006 | ||
| 15007 | 8711 | first to get the correct constant definitions. If CMD is IPC_STAT or |
| 15008 | GETALL, then ARG must be a variable | |
| 8712 | GETALL, then ARG must be a variable which will hold the returned | |
| 15009 | semid_ds structure or semaphore value array. Returns like | |
| 8713 | semid_ds structure or semaphore value array. Returns like C<ioctl>: | |
| 15010 | L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>: | |
| 15011 | 8714 | the undefined value for error, "C<0 but true>" for zero, or the actual |
| 15012 | 8715 | return value otherwise. The ARG must consist of a vector of native |
| 15013 | 8716 | short integers, which may be created with C<pack("s!",(0)x$nsem)>. |
| 15014 | See also L<perlipc/"SysV IPC"> | |
| 8717 | See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> | |
| 15015 | ||
| 8718 | documentation. | |
| 15016 | 8719 | |
| 15017 | 8720 | =end original |
| 15018 | 8721 | |
| 15019 | ||
| 8722 | System V IPC 関数 C<semctl> を呼び出します。正しい定数定義を得るために、まず | |
| 8723 | ||
| 8724 | use IPC::SysV; | |
| 8725 | ||
| 8726 | と宣言する必要があるでしょう。 | |
| 15020 | 8727 | CMD が、IPC_STAT か GETALL のときには、ARG は、返される |
| 15021 | 8728 | semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。 |
| 15022 | ||
| 8729 | C<ioctl> と同じように、エラー時には未定義値、 | |
| 15023 | ||
| 8730 | ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。 | |
| 15024 | ARG はネイティブな short int のベクターから成っていなければなりません | |
| 8731 | ARG はネイティブな short int のベクターから成っていなければなりません。 | |
| 15025 | C<pack("s!",(0)x$nsem)> で作成できます。 | |
| 8732 | これは C<pack("s!",(0)x$nsem)> で作成できます。 | |
| 15026 | L<perlipc/"SysV IPC"> | |
| 8733 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。 | |
| 15027 | L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も | |
| 15028 | 参照してください。 | |
| 15029 | 8734 | |
| 15030 | =begin original | |
| 15031 | ||
| 15032 | Portability issues: L<perlport/semctl>. | |
| 15033 | ||
| 15034 | =end original | |
| 15035 | ||
| 15036 | 移植性の問題: L<perlport/semctl>。 | |
| 15037 | ||
| 15038 | 8735 | =item semget KEY,NSEMS,FLAGS |
| 15039 | X<semget> | |
| 15040 | 8736 | |
| 15041 | =for Pod::Functions get set of SysV semaphores | |
| 15042 | ||
| 15043 | 8737 | =begin original |
| 15044 | 8738 | |
| 15045 | Calls the System V IPC function | |
| 8739 | Calls the System V IPC function semget. Returns the semaphore id, or | |
| 15046 | the undefined value | |
| 8740 | the undefined value if there is an error. See also | |
| 15047 | L<perlipc/"SysV IPC"> | |
| 8741 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> | |
| 15048 | ||
| 8742 | documentation. | |
| 15049 | 8743 | |
| 15050 | 8744 | =end original |
| 15051 | 8745 | |
| 15052 | System V IPC 関数 | |
| 8746 | System V IPC 関数 semget を呼び出します。 | |
| 15053 | 8747 | セマフォ ID か、エラー時には未定義値を返します。 |
| 15054 | L<perlipc/"SysV IPC"> | |
| 8748 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も | |
| 15055 | ||
| 8749 | 参照してください。 | |
| 15056 | 8750 | |
| 15057 | =begin original | |
| 15058 | ||
| 15059 | Portability issues: L<perlport/semget>. | |
| 15060 | ||
| 15061 | =end original | |
| 15062 | ||
| 15063 | 移植性の問題: L<perlport/semget>。 | |
| 15064 | ||
| 15065 | 8751 | =item semop KEY,OPSTRING |
| 15066 | X<semop> | |
| 15067 | 8752 | |
| 15068 | =for Pod::Functions SysV semaphore operations | |
| 15069 | ||
| 15070 | 8753 | =begin original |
| 15071 | 8754 | |
| 15072 | Calls the System V IPC function | |
| 8755 | Calls the System V IPC function semop to perform semaphore operations | |
| 15073 | such as signal | |
| 8756 | such as signaling and waiting. OPSTRING must be a packed array of | |
| 15074 | 8757 | semop structures. Each semop structure can be generated with |
| 15075 | C<pack("s | |
| 8758 | C<pack("sss", $semnum, $semop, $semflag)>. The number of semaphore | |
| 15076 | implie | |
| 8759 | operations is implied by the length of OPSTRING. Returns true if | |
| 15077 | successful, false | |
| 8760 | successful, or false if there is an error. As an example, the | |
| 15078 | 8761 | following code waits on semaphore $semnum of semaphore id $semid: |
| 15079 | 8762 | |
| 15080 | 8763 | =end original |
| 15081 | 8764 | |
| 15082 | 8765 | シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、 |
| 15083 | System V IPC 関数 | |
| 8766 | System V IPC 関数 semop を呼び出します。 | |
| 15084 | 8767 | OPSTRING は、semop 構造体の pack された配列でなければなりません。 |
| 15085 | semop 構造体は、それぞれ、 | |
| 8768 | semop 構造体は、それぞれ、 | |
| 15086 | 作ることができます。 | |
| 8769 | C<pack("sss", $semnum, $semop, $semflag)> のように作ることができます。 | |
| 15087 | 8770 | セマフォ操作の数は、OPSTRING の長さからわかります。 |
| 15088 | 8771 | 成功時には真を、エラー時には偽を返します。 |
| 15089 | 8772 | 以下の例は、セマフォ ID $semid のセマフォ $semnum で |
| 15090 | 8773 | 待ち合わせを行ないます。 |
| 15091 | 8774 | |
| 15092 | | |
| 8775 | $semop = pack("sss", $semnum, -1, 0); | |
| 15093 | 8776 | die "Semaphore trouble: $!\n" unless semop($semid, $semop); |
| 15094 | 8777 | |
| 15095 | 8778 | =begin original |
| 15096 | 8779 | |
| 15097 | 8780 | To signal the semaphore, replace C<-1> with C<1>. See also |
| 15098 | L<perlipc/"SysV IPC"> and | |
| 8781 | L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore> | |
| 15099 | ||
| 8782 | documentation. | |
| 15100 | 8783 | |
| 15101 | 8784 | =end original |
| 15102 | 8785 | |
| 15103 | 8786 | セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。 |
| 15104 | L<perlipc/"SysV IPC"> | |
| 8787 | L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も | |
| 15105 | ||
| 8788 | 参照してください。 | |
| 15106 | 8789 | |
| 15107 | =begin original | |
| 15108 | ||
| 15109 | Portability issues: L<perlport/semop>. | |
| 15110 | ||
| 15111 | =end original | |
| 15112 | ||
| 15113 | 移植性の問題: L<perlport/semop>。 | |
| 15114 | ||
| 15115 | 8790 | =item send SOCKET,MSG,FLAGS,TO |
| 15116 | X<send> | |
| 15117 | 8791 | |
| 15118 | 8792 | =item send SOCKET,MSG,FLAGS |
| 15119 | 8793 | |
| 15120 | =for Pod::Functions send a message over a socket | |
| 15121 | ||
| 15122 | 8794 | =begin original |
| 15123 | 8795 | |
| 15124 | Sends a message on a socket. | |
| 8796 | Sends a message on a socket. Takes the same flags as the system call | |
| 15125 | f | |
| 8797 | of the same name. On unconnected sockets you must specify a | |
| 15126 | ||
| 8798 | destination to send TO, in which case it does a C C<sendto>. Returns | |
| 15127 | ||
| 8799 | the number of characters sent, or the undefined value if there is an | |
| 15128 | ||
| 8800 | error. The C system call sendmsg(2) is currently unimplemented. | |
| 15129 | ||
| 8801 | See L<perlipc/"UDP: Message Passing"> for examples. | |
| 15130 | 8802 | |
| 15131 | 8803 | =end original |
| 15132 | 8804 | |
| 15133 | ||
| 8805 | SOCKET に MSG を送ります。 | |
| 15134 | ||
| 8806 | FLAGS には、同名のシステムコールと同じフラグを指定します。 | |
| 15135 | ||
| 8807 | 接続していないソケットには、送信先 TO を指定しなければならず、 | |
| 15136 | ||
| 8808 | この場合、C の C<sendto> を実行します。 | |
| 15137 | この場合、L<sendto(2)> を実行します。 | |
| 15138 | 8809 | 送信した文字数か、エラー時には、未定義値を返します。 |
| 15139 | システムコール | |
| 8810 | C の システムコール sendmsg(2) は現在実装されていません。 | |
| 15140 | 8811 | 例については L<perlipc/"UDP: Message Passing"> を参照してください。 |
| 15141 | 8812 | |
| 15142 | =begin original | |
| 15143 | ||
| 15144 | Note that if the socket has been marked as C<:utf8>, C<send> will | |
| 15145 | throw an exception. The C<:encoding(...)> layer implicitly introduces | |
| 15146 | the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>. | |
| 15147 | ||
| 15148 | =end original | |
| 15149 | ||
| 15150 | ソケットが C<:utf8> とマークされている場合、 | |
| 15151 | C<send> は例外を投げることに注意してください。 | |
| 15152 | C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。 | |
| 15153 | L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。 | |
| 15154 | ||
| 15155 | 8813 | =item setpgrp PID,PGRP |
| 15156 | X<setpgrp> X<group> | |
| 15157 | 8814 | |
| 15158 | =for Pod::Functions set the process group of a process | |
| 15159 | ||
| 15160 | 8815 | =begin original |
| 15161 | 8816 | |
| 15162 | 8817 | Sets the current process group for the specified PID, C<0> for the current |
| 15163 | process. | |
| 8818 | process. Will produce a fatal error if used on a machine that doesn't | |
| 15164 | implement POSIX | |
| 8819 | implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted, | |
| 15165 | ||
| 8820 | it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not | |
| 15166 | ||
| 8821 | accept any arguments, so only C<setpgrp(0,0)> is portable. See also | |
| 15167 | C<set | |
| 8822 | C<POSIX::setsid()>. | |
| 15168 | L<C<POSIX::setsid()>|POSIX/C<setsid>>. | |
| 15169 | 8823 | |
| 15170 | 8824 | =end original |
| 15171 | 8825 | |
| 15172 | 8826 | 指定した PID (C<0> を指定するとカレントプロセス) に |
| 15173 | 8827 | 対するプロセスグループを設定します。 |
| 15174 | POSIX | |
| 8828 | POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、 | |
| 15175 | ||
| 8829 | 致命的エラーが発生します。 | |
| 15176 | 8830 | 引数が省略された場合は、C<0,0>が使われます。 |
| 15177 | BSD 4.2 版の | |
| 8831 | BSD 4.2 版の C<setpgrp> は引数を取ることができないので、 | |
| 15178 | 8832 | C<setpgrp(0,0)> のみが移植性があることに注意してください。 |
| 15179 | ||
| 8833 | C<POSIX::setsid()> も参照してください。 | |
| 15180 | 8834 | |
| 15181 | =begin original | |
| 15182 | ||
| 15183 | Portability issues: L<perlport/setpgrp>. | |
| 15184 | ||
| 15185 | =end original | |
| 15186 | ||
| 15187 | 移植性の問題: L<perlport/setpgrp>。 | |
| 15188 | ||
| 15189 | 8835 | =item setpriority WHICH,WHO,PRIORITY |
| 15190 | X<setpriority> X<priority> X<nice> X<renice> | |
| 15191 | 8836 | |
| 15192 | =for Pod::Functions set a process's nice value | |
| 15193 | ||
| 15194 | 8837 | =begin original |
| 15195 | 8838 | |
| 15196 | 8839 | Sets the current priority for a process, a process group, or a user. |
| 15197 | (See | |
| 8840 | (See setpriority(2).) Will produce a fatal error if used on a machine | |
| 15198 | that doesn't implement | |
| 8841 | that doesn't implement setpriority(2). | |
| 15199 | 8842 | |
| 15200 | 8843 | =end original |
| 15201 | 8844 | |
| 15202 | 8845 | プロセス、プロセスグループ、ユーザに対する優先順位を設定します。 |
| 15203 | ( | |
| 8846 | (setpriority(2) を参照してください。) | |
| 15204 | ||
| 8847 | setpriority(2) が実装されていないマシンでは、 | |
| 8848 | 致命的エラーが発生します。 | |
| 15205 | 8849 | |
| 15206 | =begin original | |
| 15207 | ||
| 15208 | C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER> | |
| 15209 | imported from L<POSIX/RESOURCE CONSTANTS>. | |
| 15210 | ||
| 15211 | =end original | |
| 15212 | ||
| 15213 | C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた | |
| 15214 | C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。 | |
| 15215 | ||
| 15216 | =begin original | |
| 15217 | ||
| 15218 | Portability issues: L<perlport/setpriority>. | |
| 15219 | ||
| 15220 | =end original | |
| 15221 | ||
| 15222 | 移植性の問題: L<perlport/setpriority>。 | |
| 15223 | ||
| 15224 | 8850 | =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL |
| 15225 | X<setsockopt> | |
| 15226 | 8851 | |
| 15227 | =for Pod::Functions set some socket options | |
| 15228 | ||
| 15229 | 8852 | =begin original |
| 15230 | 8853 | |
| 15231 | Sets the socket option requested. Returns | |
| 8854 | Sets the socket option requested. Returns undefined if there is an | |
| 15232 | error. | |
| 8855 | error. OPTVAL may be specified as C<undef> if you don't want to pass an | |
| 15233 | ||
| 8856 | argument. | |
| 15234 | LEVEL and OPNAME. Values for LEVEL can also be obtained from | |
| 15235 | getprotobyname. OPTVAL might either be a packed string or an integer. | |
| 15236 | An integer OPTVAL is shorthand for pack("i", OPTVAL). | |
| 15237 | 8857 | |
| 15238 | 8858 | =end original |
| 15239 | 8859 | |
| 15240 | 8860 | 要求したソケットオプションを設定します。 |
| 15241 | エラー時には、 | |
| 8861 | エラー時には、未定義値が返されます。 | |
| 15242 | ||
| 8862 | 引数を渡したくない場合には、OPTVAL に C<undef> を指定します。 | |
| 15243 | 整数定数を使います。 | |
| 15244 | LEVEL の値は getprotobyname から得ることもできます。 | |
| 15245 | OPTVAL は pack された文字列か整数です。 | |
| 15246 | 整数の OPTVAL は pack("i", OPTVAL) の省略表現です。 | |
| 15247 | 8863 | |
| 15248 | =begin original | |
| 15249 | ||
| 15250 | An example disabling Nagle's algorithm on a socket: | |
| 15251 | ||
| 15252 | =end original | |
| 15253 | ||
| 15254 | ソケットに対する Nagle のアルゴリズムを無効にする例です: | |
| 15255 | ||
| 15256 | use Socket qw(IPPROTO_TCP TCP_NODELAY); | |
| 15257 | setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1); | |
| 15258 | ||
| 15259 | =begin original | |
| 15260 | ||
| 15261 | Portability issues: L<perlport/setsockopt>. | |
| 15262 | ||
| 15263 | =end original | |
| 15264 | ||
| 15265 | 移植性の問題: L<perlport/setsockopt>。 | |
| 15266 | ||
| 15267 | 8864 | =item shift ARRAY |
| 15268 | X<shift> | |
| 15269 | 8865 | |
| 15270 | 8866 | =item shift |
| 15271 | 8867 | |
| 15272 | =for Pod::Functions remove the first element of an array, and return it | |
| 15273 | ||
| 15274 | 8868 | =begin original |
| 15275 | 8869 | |
| 15276 | 8870 | Shifts the first value of the array off and returns it, shortening the |
| 15277 | 8871 | array by 1 and moving everything down. If there are no elements in the |
| 15278 | 8872 | array, returns the undefined value. If ARRAY is omitted, shifts the |
| 15279 | ||
| 8873 | C<@_> array within the lexical scope of subroutines and formats, and the | |
| 15280 | ||
| 8874 | C<@ARGV> array at file scopes or within the lexical scopes established by | |
| 15281 | ||
| 8875 | the C<eval ''>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, and C<END {}> | |
| 15282 | ||
| 8876 | constructs. | |
| 15283 | C<UNITCHECK {}>, and C<END {}> constructs. | |
| 15284 | 8877 | |
| 15285 | 8878 | =end original |
| 15286 | 8879 | |
| 15287 | 配列の最初の値を取り出して、その値を返し、配列を一つ | |
| 8880 | 配列の最初の値を取り出して、その値を返し、配列を一つ | |
| 15288 | 前へずらします。 | |
| 8881 | 短くして、すべての要素を前へずらします。 | |
| 15289 | 8882 | 配列に要素がなければ、未定義値を返します。 |
| 15290 | ARRAY を省略すると、 | |
| 8883 | ARRAY を省略すると、 | |
| 15291 | ||
| 8884 | サブルーチンやフォーマットのレキシカルスコープでは C<@_> を、 | |
| 15292 | ||
| 8885 | ファイルスコープまたは | |
| 15293 | ||
| 8886 | C<eval ''>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>, C<END {}> | |
| 8887 | で作成されたレキシカルスコープでは C<@ARGV> が用いられます。 | |
| 15294 | 8888 | |
| 15295 | 8889 | =begin original |
| 15296 | 8890 | |
| 15297 | S | |
| 8891 | See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the | |
| 15298 | ||
| 8892 | same thing to the left end of an array that C<pop> and C<push> do to the | |
| 15299 | ||
| 8893 | right end. | |
| 15300 | removed as of Perl 5.24. | |
| 15301 | 8894 | |
| 15302 | 8895 | =end original |
| 15303 | 8896 | |
| 15304 | ||
| 8897 | C<unshift>、C<push>、C<pop> も参照してください。 | |
| 15305 | ||
| 8898 | C<shift> と C<unshift> は、C<pop> と | |
| 15306 | ||
| 8899 | C<push> が配列の右端で行なうことを、左端で行ないます。 | |
| 15307 | 8900 | |
| 15308 | =begin original | |
| 15309 | ||
| 15310 | See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>, | |
| 15311 | and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and | |
| 15312 | L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of | |
| 15313 | an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to | |
| 15314 | the right end. | |
| 15315 | ||
| 15316 | =end original | |
| 15317 | ||
| 15318 | L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、 | |
| 15319 | L<C<pop>|/pop ARRAY> も参照してください。 | |
| 15320 | L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、 | |
| 15321 | L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で | |
| 15322 | 行なうことを、左端で行ないます。 | |
| 15323 | ||
| 15324 | 8901 | =item shmctl ID,CMD,ARG |
| 15325 | X<shmctl> | |
| 15326 | 8902 | |
| 15327 | =for Pod::Functions SysV shared memory operations | |
| 15328 | ||
| 15329 | 8903 | =begin original |
| 15330 | 8904 | |
| 15331 | 8905 | Calls the System V IPC function shmctl. You'll probably have to say |
| 15332 | 8906 | |
| 15333 | =end original | |
| 15334 | ||
| 15335 | System V IPC 関数 shmctl を呼び出します。 | |
| 15336 | 正しい定数定義を得るために、まず | |
| 15337 | ||
| 15338 | 8907 | use IPC::SysV; |
| 15339 | 8908 | |
| 15340 | =begin original | |
| 15341 | ||
| 15342 | 8909 | first to get the correct constant definitions. If CMD is C<IPC_STAT>, |
| 15343 | then ARG must be a variable | |
| 8910 | then ARG must be a variable which will hold the returned C<shmid_ds> | |
| 15344 | structure. Returns like ioctl: | |
| 8911 | structure. Returns like ioctl: the undefined value for error, "C<0> but | |
| 15345 | ||
| 8912 | true" for zero, or the actual return value otherwise. | |
| 15346 | See also L<perlipc/"SysV IPC"> and | |
| 8913 | See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation. | |
| 15347 | L<C<IPC::SysV>|IPC::SysV>. | |
| 15348 | 8914 | |
| 15349 | 8915 | =end original |
| 15350 | 8916 | |
| 15351 | ||
| 8917 | System V IPC 関数 shmctl を呼び出します。正しい定数定義を得るために、まず | |
| 8918 | ||
| 8919 | use IPC::SysV; | |
| 8920 | ||
| 8921 | と宣言する必要があるでしょう。 | |
| 15352 | 8922 | CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を |
| 15353 | 8923 | 納める変数でなければなりません。 |
| 15354 | ioctl と同 | |
| 8924 | ioctl と同じように、エラー時には未定義値、ゼロのときは "C<0> だが真"、 | |
| 15355 | ||
| 8925 | それ以外なら、その値そのものを返します。 | |
| 15356 | L<perlipc/"SysV IPC"> と | |
| 8926 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 | |
| 15357 | 8927 | |
| 15358 | =begin original | |
| 15359 | ||
| 15360 | Portability issues: L<perlport/shmctl>. | |
| 15361 | ||
| 15362 | =end original | |
| 15363 | ||
| 15364 | 移植性の問題: L<perlport/shmctl>。 | |
| 15365 | ||
| 15366 | 8928 | =item shmget KEY,SIZE,FLAGS |
| 15367 | X<shmget> | |
| 15368 | 8929 | |
| 15369 | =for Pod::Functions get SysV shared memory segment identifier | |
| 15370 | ||
| 15371 | 8930 | =begin original |
| 15372 | 8931 | |
| 15373 | 8932 | Calls the System V IPC function shmget. Returns the shared memory |
| 15374 | segment id, or | |
| 8933 | segment id, or the undefined value if there is an error. | |
| 15375 | See also L<perlipc/"SysV IPC"> and | |
| 8934 | See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation. | |
| 15376 | L<C<IPC::SysV>|IPC::SysV>. | |
| 15377 | 8935 | |
| 15378 | 8936 | =end original |
| 15379 | 8937 | |
| 15380 | 8938 | System V IPC 関数 shmget を呼び出します。 |
| 15381 | 共有メモリのセグメント ID か、エラー時には | |
| 8939 | 共有メモリのセグメント ID か、エラー時には未定義値を返します。 | |
| 15382 | L<perlipc/"SysV IPC"> と | |
| 8940 | L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。 | |
| 15383 | 8941 | |
| 15384 | =begin original | |
| 15385 | ||
| 15386 | Portability issues: L<perlport/shmget>. | |
| 15387 | ||
| 15388 | =end original | |
| 15389 | ||
| 15390 | 移植性の問題: L<perlport/shmget>。 | |
| 15391 | ||
| 15392 | 8942 | =item shmread ID,VAR,POS,SIZE |
| 15393 | X<shmread> | |
| 15394 | X<shmwrite> | |
| 15395 | 8943 | |
| 15396 | =for Pod::Functions read SysV shared memory | |
| 15397 | ||
| 15398 | 8944 | =item shmwrite ID,STRING,POS,SIZE |
| 15399 | 8945 | |
| 15400 | =for Pod::Functions write SysV shared memory | |
| 15401 | ||
| 15402 | 8946 | =begin original |
| 15403 | 8947 | |
| 15404 | 8948 | Reads or writes the System V shared memory segment ID starting at |
| 15405 | 8949 | position POS for size SIZE by attaching to it, copying in/out, and |
| 15406 | 8950 | detaching from it. When reading, VAR must be a variable that will |
| 15407 | 8951 | hold the data read. When writing, if STRING is too long, only SIZE |
| 15408 | 8952 | bytes are used; if STRING is too short, nulls are written to fill out |
| 15409 | SIZE bytes. Return true if successful, false | |
| 8953 | SIZE bytes. Return true if successful, or false if there is an error. | |
| 15410 | ||
| 8954 | shmread() taints the variable. See also L<perlipc/"SysV IPC">, | |
| 15411 | ||
| 8955 | C<IPC::SysV> documentation, and the C<IPC::Shareable> module from CPAN. | |
| 15412 | L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable> | |
| 15413 | module from CPAN. | |
| 15414 | 8956 | |
| 15415 | 8957 | =end original |
| 15416 | 8958 | |
| 15417 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
| 8959 | System V 共有メモリセグメント ID に対し、アタッチして、 | |
| 15418 | デタッチするという形で、位置 POS から、 | |
| 8960 | コピーを行ない、デタッチするという形で、位置 POS から、 | |
| 15419 | 行ないます。 | |
| 8961 | サイズ SIZE だけ、読み込みか書き込みを行ないます。 | |
| 15420 | 読み込み時には、VAR は読み込んだデータを納める | |
| 8962 | 読み込み時には、VAR は読み込んだデータを納める | |
| 15421 | ||
| 8963 | 変数でなければなりません。 | |
| 15422 | ||
| 8964 | 書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます。 | |
| 8965 | STRING が短すぎる場合には、SIZE バイトを埋めるために、 | |
| 8966 | ヌル文字が書き込まれます。 | |
| 15423 | 8967 | 成功時には真を、エラー時には偽を返します。 |
| 15424 | ||
| 8968 | shmread() は変数を汚染します。 | |
| 15425 | L<perlipc/"SysV IPC"> | |
| 8969 | L<perlipc/"SysV IPC"> と C<IPC::SysV> の文章と、 | |
| 15426 | ||
| 8970 | CPAN の C<IPC::Shareable> も参照してください。 | |
| 15427 | 8971 | |
| 15428 | =begin original | |
| 15429 | ||
| 15430 | Portability issues: L<perlport/shmread> and L<perlport/shmwrite>. | |
| 15431 | ||
| 15432 | =end original | |
| 15433 | ||
| 15434 | 移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。 | |
| 15435 | ||
| 15436 | 8972 | =item shutdown SOCKET,HOW |
| 15437 | X<shutdown> | |
| 15438 | 8973 | |
| 15439 | =for Pod::Functions close down just half of a socket connection | |
| 15440 | ||
| 15441 | 8974 | =begin original |
| 15442 | 8975 | |
| 15443 | 8976 | Shuts down a socket connection in the manner indicated by HOW, which |
| 15444 | has the same interpretation as in the syscall of the same name. | |
| 8977 | has the same interpretation as in the system call of the same name. | |
| 15445 | 8978 | |
| 15446 | 8979 | =end original |
| 15447 | 8980 | |
| 15448 | 8981 | 同名のシステムコールと同じように解釈される HOW によって、 |
| 15449 | 8982 | 指定された方法でソケット接続のシャットダウンを行ないます。 |
| 15450 | 8983 | |
| 15451 | shutdown( | |
| 8984 | shutdown(SOCKET, 0); # I/we have stopped reading data | |
| 15452 | shutdown( | |
| 8985 | shutdown(SOCKET, 1); # I/we have stopped writing data | |
| 15453 | shutdown( | |
| 8986 | shutdown(SOCKET, 2); # I/we have stopped using this socket | |
| 15454 | 8987 | |
| 15455 | 8988 | =begin original |
| 15456 | 8989 | |
| 15457 | 8990 | This is useful with sockets when you want to tell the other |
| 15458 | 8991 | side you're done writing but not done reading, or vice versa. |
| 15459 | It's also a more insistent form of close because it also | |
| 8992 | It's also a more insistent form of close because it also | |
| 15460 | 8993 | disables the file descriptor in any forked copies in other |
| 15461 | 8994 | processes. |
| 15462 | 8995 | |
| 15463 | 8996 | =end original |
| 15464 | 8997 | |
| 15465 | 8998 | これは、こちらがソケットを書き終わったが読み終わっていない、 |
| 15466 | 8999 | またはその逆を相手側に伝えたいときに便利です。 |
| 15467 | 9000 | これはその他のプロセスでフォークしたファイル記述子のコピーも |
| 15468 | 9001 | 無効にするので、よりしつこい閉じ方です。 |
| 15469 | 9002 | |
| 15470 | =begin original | |
| 15471 | ||
| 15472 | Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if | |
| 15473 | the first argument is not a valid filehandle, or returns C<0> and sets | |
| 15474 | L<C<$!>|perlvar/$!> for any other failure. | |
| 15475 | ||
| 15476 | =end original | |
| 15477 | ||
| 15478 | 成功時には C<1> を返します; | |
| 15479 | エラーの場合、最初の引数が有効なファイルハンドルでない場合は | |
| 15480 | L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して | |
| 15481 | L<C<$!>|perlvar/$!> をセットします。 | |
| 15482 | ||
| 15483 | 9003 | =item sin EXPR |
| 15484 | X<sin> X<sine> X<asin> X<arcsine> | |
| 15485 | 9004 | |
| 15486 | 9005 | =item sin |
| 15487 | 9006 | |
| 15488 | =for Pod::Functions return the sine of a number | |
| 15489 | ||
| 15490 | 9007 | =begin original |
| 15491 | 9008 | |
| 15492 | 9009 | Returns the sine of EXPR (expressed in radians). If EXPR is omitted, |
| 15493 | returns sine of | |
| 9010 | returns sine of C<$_>. | |
| 15494 | 9011 | |
| 15495 | 9012 | =end original |
| 15496 | 9013 | |
| 15497 | 9014 | (ラジアンで示した) EXPR の正弦を返します。 |
| 15498 | EXPR が省略されたときには、 | |
| 9015 | EXPR が省略されたときには、C<$_> の正弦を返します。 | |
| 15499 | 9016 | |
| 15500 | 9017 | =begin original |
| 15501 | 9018 | |
| 15502 | 9019 | For the inverse sine operation, you may use the C<Math::Trig::asin> |
| 15503 | 9020 | function, or use this relation: |
| 15504 | 9021 | |
| 15505 | 9022 | =end original |
| 15506 | 9023 | |
| 15507 | 9024 | 逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、 |
| 15508 | 9025 | 以下の関係を使ってください: |
| 15509 | 9026 | |
| 15510 | 9027 | sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } |
| 15511 | 9028 | |
| 15512 | 9029 | =item sleep EXPR |
| 15513 | X<sleep> X<pause> | |
| 15514 | 9030 | |
| 15515 | 9031 | =item sleep |
| 15516 | 9032 | |
| 15517 | =for Pod::Functions block for some number of seconds | |
| 15518 | ||
| 15519 | 9033 | =begin original |
| 15520 | 9034 | |
| 15521 | Causes the script to sleep for | |
| 9035 | Causes the script to sleep for EXPR seconds, or forever if no EXPR. | |
| 15522 | a | |
| 9036 | May be interrupted if the process receives a signal such as C<SIGALRM>. | |
| 9037 | Returns the number of seconds actually slept. You probably cannot | |
| 9038 | mix C<alarm> and C<sleep> calls, because C<sleep> is often implemented | |
| 9039 | using C<alarm>. | |
| 15523 | 9040 | |
| 15524 | 9041 | =end original |
| 15525 | 9042 | |
| 15526 | スクリプトを | |
| 9043 | スクリプトを EXPR で指定した秒数 (省略時には、永久に) | |
| 15527 | 9044 | スリープさせます。 |
| 15528 | ||
| 9045 | そのプロセスには、C<SIGALRM>のようなシグナルを | |
| 9046 | 受信すると、割り込みがかかります。 | |
| 9047 | 実際にスリープした秒数を返します。C<sleep> は、C<alarm> を | |
| 9048 | 使って実装されることが多いので、C<alarm> と | |
| 9049 | C<sleep> は、おそらく混ぜて使用することはできません。 | |
| 15529 | 9050 | |
| 15530 | 9051 | =begin original |
| 15531 | 9052 | |
| 15532 | May be interrupted if the process receives a signal such as C<SIGALRM>. | |
| 15533 | ||
| 15534 | =end original | |
| 15535 | ||
| 15536 | そのプロセスが C<SIGALRM>のようなシグナルを受信すると、 | |
| 15537 | 割り込みがかかります。 | |
| 15538 | ||
| 15539 | eval { | |
| 15540 | local $SIG{ALRM} = sub { die "Alarm!\n" }; | |
| 15541 | sleep; | |
| 15542 | }; | |
| 15543 | die $@ unless $@ eq "Alarm!\n"; | |
| 15544 | ||
| 15545 | =begin original | |
| 15546 | ||
| 15547 | You probably cannot mix L<C<alarm>|/alarm SECONDS> and | |
| 15548 | L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often | |
| 15549 | implemented using L<C<alarm>|/alarm SECONDS>. | |
| 15550 | ||
| 15551 | =end original | |
| 15552 | ||
| 15553 | L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って | |
| 15554 | 実装されることが多いので、L<C<alarm>|/alarm SECONDS> と | |
| 15555 | L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。 | |
| 15556 | ||
| 15557 | =begin original | |
| 15558 | ||
| 15559 | 9053 | On some older systems, it may sleep up to a full second less than what |
| 15560 | 9054 | you requested, depending on how it counts seconds. Most modern systems |
| 15561 | 9055 | always sleep the full amount. They may appear to sleep longer than that, |
| 15562 | 9056 | however, because your process might not be scheduled right away in a |
| 15563 | 9057 | busy multitasking system. |
| 15564 | 9058 | |
| 15565 | 9059 | =end original |
| 15566 | 9060 | |
| 15567 | 9061 | 古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に |
| 15568 | 9062 | 満たないうちに、スリープから抜ける場合があります。 |
| 15569 | 9063 | 最近のシステムでは、常に完全にスリープします。 |
| 15570 | 9064 | しかし、負荷の高いマルチタスクシステムでは |
| 15571 | 9065 | 正しくスケジューリングされないがために |
| 15572 | 9066 | より長い時間スリープすることがあります。 |
| 15573 | 9067 | |
| 15574 | 9068 | =begin original |
| 15575 | 9069 | |
| 15576 | For delays of finer granularity than one second, | |
| 9070 | For delays of finer granularity than one second, you may use Perl's | |
| 15577 | ||
| 9071 | C<syscall> interface to access setitimer(2) if your system supports | |
| 15578 | ||
| 9072 | it, or else see L</select> above. The Time::HiRes module from CPAN | |
| 15579 | ||
| 9073 | may also help. | |
| 15580 | version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the | |
| 15581 | first three arguments undefined, or you might be able to use the | |
| 15582 | L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)> | |
| 15583 | if your system supports it. See L<perlfaq8> for details. | |
| 15584 | 9074 | |
| 15585 | 9075 | =end original |
| 15586 | 9076 | |
| 15587 | 1 秒より精度の高いスリープを行なうには、 | |
| 9077 | 1 秒より精度の高いスリープを行なうには、 | |
| 15588 | ||
| 9078 | setitimer(2) をサポートしているシステムでは、Perl の | |
| 15589 | ||
| 9079 | C<syscall> インタフェースを使ってアクセスするか、 | |
| 15590 | ||
| 9080 | さもなければ上述の L</select> を参照してください。 | |
| 15591 | ||
| 9081 | CPAN の Time::HiRes モジュールも有用でしょう。 | |
| 15592 | Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って | |
| 15593 | アクセスすることもできます。 | |
| 15594 | 詳しくは L<perlfaq8> を参照してください。 | |
| 15595 | 9082 | |
| 15596 | 9083 | =begin original |
| 15597 | 9084 | |
| 15598 | See also the | |
| 9085 | See also the POSIX module's C<pause> function. | |
| 15599 | 9086 | |
| 15600 | 9087 | =end original |
| 15601 | 9088 | |
| 15602 | ||
| 9089 | POSIX モジュールの C<pause> 関数も参照して下さい。 | |
| 15603 | 9090 | |
| 15604 | 9091 | =item socket SOCKET,DOMAIN,TYPE,PROTOCOL |
| 15605 | X<socket> | |
| 15606 | 9092 | |
| 15607 | =for Pod::Functions create a socket | |
| 15608 | ||
| 15609 | 9093 | =begin original |
| 15610 | 9094 | |
| 15611 | 9095 | Opens a socket of the specified kind and attaches it to filehandle |
| 15612 | 9096 | SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for |
| 15613 | the syscall of the same name. You should C<use Socket> first | |
| 9097 | the system call of the same name. You should C<use Socket> first | |
| 15614 | 9098 | to get the proper definitions imported. See the examples in |
| 15615 | 9099 | L<perlipc/"Sockets: Client/Server Communication">. |
| 15616 | 9100 | |
| 15617 | 9101 | =end original |
| 15618 | 9102 | |
| 15619 | 指定した種類のソケットをオープンし、ファイルハンドル | |
| 9103 | 指定した種類のソケットをオープンし、ファイルハンドル | |
| 15620 | ||
| 9104 | SOCKET にアタッチします。 | |
| 15621 | ||
| 9105 | DOMAIN、TYPE、PROTOCOL は、 | |
| 15622 | ||
| 9106 | 同名のシステムコールと同じように指定します。 | |
| 9107 | 適切な定義を import するために、まず、C<use Socket> と | |
| 9108 | するとよいでしょう。 | |
| 9109 | 例については L<perlipc/"Sockets: Client/Server Communication"> を | |
| 9110 | 参照してください。 | |
| 15623 | 9111 | |
| 15624 | 9112 | =begin original |
| 15625 | 9113 | |
| 15626 | 9114 | On systems that support a close-on-exec flag on files, the flag will |
| 15627 | 9115 | be set for the newly opened file descriptor, as determined by the |
| 15628 | value of | |
| 9116 | value of $^F. See L<perlvar/$^F>. | |
| 15629 | 9117 | |
| 15630 | 9118 | =end original |
| 15631 | 9119 | |
| 15632 | 9120 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 15633 | フラグは | |
| 9121 | フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して | |
| 15634 | ||
| 9122 | セットされます。 | |
| 15635 | L<perlvar/$^F> | |
| 9123 | L<perlvar/$^F>を参照してください。 | |
| 15636 | 9124 | |
| 15637 | 9125 | =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL |
| 15638 | X<socketpair> | |
| 15639 | 9126 | |
| 15640 | =for Pod::Functions create a pair of sockets | |
| 15641 | ||
| 15642 | 9127 | =begin original |
| 15643 | 9128 | |
| 15644 | 9129 | Creates an unnamed pair of sockets in the specified domain, of the |
| 15645 | 9130 | specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as |
| 15646 | for the syscall of the same name. If unimplemented, | |
| 9131 | for the system call of the same name. If unimplemented, yields a fatal | |
| 15647 | Returns true if successful. | |
| 9132 | error. Returns true if successful. | |
| 15648 | 9133 | |
| 15649 | 9134 | =end original |
| 15650 | 9135 | |
| 15651 | 9136 | 指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。 |
| 15652 | DOMAIN | |
| 9137 | DOMAIN、TYPE、PROTOCOL は、同名のシステムコールと同じように指定します。 | |
| 15653 | 実装されていない場合には、 | |
| 9138 | 実装されていない場合には、致命的エラーとなります。 | |
| 15654 | 9139 | 成功時には真を返します。 |
| 15655 | 9140 | |
| 15656 | 9141 | =begin original |
| 15657 | 9142 | |
| 15658 | 9143 | On systems that support a close-on-exec flag on files, the flag will |
| 15659 | 9144 | be set for the newly opened file descriptors, as determined by the value |
| 15660 | of | |
| 9145 | of $^F. See L<perlvar/$^F>. | |
| 15661 | 9146 | |
| 15662 | 9147 | =end original |
| 15663 | 9148 | |
| 15664 | 9149 | ファイルに対する close-on-exec フラグをサポートしているシステムでは、 |
| 15665 | フラグは | |
| 9150 | フラグは$^F の値で決定される、新しくオープンされたファイル記述子に対して | |
| 15666 | ||
| 9151 | セットされます。 | |
| 15667 | 9152 | L<perlvar/$^F> を参照してください。 |
| 15668 | 9153 | |
| 15669 | 9154 | =begin original |
| 15670 | 9155 | |
| 15671 | Some systems define | |
| 9156 | Some systems defined C<pipe> in terms of C<socketpair>, in which a call | |
| 15672 | ||
| 9157 | to C<pipe(Rdr, Wtr)> is essentially: | |
| 15673 | which a call to C<pipe($rdr, $wtr)> is essentially: | |
| 15674 | 9158 | |
| 15675 | 9159 | =end original |
| 15676 | 9160 | |
| 15677 | ||
| 9161 | C<pipe> を C<socketpair> を使って定義しているシステムもあります; | |
| 15678 | ||
| 9162 | C<pipe(Rdr, Wtr)> は本質的には以下のようになります: | |
| 15679 | 定義しているシステムもあります; | |
| 15680 | C<pipe($rdr, $wtr)> は本質的には以下のようになります: | |
| 15681 | 9163 | |
| 15682 | 9164 | use Socket; |
| 15683 | socketpair( | |
| 9165 | socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); | |
| 15684 | shutdown( | |
| 9166 | shutdown(Rdr, 1); # no more writing for reader | |
| 15685 | shutdown( | |
| 9167 | shutdown(Wtr, 0); # no more reading for writer | |
| 15686 | 9168 | |
| 15687 | 9169 | =begin original |
| 15688 | 9170 | |
| 15689 | See L<perlipc> for an example of socketpair use. | |
| 9171 | See L<perlipc> for an example of socketpair use. | |
| 15690 | emulate socketpair using IP sockets to localhost if your system implements | |
| 15691 | sockets but not socketpair. | |
| 15692 | 9172 | |
| 15693 | 9173 | =end original |
| 15694 | 9174 | |
| 15695 | 9175 | socketpair の使用例については L<perlipc> を参照してください。 |
| 15696 | Perl 5.8 以降では、システムがソケットを実装しているが socketpair を | |
| 15697 | 実装していない場合、localhost に対して IP ソケットを使うことで | |
| 15698 | socketpair をエミュレートします。 | |
| 15699 | 9176 | |
| 15700 | =begin original | |
| 15701 | ||
| 15702 | Portability issues: L<perlport/socketpair>. | |
| 15703 | ||
| 15704 | =end original | |
| 15705 | ||
| 15706 | 移植性の問題: L<perlport/socketpair>。 | |
| 15707 | ||
| 15708 | 9177 | =item sort SUBNAME LIST |
| 15709 | X<sort> | |
| 15710 | 9178 | |
| 15711 | 9179 | =item sort BLOCK LIST |
| 15712 | 9180 | |
| 15713 | 9181 | =item sort LIST |
| 15714 | 9182 | |
| 15715 | =for Pod::Functions sort a list of values | |
| 15716 | ||
| 15717 | 9183 | =begin original |
| 15718 | 9184 | |
| 15719 | ||
| 9185 | Sorts the LIST and returns the sorted list value. If SUBNAME or BLOCK | |
| 15720 | ||
| 9186 | is omitted, C<sort>s in standard string comparison order. If SUBNAME is | |
| 15721 | ||
| 9187 | specified, it gives the name of a subroutine that returns an integer | |
| 9188 | less than, equal to, or greater than C<0>, depending on how the elements | |
| 9189 | of the list are to be ordered. (The C<< <=> >> and C<cmp> | |
| 9190 | operators are extremely useful in such routines.) SUBNAME may be a | |
| 9191 | scalar variable name (unsubscripted), in which case the value provides | |
| 9192 | the name of (or a reference to) the actual subroutine to use. In place | |
| 9193 | of a SUBNAME, you can provide a BLOCK as an anonymous, in-line sort | |
| 9194 | subroutine. | |
| 15722 | 9195 | |
| 15723 | 9196 | =end original |
| 15724 | 9197 | |
| 15725 | ||
| 9198 | LIST をソートし、ソートされたリスト値を返します。 | |
| 15726 | ||
| 9199 | SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが | |
| 9200 | 行なわれます。 | |
| 15728 | ||
| 9201 | SUBNAME を指定すると、それは、リストの | |
| 9202 | 要素をどのような順番に並べるかに応じて、負、ゼロ、正の整数を返す | |
| 15730 | ||
| 9203 | サブルーチンの名前であると解釈されます。 | |
| 15731 | ||
| 9204 | (このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、 | |
| 15732 | order. If SUBNAME is specified, it gives the name of a subroutine | |
| 15733 | that returns an integer less than, equal to, or greater than C<0>, | |
| 15734 | depending on how the elements of the list are to be ordered. (The | |
| 15735 | C<< <=> >> and C<cmp> operators are extremely useful in such routines.) | |
| 15736 | SUBNAME may be a scalar variable name (unsubscripted), in which case | |
| 15737 | the value provides the name of (or a reference to) the actual | |
| 15738 | subroutine to use. In place of a SUBNAME, you can provide a BLOCK as | |
| 15739 | an anonymous, in-line sort subroutine. | |
| 15740 | ||
| 15741 | =end original | |
| 15742 | ||
| 15743 | SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の | |
| 15744 | 文字列比較の順番で行なわれます。 | |
| 15745 | SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに | |
| 15746 | 応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。 | |
| 15747 | (このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、 | |
| 15748 | 9205 | たいへん便利です。) |
| 15749 | SUBNAME は、スカラ変数名(添字なし)でもよく、 | |
| 9206 | SUBNAME は、スカラ変数名(添え字なし)でもよく、 | |
| 15750 | 実際のサブルーチンの | |
| 9207 | その場合には、その値が使用する実際のサブルーチンの | |
| 15751 | ||
| 9208 | 名前(またはそのリファレンス)と解釈されます。 | |
| 15752 | ||
| 9209 | SUBNAME の代わりに、無名のインライン | |
| 9210 | ソートルーチンとして、BLOCK を書くことができます。 | |
| 15753 | 9211 | |
| 15754 | 9212 | =begin original |
| 15755 | 9213 | |
| 15756 | If the subroutine's prototype is C<($$)>, the elements to be compared | |
| 9214 | If the subroutine's prototype is C<($$)>, the elements to be compared | |
| 15757 | passed by reference in | |
| 9215 | are passed by reference in C<@_>, as for a normal subroutine. This is | |
| 15758 | ||
| 9216 | slower than unprototyped subroutines, where the elements to be | |
| 15759 | compared are passed into the subroutine | |
| 9217 | compared are passed into the subroutine | |
| 15760 | ||
| 9218 | as the package global variables $a and $b (see example below). Note that | |
| 9219 | in the latter case, it is usually counter-productive to declare $a and | |
| 9220 | $b as lexicals. | |
| 15761 | 9221 | |
| 15762 | 9222 | =end original |
| 15763 | 9223 | |
| 15764 | サブルーチンのプロトタイプが C<($$)>の場合、 | |
| 9224 | サブルーチンのプロトタイプが C<($$)>の場合、 | |
| 15765 | 同じように | |
| 9225 | 比較する要素は通常のサブルーチンと同じように C<@_> の中に | |
| 15766 | ||
| 9226 | リファレンスとして渡されます。 | |
| 15767 | サブルーチン | |
| 9227 | これはプロトタイプなしのサブルーチンより遅いです。 | |
| 15768 | ||
| 9228 | この場合は比較のためサブルーチンに渡される 2 つの | |
| 9229 | 要素は、パッケージのグローバル変数 $a と $b で渡されます | |
| 9230 | (次の例を参照してください)。 | |
| 9231 | 後者の場合、レキシカルに $a と $b を宣言するのは普通逆効果になります。 | |
| 15769 | 9232 | |
| 15770 | 9233 | =begin original |
| 15771 | 9234 | |
| 15772 | I | |
| 9235 | In either case, the subroutine may not be recursive. The values to be | |
| 15773 | ||
| 9236 | compared are always passed by reference, so don't modify them. | |
| 15774 | C<$b> are not set. | |
| 15775 | 9237 | |
| 15776 | 9238 | =end original |
| 15777 | 9239 | |
| 15778 | サブルーチン | |
| 9240 | どちらの場合でも、サブルーチンは再帰的であってはなりません。 | |
| 15779 | ス | |
| 9241 | $a や $b はリファレンスによって渡されるので、変更しないでください。 | |
| 15780 | C<$a> と C<$b> は設定されません。 | |
| 15781 | 9242 | |
| 15782 | 9243 | =begin original |
| 15783 | 9244 | |
| 15784 | The values to be compared are always passed by reference and should not | |
| 15785 | be modified. | |
| 15786 | ||
| 15787 | =end original | |
| 15788 | ||
| 15789 | 比較される値はリファレンスによって渡されるので、変更するべきではありません。 | |
| 15790 | ||
| 15791 | =begin original | |
| 15792 | ||
| 15793 | 9245 | You also cannot exit out of the sort block or subroutine using any of the |
| 15794 | loop control operators described in L<perlsyn> or with | |
| 9246 | loop control operators described in L<perlsyn> or with C<goto>. | |
| 15795 | L<C<goto>|/goto LABEL>. | |
| 15796 | 9247 | |
| 15797 | 9248 | =end original |
| 15798 | 9249 | |
| 15799 | 9250 | また、ソートブロックやサブルーチンから L<perlsyn> で説明されている |
| 15800 | ループ制御子や | |
| 9251 | ループ制御子や C<goto> を使って抜けてはいけません。 | |
| 15801 | 9252 | |
| 15802 | 9253 | =begin original |
| 15803 | 9254 | |
| 15804 | When | |
| 9255 | When C<use locale> is in effect, C<sort LIST> sorts LIST according to the | |
| 15805 | is in effect, C<sort LIST> sorts LIST according to the | |
| 15806 | 9256 | current collation locale. See L<perllocale>. |
| 15807 | 9257 | |
| 15808 | 9258 | =end original |
| 15809 | 9259 | |
| 15810 | ||
| 9260 | C<use locale> が有効の場合、C<sort LIST> は LIST を現在の比較ロケールに | |
| 15811 | ||
| 9261 | 従ってソートします。L<perllocale> を参照して下さい。 | |
| 15812 | ソートします。 | |
| 15813 | L<perllocale> を参照してください。 | |
| 15814 | 9262 | |
| 15815 | 9263 | =begin original |
| 15816 | 9264 | |
| 15817 | L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list, | |
| 15818 | much as a for loop's index variable aliases the list elements. That is, | |
| 15819 | modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST> | |
| 15820 | (for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or | |
| 15821 | L<C<grep>|/grep BLOCK LIST>) | |
| 15822 | actually modifies the element in the original list. This is usually | |
| 15823 | something to be avoided when writing clear code. | |
| 15824 | ||
| 15825 | =end original | |
| 15826 | ||
| 15827 | L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します; | |
| 15828 | for ループのインデックス変数がリスト要素へのエイリアスと同様です。 | |
| 15829 | つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、 | |
| 15830 | C<foreach> や L<C<map>|/map BLOCK LIST> や | |
| 15831 | L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が | |
| 15832 | 変更されます。 | |
| 15833 | これはきれいなコードを書くときには普通は回避されます。 | |
| 15834 | ||
| 15835 | =begin original | |
| 15836 | ||
| 15837 | Historically Perl has varied in whether sorting is stable by default. | |
| 15838 | If stability matters, it can be controlled explicitly by using the | |
| 15839 | L<sort> pragma. | |
| 15840 | ||
| 15841 | =end original | |
| 15842 | ||
| 15843 | 歴史的には、ソートがデフォルトで安定かどうかは様々です。 | |
| 15844 | 安定性が問題になる場合は、L<sort> プラグマを使うことで明示的に制御できます。 | |
| 15845 | ||
| 15846 | =begin original | |
| 15847 | ||
| 15848 | 9265 | Examples: |
| 15849 | 9266 | |
| 15850 | 9267 | =end original |
| 15851 | 9268 | |
| 15852 | 9269 | 例: |
| 15853 | 9270 | |
| 15854 | 9271 | # sort lexically |
| 15855 | | |
| 9272 | @articles = sort @files; | |
| 15856 | 9273 | |
| 15857 | 9274 | # same thing, but with explicit sort routine |
| 15858 | | |
| 9275 | @articles = sort {$a cmp $b} @files; | |
| 15859 | 9276 | |
| 15860 | 9277 | # now case-insensitively |
| 15861 | | |
| 9278 | @articles = sort {uc($a) cmp uc($b)} @files; | |
| 15862 | 9279 | |
| 15863 | 9280 | # same thing in reversed order |
| 15864 | | |
| 9281 | @articles = sort {$b cmp $a} @files; | |
| 15865 | 9282 | |
| 15866 | 9283 | # sort numerically ascending |
| 15867 | | |
| 9284 | @articles = sort {$a <=> $b} @files; | |
| 15868 | 9285 | |
| 15869 | 9286 | # sort numerically descending |
| 15870 | | |
| 9287 | @articles = sort {$b <=> $a} @files; | |
| 15871 | 9288 | |
| 15872 | 9289 | # this sorts the %age hash by value instead of key |
| 15873 | 9290 | # using an in-line function |
| 15874 | | |
| 9291 | @eldest = sort { $age{$b} <=> $age{$a} } keys %age; | |
| 15875 | 9292 | |
| 15876 | 9293 | # sort using explicit subroutine name |
| 15877 | 9294 | sub byage { |
| 15878 | ||
| 9295 | $age{$a} <=> $age{$b}; # presuming numeric | |
| 15879 | 9296 | } |
| 15880 | | |
| 9297 | @sortedclass = sort byage @class; | |
| 15881 | 9298 | |
| 15882 | 9299 | sub backwards { $b cmp $a } |
| 15883 | | |
| 9300 | @harry = qw(dog cat x Cain Abel); | |
| 15884 | | |
| 9301 | @george = qw(gone chased yz Punished Axed); | |
| 15885 | 9302 | print sort @harry; |
| 15886 | ||
| 9303 | # prints AbelCaincatdogx | |
| 15887 | 9304 | print sort backwards @harry; |
| 15888 | ||
| 9305 | # prints xdogcatCainAbel | |
| 15889 | 9306 | print sort @george, 'to', @harry; |
| 15890 | ||
| 9307 | # prints AbelAxedCainPunishedcatchaseddoggonetoxyz | |
| 15891 | 9308 | |
| 15892 | 9309 | # inefficiently sort by descending numeric compare using |
| 15893 | 9310 | # the first integer after the first = sign, or the |
| 15894 | 9311 | # whole record case-insensitively otherwise |
| 15895 | 9312 | |
| 15896 | | |
| 9313 | @new = sort { | |
| 15897 | ||
| 9314 | ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] | |
| 15898 | ||
| 9315 | || | |
| 15899 | | |
| 9316 | uc($a) cmp uc($b) | |
| 15900 | 9317 | } @old; |
| 15901 | 9318 | |
| 15902 | 9319 | # same thing, but much more efficiently; |
| 15903 | 9320 | # we'll build auxiliary indices instead |
| 15904 | 9321 | # for speed |
| 15905 | | |
| 9322 | @nums = @caps = (); | |
| 15906 | 9323 | for (@old) { |
| 15907 | ||
| 9324 | push @nums, /=(\d+)/; | |
| 15908 | ||
| 9325 | push @caps, uc($_); | |
| 15909 | 9326 | } |
| 15910 | 9327 | |
| 15911 | | |
| 9328 | @new = @old[ sort { | |
| 15912 | ||
| 9329 | $nums[$b] <=> $nums[$a] | |
| 15913 | ||
| 9330 | || | |
| 15914 | ||
| 9331 | $caps[$a] cmp $caps[$b] | |
| 15915 | ||
| 9332 | } 0..$#old | |
| 15916 | ||
| 9333 | ]; | |
| 15917 | 9334 | |
| 15918 | 9335 | # same thing, but without any temps |
| 15919 | | |
| 9336 | @new = map { $_->[0] } | |
| 15920 | 9337 | sort { $b->[1] <=> $a->[1] |
| 15921 | 9338 | || |
| 15922 | 9339 | $a->[2] cmp $b->[2] |
| 15923 | } map { [$_, /=(\d+)/, | |
| 9340 | } map { [$_, /=(\d+)/, uc($_)] } @old; | |
| 15924 | 9341 | |
| 15925 | 9342 | # using a prototype allows you to use any comparison subroutine |
| 15926 | 9343 | # as a sort subroutine (including other package's subroutines) |
| 15927 | package | |
| 9344 | package other; | |
| 15928 | sub backwards ($$) { $_[1] cmp $_[0]; } | |
| 9345 | sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here | |
| 15929 | ||
| 15930 | 9347 | package main; |
| 15931 | | |
| 9348 | @new = sort other::backwards @old; | |
| 15932 | 9349 | |
| 15933 | # guarantee stability | |
| 15934 | use sort 'stable'; | |
| 15935 | my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old; | |
| 15936 | ||
| 15937 | 9350 | =begin original |
| 15938 | 9351 | |
| 15939 | ||
| 9352 | If you're using strict, you I<must not> declare $a | |
| 15940 | a | |
| 9353 | and $b as lexicals. They are package globals. That means | |
| 15941 | ||
| 9354 | if you're in the C<main> package and type | |
| 15942 | 9355 | |
| 15943 | 9356 | =end original |
| 15944 | 9357 | |
| 15945 | ||
| 9358 | use strict している場合、$a と $b をレキシカルとして | |
| 15946 | ||
| 9359 | 宣言しては I<いけません>。 | |
| 15947 | ||
| 9360 | これはパッケージグローバルです。 | |
| 9361 | つまり、C<main> パッケージで以下のように書いた場合: | |
| 15948 | 9362 | |
| 15949 | | |
| 9363 | @articles = sort {$b <=> $a} @files; | |
| 15950 | my @contact = sort +find_records(@key); | |
| 15951 | my @contact = sort &find_records(@key); | |
| 15952 | my @contact = sort(find_records(@key)); | |
| 15953 | 9364 | |
| 15954 | 9365 | =begin original |
| 15955 | 9366 | |
| 15956 | ||
| 9367 | then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>), | |
| 15957 | ||
| 9368 | but if you're in the C<FooPack> package, it's the same as typing | |
| 15958 | 9369 | |
| 15959 | 9370 | =end original |
| 15960 | 9371 | |
| 15961 | ||
| 9372 | C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を | |
| 15962 | 以下 | |
| 9373 | 意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります: | |
| 15963 | 9374 | |
| 15964 | | |
| 9375 | @articles = sort {$FooPack::b <=> $FooPack::a} @files; | |
| 15965 | my @contact = sort find_records(@key); | |
| 15966 | my @contact = sort(find_records @key); | |
| 15967 | my @contact = sort(find_records (@key)); | |
| 15968 | 9376 | |
| 15969 | 9377 | =begin original |
| 15970 | 9378 | |
| 15971 | C<$a> and C<$b> are set as package globals in the package the sort() is | |
| 15972 | called from. That means C<$main::a> and C<$main::b> (or C<$::a> and | |
| 15973 | C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the | |
| 15974 | C<FooPack> package, etc. If the sort block is in scope of a C<my> or | |
| 15975 | C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full | |
| 15976 | name of the variables in the sort block : | |
| 15977 | ||
| 15978 | =end original | |
| 15979 | ||
| 15980 | C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして | |
| 15981 | 設定されます。 | |
| 15982 | つまり、C<main> パッケージの C<$main::a> と C<$main::b> | |
| 15983 | (あるいは C<$::a> と C<$::b>) 、 | |
| 15984 | C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。 | |
| 15985 | ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、 | |
| 15986 | ソートブロックの変数の完全名を I<指定しなければなりません>: | |
| 15987 | ||
| 15988 | package main; | |
| 15989 | my $a = "C"; # DANGER, Will Robinson, DANGER !!! | |
| 15990 | ||
| 15991 | print sort { $a cmp $b } qw(A C E G B D F H); | |
| 15992 | # WRONG | |
| 15993 | sub badlexi { $a cmp $b } | |
| 15994 | print sort badlexi qw(A C E G B D F H); | |
| 15995 | # WRONG | |
| 15996 | # the above prints BACFEDGH or some other incorrect ordering | |
| 15997 | ||
| 15998 | print sort { $::a cmp $::b } qw(A C E G B D F H); | |
| 15999 | # OK | |
| 16000 | print sort { our $a cmp our $b } qw(A C E G B D F H); | |
| 16001 | # also OK | |
| 16002 | print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H); | |
| 16003 | # also OK | |
| 16004 | sub lexi { our $a cmp our $b } | |
| 16005 | print sort lexi qw(A C E G B D F H); | |
| 16006 | # also OK | |
| 16007 | # the above print ABCDEFGH | |
| 16008 | ||
| 16009 | =begin original | |
| 16010 | ||
| 16011 | With proper care you may mix package and my (or state) C<$a> and/or C<$b>: | |
| 16012 | ||
| 16013 | =end original | |
| 16014 | ||
| 16015 | 適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を | |
| 16016 | 混ぜることができます: | |
| 16017 | ||
| 16018 | my $a = { | |
| 16019 | tiny => -2, | |
| 16020 | small => -1, | |
| 16021 | normal => 0, | |
| 16022 | big => 1, | |
| 16023 | huge => 2 | |
| 16024 | }; | |
| 16025 | ||
| 16026 | say sort { $a->{our $a} <=> $a->{our $b} } | |
| 16027 | qw{ huge normal tiny small big}; | |
| 16028 | ||
| 16029 | # prints tinysmallnormalbighuge | |
| 16030 | ||
| 16031 | =begin original | |
| 16032 | ||
| 16033 | C<$a> and C<$b> are implicitly local to the sort() execution and regain their | |
| 16034 | former values upon completing the sort. | |
| 16035 | ||
| 16036 | =end original | |
| 16037 | ||
| 16038 | C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に | |
| 16039 | 元の値に戻ります。 | |
| 16040 | ||
| 16041 | =begin original | |
| 16042 | ||
| 16043 | Sort subroutines written using C<$a> and C<$b> are bound to their calling | |
| 16044 | package. It is possible, but of limited interest, to define them in a | |
| 16045 | different package, since the subroutine must still refer to the calling | |
| 16046 | package's C<$a> and C<$b> : | |
| 16047 | ||
| 16048 | =end original | |
| 16049 | ||
| 16050 | C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに | |
| 16051 | しなければなりません。 | |
| 16052 | 異なるパッケージに定義することは可能ですが、 | |
| 16053 | これは可能ですが、限られた関心しかありません; | |
| 16054 | サブルーチンは呼び出しパッケージの C<$a> と C<$b> を | |
| 16055 | 参照しなければならないからです: | |
| 16056 | ||
| 16057 | package Foo; | |
| 16058 | sub lexi { $Bar::a cmp $Bar::b } | |
| 16059 | package Bar; | |
| 16060 | ... sort Foo::lexi ... | |
| 16061 | ||
| 16062 | =begin original | |
| 16063 | ||
| 16064 | Use the prototyped versions (see above) for a more generic alternative. | |
| 16065 | ||
| 16066 | =end original | |
| 16067 | ||
| 16068 | より一般的な代替案としては(前述の)プロトタイプ版を使ってください。 | |
| 16069 | ||
| 16070 | =begin original | |
| 16071 | ||
| 16072 | 9379 | The comparison function is required to behave. If it returns |
| 16073 | 9380 | inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and |
| 16074 | 9381 | sometimes saying the opposite, for example) the results are not |
| 16075 | 9382 | well-defined. |
| 16076 | 9383 | |
| 16077 | 9384 | =end original |
| 16078 | 9385 | |
| 16079 | 9386 | 比較関数は一貫した振る舞いをすることが求められます。 |
| 16080 | 9387 | 一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より |
| 16081 | 9388 | 小さいと返し、またあるときは逆を返す)場合、結果は未定義です。 |
| 16082 | 9389 | |
| 16083 | =begin original | |
| 16084 | ||
| 16085 | Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand | |
| 16086 | is C<NaN> (not-a-number), be careful when sorting with a | |
| 16087 | comparison function like C<< $a <=> $b >> any lists that might contain a | |
| 16088 | C<NaN>. The following example takes advantage that C<NaN != NaN> to | |
| 16089 | eliminate any C<NaN>s from the input list. | |
| 16090 | ||
| 16091 | =end original | |
| 16092 | ||
| 16093 | C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに | |
| 16094 | L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で | |
| 16095 | ソートする場合はリストに C<NaN> が含まれないように注意してください。 | |
| 16096 | 以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を | |
| 16097 | 利用しています。 | |
| 16098 | ||
| 16099 | my @result = sort { $a <=> $b } grep { $_ == $_ } @input; | |
| 16100 | ||
| 16101 | 9390 | =item splice ARRAY,OFFSET,LENGTH,LIST |
| 16102 | X<splice> | |
| 16103 | 9391 | |
| 16104 | 9392 | =item splice ARRAY,OFFSET,LENGTH |
| 16105 | 9393 | |
| 16106 | 9394 | =item splice ARRAY,OFFSET |
| 16107 | 9395 | |
| 16108 | 9396 | =item splice ARRAY |
| 16109 | 9397 | |
| 16110 | =for Pod::Functions add or remove elements anywhere in an array | |
| 16111 | ||
| 16112 | 9398 | =begin original |
| 16113 | 9399 | |
| 16114 | 9400 | Removes the elements designated by OFFSET and LENGTH from an array, and |
| 16115 | 9401 | replaces them with the elements of LIST, if any. In list context, |
| 16116 | 9402 | returns the elements removed from the array. In scalar context, |
| 16117 | returns the last element removed, or | |
| 9403 | returns the last element removed, or C<undef> if no elements are | |
| 16118 | elements are | |
| 16119 | 9404 | removed. The array grows or shrinks as necessary. |
| 16120 | 9405 | If OFFSET is negative then it starts that far from the end of the array. |
| 16121 | 9406 | If LENGTH is omitted, removes everything from OFFSET onward. |
| 16122 | If LENGTH is negative, | |
| 9407 | If LENGTH is negative, leaves that many elements off the end of the array. | |
| 16123 | ||
| 9408 | If both OFFSET and LENGTH are omitted, removes everything. | |
| 16124 | If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is | |
| 16125 | past the end of the array and a LENGTH was provided, Perl issues a warning, | |
| 16126 | and splices at the end of the array. | |
| 16127 | 9409 | |
| 9410 | The following equivalences hold (assuming C<$[ == 0>): | |
| 9411 | ||
| 16128 | 9412 | =end original |
| 16129 | 9413 | |
| 16130 | 9414 | ARRAY から OFFSET、LENGTH で指定される要素を取り除き、 |
| 16131 | 9415 | LIST があれば、それを代わりに挿入します。 |
| 16132 | 9416 | リストコンテキストでは、配列から取り除かれた要素を返します。 |
| 16133 | スカラコンテキストでは、取り除かれた最後の要素を返します | |
| 9417 | スカラコンテキストでは、取り除かれた最後の要素を返します。 | |
| 16134 | 取り除かれなかった場合は | |
| 9418 | 要素が取り除かれなかった場合は C<undef> を返します。 | |
| 16135 | 9419 | 配列は、必要に応じて、大きくなったり、小さくなったりします。 |
| 16136 | 9420 | OFFSET が負の数の場合は、配列の最後からの距離を示します。 |
| 16137 | 9421 | LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。 |
| 16138 | LENGTH が負の数の場合は、 | |
| 9422 | LENGTH が負の数の場合は、指定された数だけ配列の最後から要素を取り除きます。 | |
| 16139 | 除いて取り除きます。 | |
| 16140 | 9423 | OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。 |
| 16141 | OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、 | |
| 16142 | 配列の最後に対して処理します。 | |
| 16143 | 9424 | |
| 16144 | = | |
| 9425 | 以下は、(C<$[ == 0> と仮定すると) それぞれ、等価です。 | |
| 16145 | 9426 | |
| 16146 | ||
| 9427 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) | |
| 9428 | pop(@a) splice(@a,-1) | |
| 9429 | shift(@a) splice(@a,0,1) | |
| 9430 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) | |
| 9431 | $a[$x] = $y splice(@a,$x,1,$y) | |
| 16147 | 9432 | |
| 16148 | =end original | |
| 16149 | ||
| 16150 | 以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。 | |
| 16151 | ||
| 16152 | push(@a,$x,$y) splice(@a,@a,0,$x,$y) | |
| 16153 | pop(@a) splice(@a,-1) | |
| 16154 | shift(@a) splice(@a,0,1) | |
| 16155 | unshift(@a,$x,$y) splice(@a,0,0,$x,$y) | |
| 16156 | $a[$i] = $y splice(@a,$i,1,$y) | |
| 16157 | ||
| 16158 | 9433 | =begin original |
| 16159 | 9434 | |
| 16160 | ||
| 9435 | Example, assuming array lengths are passed before arrays: | |
| 16161 | to implement n-ary queue processing: | |
| 16162 | 9436 | |
| 16163 | 9437 | =end original |
| 16164 | 9438 | |
| 16165 | ||
| 9439 | 次の例では、配列の前に、それぞれの配列の大きさが渡されるものとしています: | |
| 16166 | 実装に使えます: | |
| 16167 | 9440 | |
| 16168 | sub | |
| 9441 | sub aeq { # compare two list values | |
| 16169 | ||
| 9442 | my(@a) = splice(@_,0,shift); | |
| 16170 | ||
| 9443 | my(@b) = splice(@_,0,shift); | |
| 16171 | | |
| 9444 | return 0 unless @a == @b; # same len? | |
| 16172 | | |
| 9445 | while (@a) { | |
| 9446 | return 0 if pop(@a) ne pop(@b); | |
| 9447 | } | |
| 9448 | return 1; | |
| 16173 | 9449 | } |
| 9450 | if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... } | |
| 16174 | 9451 | |
| 16175 | nary_print(3, qw(a b c d e f g h)); | |
| 16176 | # prints: | |
| 16177 | # a -- b -- c | |
| 16178 | # d -- e -- f | |
| 16179 | # g -- h | |
| 16180 | ||
| 16181 | =begin original | |
| 16182 | ||
| 16183 | Starting with Perl 5.14, an experimental feature allowed | |
| 16184 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a | |
| 16185 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 16186 | removed as of Perl 5.24. | |
| 16187 | ||
| 16188 | =end original | |
| 16189 | ||
| 16190 | Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を | |
| 16191 | 取ることが出来るという実験的機能がありました。 | |
| 16192 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 16193 | ||
| 16194 | 9452 | =item split /PATTERN/,EXPR,LIMIT |
| 16195 | X<split> | |
| 16196 | 9453 | |
| 16197 | 9454 | =item split /PATTERN/,EXPR |
| 16198 | 9455 | |
| 16199 | 9456 | =item split /PATTERN/ |
| 16200 | 9457 | |
| 16201 | 9458 | =item split |
| 16202 | 9459 | |
| 16203 | =for Pod::Functions split up a string using a regexp delimiter | |
| 16204 | ||
| 16205 | 9460 | =begin original |
| 16206 | 9461 | |
| 16207 | Splits | |
| 9462 | Splits a string into a list of strings and returns that list. By default, | |
| 16208 | ||
| 9463 | empty leading fields are preserved, and empty trailing ones are deleted. | |
| 16209 | (Prior to Perl 5.11, it also overwrote C<@_> with the list in | |
| 16210 | void and scalar context. If you target old perls, beware.) | |
| 16211 | 9464 | |
| 16212 | 9465 | =end original |
| 16213 | 9466 | |
| 16214 | 文字列 | |
| 9467 | 文字列を文字列のリストに分割して、リストを返します。 | |
| 16215 | ||
| 9468 | デフォルトでは、行頭の空白は保存され、末尾の空白は削除されます。 | |
| 16216 | (Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は | |
| 16217 | C<@_> をリストで上書きします。 | |
| 16218 | もし古い perl を対象にするなら、注意してください。) | |
| 16219 | 9469 | |
| 16220 | 9470 | =begin original |
| 16221 | 9471 | |
| 16222 | I | |
| 9472 | In scalar context, returns the number of fields found and splits into | |
| 9473 | the C<@_> array. Use of split in scalar context is deprecated, however, | |
| 9474 | because it clobbers your subroutine arguments. | |
| 16223 | 9475 | |
| 16224 | 9476 | =end original |
| 16225 | 9477 | |
| 16226 | ||
| 9478 | スカラコンテキストの場合には、見つかったフィールドの数を返し、 | |
| 9479 | 配列 C<@_> に分割結果を設定します。 | |
| 9480 | しかし、スカラコンテキストでの split の使用は推奨されません。 | |
| 9481 | サブルーチンの引数を上書きしてしまうからです。 | |
| 16227 | 9482 | |
| 16228 | 9483 | =begin original |
| 16229 | 9484 | |
| 16230 | ||
| 9485 | If EXPR is omitted, splits the C<$_> string. If PATTERN is also omitted, | |
| 16231 | th | |
| 9486 | splits on whitespace (after skipping any leading whitespace). Anything | |
| 16232 | ||
| 9487 | matching PATTERN is taken to be a delimiter separating the fields. (Note | |
| 16233 | ||
| 9488 | that the delimiter may be longer than one character.) | |
| 16234 | empty string, which is a zero-width match). | |
| 16235 | 9489 | |
| 16236 | 9490 | =end original |
| 16237 | 9491 | |
| 16238 | EXPR | |
| 9492 | EXPR を省略すると、文字列 C<$_> を split します。 | |
| 16239 | ||
| 9493 | もし、PATTERN も省略すると、 | |
| 16240 | ||
| 9494 | (先頭の空白文字をスキップした後) 空白で split します。 | |
| 16241 | ||
| 9495 | PATTERN にマッチするものは、フィールドを分割するデリミタとして扱われます。 | |
| 16242 | ||
| 9496 | (デリミタは、1 文字とは限りません。) | |
| 16243 | 9497 | |
| 16244 | 9498 | =begin original |
| 16245 | 9499 | |
| 16246 | ||
| 9500 | If LIMIT is specified and positive, splits into no more than that | |
| 16247 | to | |
| 9501 | many fields (though it may split into fewer). If LIMIT is unspecified | |
| 9502 | or zero, trailing null fields are stripped (which potential users | |
| 9503 | of C<pop> would do well to remember). If LIMIT is negative, it is | |
| 9504 | treated as if an arbitrarily large LIMIT had been specified. | |
| 16248 | 9505 | |
| 16249 | 9506 | =end original |
| 16250 | 9507 | |
| 16251 | ||
| 9508 | 正の数の LIMIT を指定した場合には、最大その数までのフィールドに | |
| 16252 | ||
| 9509 | split します (しかし、それより少ないことはあります)。 | |
| 9510 | LIMIT を指定しないかゼロなら、末尾の空フィールドを捨ててしまいます | |
| 9511 | (C<pop> を行なうときには気を付けないといけません)。 | |
| 9512 | LIMIT が負ならば、LIMIT に任意の大きな数を指定したのと同じことになります。 | |
| 16253 | 9513 | |
| 16254 | 9514 | =begin original |
| 16255 | 9515 | |
| 16256 | ||
| 9516 | A pattern matching the null string (not to be confused with | |
| 16257 | ||
| 9517 | a null pattern C<//>, which is just one member of the set of patterns | |
| 9518 | matching a null string) will split the value of EXPR into separate | |
| 9519 | characters at each point it matches that way. For example: | |
| 16258 | 9520 | |
| 16259 | ||
| 9521 | print join(':', split(/ */, 'hi there')); | |
| 16260 | 9522 | |
| 16261 | ||
| 9523 | produces the output 'h:i:t:h:e:r:e'. | |
| 16262 | (文字の間)で分割されます。 | |
| 16263 | 例えば、以下のものは: | |
| 16264 | 9524 | |
| 16265 | print join(':', split(/b/, 'abc')), "\n"; | |
| 16266 | ||
| 16267 | =begin original | |
| 16268 | ||
| 16269 | uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>. | |
| 16270 | However, this: | |
| 16271 | ||
| 16272 | 9525 | =end original |
| 16273 | 9526 | |
| 16274 | ||
| 9527 | 空文字列にマッチするパターン (ヌルパターン C<//> と混同しないでください。 | |
| 16275 | ||
| 9528 | これは、空文字列にマッチするパターンの一つでしかありません) は、 | |
| 9529 | どの場所にもマッチし、EXPR の値を1 文字ずつに分割します。 | |
| 9530 | たとえば、 | |
| 16276 | 9531 | |
| 16277 | print join(':', split(//, ' | |
| 9532 | print join(':', split(/ */, 'hi there')); | |
| 16278 | 9533 | |
| 16279 | ||
| 9534 | は、'h:i:t:h:e:r:e' という出力になります。 | |
| 16280 | 9535 | |
| 16281 | uses empty string matches as separators to produce the output | |
| 16282 | C<a:b:c>; thus, the empty string may be used to split EXPR into a | |
| 16283 | list of its component characters. | |
| 16284 | ||
| 16285 | =end original | |
| 16286 | ||
| 16287 | 空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、 | |
| 16288 | 空文字列は EXPR を構成する文字のリストに分割するために使われます。 | |
| 16289 | ||
| 16290 | 9536 | =begin original |
| 16291 | 9537 | |
| 16292 | ||
| 9538 | Empty leading (or trailing) fields are produced when there are positive width | |
| 16293 | the | |
| 9539 | matches at the beginning (or end) of the string; a zero-width match at the | |
| 16294 | ||
| 9540 | beginning (or end) of the string does not produce an empty field. For | |
| 16295 | ||
| 9541 | example: | |
| 16296 | interpretation as the last successful match. | |
| 16297 | 9542 | |
| 16298 | 9543 | =end original |
| 16299 | 9544 | |
| 16300 | ||
| 9545 | 先頭と末尾の空フィールドは、文字列の先頭または末尾で 0 でない幅で | |
| 16301 | ||
| 9546 | マッチした場合は生成されます。 | |
| 16302 | ||
| 9547 | 幅 0 でマッチした場合は生成されません。 | |
| 16303 | マッチングという普通の解釈と異なります。 | |
| 16304 | ||
| 16305 | =begin original | |
| 16306 | ||
| 16307 | If PATTERN is C</^/>, then it is treated as if it used the | |
| 16308 | L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it | |
| 16309 | isn't much use otherwise. | |
| 16310 | ||
| 16311 | =end original | |
| 16312 | ||
| 16313 | PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS> | |
| 16314 | (C</^/m>) が使われたかのように扱われます; そうでなければほとんど | |
| 16315 | 使えないからです。 | |
| 16316 | ||
| 16317 | =begin original | |
| 16318 | ||
| 16319 | C<E<sol>m> and any of the other pattern modifiers valid for C<qr> | |
| 16320 | (summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be | |
| 16321 | specified explicitly. | |
| 16322 | ||
| 16323 | =end original | |
| 16324 | ||
| 16325 | C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子 | |
| 16326 | (L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は | |
| 16327 | 明示的に定義されます。 | |
| 16328 | ||
| 16329 | =begin original | |
| 16330 | ||
| 16331 | As another special case, | |
| 16332 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default | |
| 16333 | behavior of the | |
| 16334 | command line tool B<awk> when the PATTERN is either omitted or a | |
| 16335 | string composed of a single space character (such as S<C<' '>> or | |
| 16336 | S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading | |
| 16337 | whitespace in EXPR is removed before splitting occurs, and the PATTERN is | |
| 16338 | instead treated as if it were C</\s+/>; in particular, this means that | |
| 16339 | I<any> contiguous whitespace (not just a single space character) is used as | |
| 16340 | a separator. However, this special treatment can be avoided by specifying | |
| 16341 | the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing | |
| 16342 | only a single space character to be a separator. In earlier Perls this | |
| 16343 | special case was restricted to the use of a plain S<C<" ">> as the | |
| 16344 | pattern argument to split; in Perl 5.18.0 and later this special case is | |
| 16345 | triggered by any expression which evaluates to the simple string S<C<" ">>. | |
| 16346 | ||
| 16347 | =end original | |
| 16348 | ||
| 16349 | もう一つの特別な場合として、 | |
| 16350 | L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は | |
| 16351 | PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば | |
| 16352 | S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール | |
| 16353 | B<awk> のデフォルトの振る舞いをエミュレートします。 | |
| 16354 | この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は | |
| 16355 | C</\s+/> であったかのように扱われます; 特に、これは (単に単一の | |
| 16356 | スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして | |
| 16357 | 使われるということです。 | |
| 16358 | しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を | |
| 16359 | 指定することで回避でき、それによってセパレータとして単一の | |
| 16360 | スペース文字のみが使われます。 | |
| 16361 | 以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を | |
| 16362 | 使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は | |
| 16363 | 単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。 | |
| 16364 | ||
| 16365 | =begin original | |
| 16366 | ||
| 16367 | As of Perl 5.28, this special-cased whitespace splitting works as expected in | |
| 16368 | the scope of L<< S<C<"use feature 'unicode_strings">>|feature/The | |
| 16369 | 'unicode_strings' feature >>. In previous versions, and outside the scope of | |
| 16370 | that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are | |
| 16371 | whitespace according to Unicode rules but not according to ASCII rules can be | |
| 16372 | treated as part of fields rather than as field separators, depending on the | |
| 16373 | string's internal encoding. | |
| 16374 | ||
| 16375 | =end original | |
| 16376 | ||
| 16377 | Perl 5.28 から、この特別な場合の空白分割は | |
| 16378 | L<< S<C<"use feature 'unicode_strings">>|feature/The | |
| 16379 | 'unicode_strings' feature >> のスコープの中では想定通りに動作します。 | |
| 16380 | 以前のバージョンでは、そしてこの機能のスコープの外側では、 | |
| 16381 | これは L<perlunicode/The "Unicode Bug"> を引き起こします: | |
| 16382 | Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、 | |
| 16383 | 文字列の内部エンコーディングに依存して、 | |
| 16384 | フィールドの区切りではなくフィールドの一部として扱われることがあります。 | |
| 16385 | ||
| 16386 | =begin original | |
| 16387 | ||
| 16388 | If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering | |
| 16389 | the previously described I<awk> emulation. | |
| 16390 | ||
| 16391 | =end original | |
| 16392 | ||
| 16393 | 省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、 | |
| 16394 | 先に記述した I<awk> エミュレーションを起動します。 | |
| 16395 | ||
| 16396 | =begin original | |
| 16397 | ||
| 16398 | If LIMIT is specified and positive, it represents the maximum number | |
| 16399 | of fields into which the EXPR may be split; in other words, LIMIT is | |
| 16400 | one greater than the maximum number of times EXPR may be split. Thus, | |
| 16401 | the LIMIT value C<1> means that EXPR may be split a maximum of zero | |
| 16402 | times, producing a maximum of one field (namely, the entire value of | |
| 16403 | EXPR). For instance: | |
| 16404 | ||
| 16405 | =end original | |
| 16406 | ||
| 16407 | LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を | |
| 16408 | 表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。 | |
| 16409 | 従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、 | |
| 16410 | 最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。 | |
| 16411 | 9548 | 例えば: |
| 16412 | 9549 | |
| 16413 | | |
| 9550 | print join(':', split(/(?=\w)/, 'hi there!')); | |
| 16414 | 9551 | |
| 16415 | 9552 | =begin original |
| 16416 | 9553 | |
| 16417 | produces the output | |
| 9554 | produces the output 'h:i :t:h:e:r:e!'. | |
| 16418 | 9555 | |
| 16419 | 9556 | =end original |
| 16420 | 9557 | |
| 16421 | これ | |
| 9558 | これの出力は 'h:i :t:h:e:r:e!' となります。 | |
| 16422 | 9559 | |
| 16423 | print join(':', split(//, 'abc', 2)), "\n"; | |
| 16424 | ||
| 16425 | 9560 | =begin original |
| 16426 | 9561 | |
| 16427 | pr | |
| 9562 | The LIMIT parameter can be used to split a line partially | |
| 16428 | 9563 | |
| 16429 | 9564 | =end original |
| 16430 | 9565 | |
| 16431 | ||
| 9566 | LIMIT を使うと、行を部分的に split することができます。 | |
| 16432 | 9567 | |
| 16433 | | |
| 9568 | ($login, $passwd, $remainder) = split(/:/, $_, 3); | |
| 16434 | print join(':', split(//, 'abc', 4)), "\n"; | |
| 16435 | 9569 | |
| 16436 | 9570 | =begin original |
| 16437 | 9571 | |
| 16438 | ||
| 9572 | When assigning to a list, if LIMIT is omitted, Perl supplies a LIMIT | |
| 9573 | one larger than the number of variables in the list, to avoid | |
| 9574 | unnecessary work. For the list above LIMIT would have been 4 by | |
| 9575 | default. In time critical applications it behooves you not to split | |
| 9576 | into more fields than you really need. | |
| 16439 | 9577 | |
| 16440 | 9578 | =end original |
| 16441 | 9579 | |
| 16442 | ||
| 9580 | リストへ代入するとき、LIMIT を省略すると、Perl は、 | |
| 9581 | 無駄な仕事を避けるため、そのリストの変数の数より、1 つだけ大きい | |
| 9582 | LIMIT が与えられたものとして処理を行ないます。 | |
| 9583 | 上のリストの場合には、LIMIT はデフォルトで 4 になります。 | |
| 9584 | 時間が問題となるアプリケーションでは、 | |
| 9585 | 必要以上のフィールドに分けないようにする必要があります。 | |
| 16443 | 9586 | |
| 16444 | 9587 | =begin original |
| 16445 | 9588 | |
| 16446 | If | |
| 9589 | If the PATTERN contains parentheses, additional list elements are | |
| 16447 | ||
| 9590 | created from each matching substring in the delimiter. | |
| 16448 | 9591 | |
| 16449 | 9592 | =end original |
| 16450 | 9593 | |
| 16451 | ||
| 9594 | PATTERN に括弧が含まれていると、デリミタ内の部分文字列にマッチするものも、 | |
| 16452 | ||
| 9595 | リスト要素に含まれるようになります。 | |
| 16453 | 9596 | |
| 16454 | ||
| 9597 | split(/([,-])/, "1-10,20", 3); | |
| 16455 | 9598 | |
| 16456 | If LIMIT is omitted (or, equivalently, zero), then it is usually | |
| 16457 | treated as if it were instead negative but with the exception that | |
| 16458 | trailing empty fields are stripped (empty leading fields are always | |
| 16459 | preserved); if all fields are empty, then all fields are considered to | |
| 16460 | be trailing (and are thus stripped in this case). Thus, the following: | |
| 16461 | ||
| 16462 | =end original | |
| 16463 | ||
| 16464 | LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように | |
| 16465 | 動作しますが、末尾の空フィールドは取り除かれるという例外があります | |
| 16466 | (先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、 | |
| 16467 | 全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。 | |
| 16468 | 従って、以下のようにすると: | |
| 16469 | ||
| 16470 | print join(':', split(/,/, 'a,b,c,,,')), "\n"; | |
| 16471 | ||
| 16472 | 9599 | =begin original |
| 16473 | 9600 | |
| 16474 | produces the | |
| 9601 | produces the list value | |
| 16475 | 9602 | |
| 16476 | 9603 | =end original |
| 16477 | 9604 | |
| 16478 | ||
| 9605 | は、以下のリスト値を生成します。 | |
| 16479 | 9606 | |
| 16480 | | |
| 9607 | (1, '-', 10, ',', 20) | |
| 16481 | 9608 | |
| 16482 | 9609 | =begin original |
| 16483 | 9610 | |
| 16484 | ||
| 9611 | If you had the entire header of a normal Unix email message in $header, | |
| 9612 | you could split it up into fields and their values this way: | |
| 16485 | 9613 | |
| 16486 | 9614 | =end original |
| 16487 | 9615 | |
| 16488 | ||
| 9616 | $header に Unix E メールメッセージヘッダ全体が入っているとすると、 | |
| 9617 | 以下のようにしてフィールドとその値に分割できます: | |
| 16489 | 9618 | |
| 16490 | ||
| 9619 | $header =~ s/\n\s+/ /g; # fix continuation lines | |
| 9620 | %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header); | |
| 16491 | 9621 | |
| 16492 | In time-critical applications, it is worthwhile to avoid splitting | |
| 16493 | into more fields than necessary. Thus, when assigning to a list, | |
| 16494 | if LIMIT is omitted (or zero), then LIMIT is treated as though it | |
| 16495 | were one larger than the number of variables in the list; for the | |
| 16496 | following, LIMIT is implicitly 3: | |
| 16497 | ||
| 16498 | =end original | |
| 16499 | ||
| 16500 | 時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは | |
| 16501 | 価値があります。 | |
| 16502 | 従って、リストに代入される場合に、LIMIT が省略される(または 0)と、 | |
| 16503 | LIMIT は リストにある変数の数より一つ大きい数のように扱われます; | |
| 16504 | 次の場合、LIMIT は暗黙に 3 になります: | |
| 16505 | ||
| 16506 | my ($login, $passwd) = split(/:/); | |
| 16507 | ||
| 16508 | 9622 | =begin original |
| 16509 | 9623 | |
| 16510 | ||
| 9624 | The pattern C</PATTERN/> may be replaced with an expression to specify | |
| 16511 | p | |
| 9625 | patterns that vary at runtime. (To do runtime compilation only once, | |
| 9626 | use C</$variable/o>.) | |
| 16512 | 9627 | |
| 16513 | 9628 | =end original |
| 16514 | 9629 | |
| 16515 | ||
| 9630 | /PATTERN/ は、実行時に変わるパターンを指定する式で置き換えることができます。 | |
| 16516 | ||
| 9631 | (実行時のコンパイルを 1 度にするために、/$variable/o を使ってください。) | |
| 16517 | 9632 | |
| 16518 | 9633 | =begin original |
| 16519 | 9634 | |
| 16520 | A | |
| 9635 | As a special case, specifying a PATTERN of space (C<' '>) will split on | |
| 16521 | ||
| 9636 | white space just as C<split> with no arguments does. Thus, C<split(' ')> can | |
| 9637 | be used to emulate B<awk>'s default behavior, whereas C<split(/ /)> | |
| 9638 | will give you as many null initial fields as there are leading spaces. | |
| 9639 | A C<split> on C</\s+/> is like a C<split(' ')> except that any leading | |
| 9640 | whitespace produces a null first field. A C<split> with no arguments | |
| 9641 | really does a C<split(' ', $_)> internally. | |
| 16522 | 9642 | |
| 16523 | 9643 | =end original |
| 16524 | 9644 | |
| 16525 | ||
| 9645 | 特別な場合として、PATTERN にスペース (C<' '>) を指定すると、 | |
| 16526 | ||
| 9646 | 引数なしの C<split> のように空白で split を行ないます。 | |
| 16527 | ||
| 9647 | つまり、C<split(' ')> は B<awk> のデフォルトの動作をエミュレートするために | |
| 9648 | 使うことができ、C<split(/ /)> は行頭のスペースの数に応じた空フィールドが | |
| 9649 | できます。 | |
| 9650 | C<split /\s+/> は C<split(' ')> と同様ですが、 | |
| 9651 | 先頭の空白は先頭の空フィールドとなります。 | |
| 9652 | 引数なしの C<split> は内部的には C<split(' ', $_)> を実行します。 | |
| 16528 | 9653 | |
| 16529 | print join(':', split(/ /, ' abc')), "\n"; | |
| 16530 | ||
| 16531 | 9654 | =begin original |
| 16532 | 9655 | |
| 16533 | ||
| 9656 | A PATTERN of C</^/> is treated as if it were C</^/m>, since it isn't | |
| 16534 | ||
| 9657 | much use otherwise. | |
| 16535 | 9658 | |
| 16536 | ||
| 9659 | Example: | |
| 16537 | 9660 | |
| 16538 | これは出力 C<:abc> を生成します。 | |
| 16539 | しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので: | |
| 16540 | ||
| 16541 | print join(':', split(//, ' abc')); | |
| 16542 | ||
| 16543 | =begin original | |
| 16544 | ||
| 16545 | produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>). | |
| 16546 | ||
| 16547 | 9661 | =end original |
| 16548 | 9662 | |
| 16549 | ||
| 9663 | PATTERN に C</^/> を指定すると C</^/m> として扱われます。 | |
| 9664 | 他の意味に使われることはまずないからです。 | |
| 16550 | 9665 | |
| 16551 | ||
| 9666 | 例: | |
| 16552 | 9667 | |
| 16553 | ||
| 9668 | open(PASSWD, '/etc/passwd'); | |
| 16554 | ||
| 9669 | while (<PASSWD>) { | |
| 16555 | ||
| 9670 | chomp; | |
| 16556 | ||
| 9671 | ($login, $passwd, $uid, $gid, | |
| 9672 | $gcos, $home, $shell) = split(/:/); | |
| 9673 | #... | |
| 9674 | } | |
| 16557 | 9675 | |
| 16558 | =end original | |
| 16559 | 9676 | |
| 16560 | ||
| 9677 | =item sprintf FORMAT, LIST | |
| 16561 | マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に | |
| 16562 | 指定されていない場合です; このようなフィールドは前の例のように | |
| 16563 | 取り除かれます)。 | |
| 16564 | 従って: | |
| 16565 | 9678 | |
| 16566 | print join(':', split(//, ' abc', -1)), "\n"; | |
| 16567 | ||
| 16568 | 9679 | =begin original |
| 16569 | 9680 | |
| 16570 | ||
| 9681 | Returns a string formatted by the usual C<printf> conventions of the C | |
| 9682 | library function C<sprintf>. See below for more details | |
| 9683 | and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of | |
| 9684 | the general principles. | |
| 16571 | 9685 | |
| 16572 | ||
| 9686 | For example: | |
| 16573 | 9687 | |
| 16574 | これは出力 S<C< :a:b:c:>> を生成します。 | |
| 16575 | ||
| 16576 | =begin original | |
| 16577 | ||
| 16578 | If the PATTERN contains | |
| 16579 | L<capturing groups|perlretut/Grouping things and hierarchical matching>, | |
| 16580 | then for each separator, an additional field is produced for each substring | |
| 16581 | captured by a group (in the order in which the groups are specified, | |
| 16582 | as per L<backreferences|perlretut/Backreferences>); if any group does not | |
| 16583 | match, then it captures the L<C<undef>|/undef EXPR> value instead of a | |
| 16584 | substring. Also, | |
| 16585 | note that any such additional field is produced whenever there is a | |
| 16586 | separator (that is, whenever a split occurs), and such an additional field | |
| 16587 | does B<not> count towards the LIMIT. Consider the following expressions | |
| 16588 | evaluated in list context (each returned list is provided in the associated | |
| 16589 | comment): | |
| 16590 | ||
| 16591 | 9688 | =end original |
| 16592 | 9689 | |
| 16593 | ||
| 9690 | 普通の C 言語の C<printf> 記法のフォーマットで、整形された文字列を返します。 | |
| 16594 | L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を | |
| 16595 | 含んでいる場合、それぞれのセパレータについて、 | |
| 16596 | (L<後方参照|perlretut/Backreferences> のようにグループが指定された) | |
| 16597 | グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが | |
| 16598 | 生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに | |
| 16599 | L<C<undef>|/undef EXPR> 値を捕捉します。 | |
| 16600 | また、このような追加のフィールドはセパレータがあるとき(つまり、分割が | |
| 16601 | 行われるとき)はいつでも生成され、このような追加のフィールドは | |
| 16602 | LIMIT に関してはカウント B<されない> ことに注意してください。 | |
| 16603 | リストコンテキストで評価される以下のような式を考えます | |
| 16604 | (それぞれの返されるリストは関連づけられたコメントで提供されます): | |
| 16605 | ||
| 16606 | split(/-|,/, "1-10,20", 3) | |
| 16607 | # ('1', '10', '20') | |
| 16608 | ||
| 16609 | split(/(-|,)/, "1-10,20", 3) | |
| 16610 | # ('1', '-', '10', ',', '20') | |
| 16611 | ||
| 16612 | split(/-|(,)/, "1-10,20", 3) | |
| 16613 | # ('1', undef, '10', ',', '20') | |
| 16614 | ||
| 16615 | split(/(-)|,/, "1-10,20", 3) | |
| 16616 | # ('1', '-', '10', undef, '20') | |
| 16617 | ||
| 16618 | split(/(-)|(,)/, "1-10,20", 3) | |
| 16619 | # ('1', '-', undef, '10', undef, ',', '20') | |
| 16620 | ||
| 16621 | =item sprintf FORMAT, LIST | |
| 16622 | X<sprintf> | |
| 16623 | ||
| 16624 | =for Pod::Functions formatted print into a string | |
| 16625 | ||
| 16626 | =begin original | |
| 16627 | ||
| 16628 | Returns a string formatted by the usual | |
| 16629 | L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C | |
| 16630 | library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for | |
| 16631 | more details and see L<sprintf(3)> or L<printf(3)> on your system for an | |
| 16632 | explanation of the general principles. | |
| 16633 | ||
| 16634 | =end original | |
| 16635 | ||
| 16636 | C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の | |
| 16637 | 普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の | |
| 16638 | 整形された文字列を返します。 | |
| 16639 | 9691 | 一般的な原則の説明については以下の説明と、システムの |
| 16640 | 9692 | L<sprintf(3)> または L<printf(3)> の説明を参照してください。 |
| 16641 | 9693 | |
| 16642 | ||
| 9694 | 例: | |
| 16643 | 9695 | |
| 16644 | For example: | |
| 16645 | ||
| 16646 | =end original | |
| 16647 | ||
| 16648 | 例えば: | |
| 16649 | ||
| 16650 | 9696 | # Format number with up to 8 leading zeroes |
| 16651 | | |
| 9697 | $result = sprintf("%08d", $number); | |
| 16652 | 9698 | |
| 16653 | 9699 | # Round number to 3 digits after decimal point |
| 16654 | | |
| 9700 | $rounded = sprintf("%.3f", $number); | |
| 16655 | 9701 | |
| 16656 | 9702 | =begin original |
| 16657 | 9703 | |
| 16658 | Perl does its own | |
| 9704 | Perl does its own C<sprintf> formatting--it emulates the C | |
| 16659 | ||
| 9705 | function C<sprintf>, but it doesn't use it (except for floating-point | |
| 16660 | ||
| 9706 | numbers, and even then only the standard modifiers are allowed). As a | |
| 16661 | ||
| 9707 | result, any non-standard extensions in your local C<sprintf> are not | |
| 16662 | ||
| 9708 | available from Perl. | |
| 16663 | therefore unavailable from Perl. | |
| 16664 | 9709 | |
| 16665 | 9710 | =end original |
| 16666 | 9711 | |
| 16667 | Perl は | |
| 9712 | Perl は C<sprintf> フォーマット処理を自力で行います。 | |
| 16668 | これは C の | |
| 9713 | これは C の C<sprintf> 関数をエミュレートしますが、 | |
| 16669 | (浮動小数点を除きますが、それでも標準の | |
| 9714 | C の関数は使いません(浮動小数点を除きますが、それでも標準の | |
| 16670 | ||
| 9715 | 記述子のみが利用できます)。 | |
| 9716 | 従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。 | |
| 16671 | 9717 | |
| 16672 | 9718 | =begin original |
| 16673 | 9719 | |
| 16674 | Unlike | |
| 9720 | Unlike C<printf>, C<sprintf> does not do what you probably mean when you | |
| 16675 | ||
| 9721 | pass it an array as your first argument. The array is given scalar context, | |
| 16676 | when you pass it an array as your first argument. | |
| 16677 | The array is given scalar context, | |
| 16678 | 9722 | and instead of using the 0th element of the array as the format, Perl will |
| 16679 | 9723 | use the count of elements in the array as the format, which is almost never |
| 16680 | 9724 | useful. |
| 16681 | 9725 | |
| 16682 | 9726 | =end original |
| 16683 | 9727 | |
| 16684 | ||
| 9728 | C<printf> と違って、 C<sprintf> の最初の引数に配列を渡しても | |
| 16685 | L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても | |
| 16686 | 9729 | あなたが多分望むとおりには動作しません。 |
| 16687 | 9730 | 配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、 |
| 16688 | 配列の要素数をフォーマットとして扱います | |
| 9731 | 配列の要素数をフォーマットとして扱います。 | |
| 9732 | これはほとんど役に立ちません。 | |
| 16689 | 9733 | |
| 16690 | 9734 | =begin original |
| 16691 | 9735 | |
| 16692 | Perl's | |
| 9736 | Perl's C<sprintf> permits the following universally-known conversions: | |
| 16693 | universally-known conversions: | |
| 16694 | 9737 | |
| 16695 | 9738 | =end original |
| 16696 | 9739 | |
| 16697 | Perl の | |
| 9740 | Perl の C<sprintf> は以下の一般に知られている変換に対応しています: | |
| 16698 | 対応しています: | |
| 16699 | 9741 | |
| 16700 | ||
| 9742 | %% a percent sign | |
| 9743 | %c a character with the given number | |
| 9744 | %s a string | |
| 9745 | %d a signed integer, in decimal | |
| 9746 | %u an unsigned integer, in decimal | |
| 9747 | %o an unsigned integer, in octal | |
| 9748 | %x an unsigned integer, in hexadecimal | |
| 9749 | %e a floating-point number, in scientific notation | |
| 9750 | %f a floating-point number, in fixed decimal notation | |
| 9751 | %g a floating-point number, in %e or %f notation | |
| 16701 | 9752 | |
| 16702 | %% a percent sign | |
| 16703 | %c a character with the given number | |
| 16704 | %s a string | |
| 16705 | %d a signed integer, in decimal | |
| 16706 | %u an unsigned integer, in decimal | |
| 16707 | %o an unsigned integer, in octal | |
| 16708 | %x an unsigned integer, in hexadecimal | |
| 16709 | %e a floating-point number, in scientific notation | |
| 16710 | %f a floating-point number, in fixed decimal notation | |
| 16711 | %g a floating-point number, in %e or %f notation | |
| 16712 | ||
| 16713 | =end original | |
| 16714 | ||
| 16715 | %% パーセントマーク | |
| 16716 | %c 与えられた番号の文字 | |
| 16717 | %s 文字列 | |
| 16718 | %d 符号付き 10 進数 | |
| 16719 | %u 符号なし 10 進数 | |
| 16720 | %o 符号なし 8 進数 | |
| 16721 | %x 符号なし 16 進数 | |
| 16722 | %e 科学的表記の浮動小数点数 | |
| 16723 | %f 固定 10 進数表記の浮動小数点数 | |
| 16724 | %g %e か %f の表記の浮動小数点数 | |
| 16725 | ||
| 16726 | 9753 | =begin original |
| 16727 | 9754 | |
| 16728 | 9755 | In addition, Perl permits the following widely-supported conversions: |
| 16729 | 9756 | |
| 16730 | 9757 | =end original |
| 16731 | 9758 | |
| 16732 | 9759 | さらに、Perl では以下のよく使われている変換に対応しています: |
| 16733 | 9760 | |
| 16734 | ||
| 9761 | %X like %x, but using upper-case letters | |
| 9762 | %E like %e, but using an upper-case "E" | |
| 9763 | %G like %g, but with an upper-case "E" (if applicable) | |
| 9764 | %b an unsigned integer, in binary | |
| 9765 | %p a pointer (outputs the Perl value's address in hexadecimal) | |
| 9766 | %n special: *stores* the number of characters output so far | |
| 9767 | into the next variable in the parameter list | |
| 16735 | 9768 | |
| 16736 | %X like %x, but using upper-case letters | |
| 16737 | %E like %e, but using an upper-case "E" | |
| 16738 | %G like %g, but with an upper-case "E" (if applicable) | |
| 16739 | %b an unsigned integer, in binary | |
| 16740 | %B like %b, but using an upper-case "B" with the # flag | |
| 16741 | %p a pointer (outputs the Perl value's address in hexadecimal) | |
| 16742 | %n special: *stores* the number of characters output so far | |
| 16743 | into the next argument in the parameter list | |
| 16744 | %a hexadecimal floating point | |
| 16745 | %A like %a, but using upper-case letters | |
| 16746 | ||
| 16747 | =end original | |
| 16748 | ||
| 16749 | %X %x と同様だが大文字を使う | |
| 16750 | %E %e と同様だが大文字の "E" を使う | |
| 16751 | %G %g と同様だが(適切なら)大文字の "E" を使う | |
| 16752 | %b 符号なし 2 進数 | |
| 16753 | %B %b と同様だが、# フラグで大文字の "B" を使う | |
| 16754 | %p ポインタ (Perl の値のアドレスを 16 進数で出力する) | |
| 16755 | %n 特殊: 出力文字数を引数リストの次の変数に「格納」する | |
| 16756 | %a 16 進浮動小数点 | |
| 16757 | %A %a と同様だが、大文字を使う | |
| 16758 | ||
| 16759 | 9769 | =begin original |
| 16760 | 9770 | |
| 16761 | 9771 | Finally, for backward (and we do mean "backward") compatibility, Perl |
| 16762 | 9772 | permits these unnecessary but widely-supported conversions: |
| 16763 | 9773 | |
| 16764 | 9774 | =end original |
| 16765 | 9775 | |
| 16766 | 9776 | 最後に、過去との互換性(これは「過去」だと考えています)のために、 |
| 16767 | 9777 | Perl は以下の不要ではあるけれども広く使われている変換に対応しています。 |
| 16768 | 9778 | |
| 16769 | ||
| 9779 | %i a synonym for %d | |
| 9780 | %D a synonym for %ld | |
| 9781 | %U a synonym for %lu | |
| 9782 | %O a synonym for %lo | |
| 9783 | %F a synonym for %f | |
| 16770 | 9784 | |
| 16771 | %i a synonym for %d | |
| 16772 | %D a synonym for %ld | |
| 16773 | %U a synonym for %lu | |
| 16774 | %O a synonym for %lo | |
| 16775 | %F a synonym for %f | |
| 16776 | ||
| 16777 | =end original | |
| 16778 | ||
| 16779 | %i %d の同義語 | |
| 16780 | %D %ld の同義語 | |
| 16781 | %U %lu の同義語 | |
| 16782 | %O %lo の同義語 | |
| 16783 | %F %f の同義語 | |
| 16784 | ||
| 16785 | 9785 | =begin original |
| 16786 | 9786 | |
| 16787 | Note that the number of exponent digits in the scientific notation | |
| 9787 | Note that the number of exponent digits in the scientific notation by | |
| 16788 | ||
| 9788 | C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the | |
| 16789 | 9789 | exponent less than 100 is system-dependent: it may be three or less |
| 16790 | 9790 | (zero-padded as necessary). In other words, 1.23 times ten to the |
| 16791 | 99th may be either "1.23e99" or "1.23e099". | |
| 9791 | 99th may be either "1.23e99" or "1.23e099". | |
| 16792 | the exponent or the hexadecimal digits may float: especially the | |
| 16793 | "long doubles" Perl configuration option may cause surprises. | |
| 16794 | 9792 | |
| 16795 | 9793 | =end original |
| 16796 | 9794 | |
| 16797 | 9795 | C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の |
| 16798 | 9796 | 指数部の科学的な表記法はシステム依存であることに注意してください: |
| 16799 | 9797 | 3 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で |
| 16800 | 9798 | パッディングされます)。 |
| 16801 | 9799 | 言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし |
| 16802 | 9800 | "1.23e099" かもしれません。 |
| 16803 | 同様に C<%a> と C<%A> の場合: | |
| 16804 | 指数部と 16 進数が浮動小数点かもしれません: | |
| 16805 | 特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。 | |
| 16806 | 9801 | |
| 16807 | 9802 | =begin original |
| 16808 | 9803 | |
| 16809 | ||
| 9804 | Perl permits the following universally-known flags between the C<%> | |
| 16810 | a | |
| 9805 | and the conversion letter: | |
| 16811 | In order, these are: | |
| 16812 | 9806 | |
| 16813 | 9807 | =end original |
| 16814 | 9808 | |
| 16815 | C<%> と | |
| 9809 | Perl は C<%> と変換文字の間のフラグとして以下の一般に知られている | |
| 16816 | ||
| 9810 | ものに対応しています: | |
| 16817 | 順番に、以下のものがあります: | |
| 16818 | 9811 | |
| 16819 | ||
| 9812 | space prefix positive number with a space | |
| 9813 | + prefix positive number with a plus sign | |
| 16821 | =item format parameter index | |
| 16822 | ||
| 16823 | (フォーマットパラメータインデックス) | |
| 16824 | ||
| 16825 | =begin original | |
| 16826 | ||
| 16827 | An explicit format parameter index, such as C<2$>. By default sprintf | |
| 16828 | will format the next unused argument in the list, but this allows you | |
| 16829 | to take the arguments out of order: | |
| 16830 | ||
| 16831 | =end original | |
| 16832 | ||
| 16833 | C<2$> のような明示的なフォーマットパラメータインデックス。 | |
| 16834 | デフォルトでは sprintf はリストの次の使われていない引数を | |
| 16835 | フォーマットしますが、これによって異なった順番の引数を使えるようにします: | |
| 16836 | ||
| 16837 | printf '%2$d %1$d', 12, 34; # prints "34 12" | |
| 16838 | printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1" | |
| 16839 | ||
| 16840 | =item flags | |
| 16841 | ||
| 16842 | (フラグ) | |
| 16843 | ||
| 16844 | =begin original | |
| 16845 | ||
| 16846 | one or more of: | |
| 16847 | ||
| 16848 | =end original | |
| 16849 | ||
| 16850 | 以下のうちの一つまたは複数指定できます: | |
| 16851 | ||
| 16852 | =begin original | |
| 16853 | ||
| 16854 | space prefix non-negative number with a space | |
| 16855 | + prefix non-negative number with a plus sign | |
| 16856 | 9814 | - left-justify within the field |
| 16857 | 9815 | 0 use zeros, not spaces, to right-justify |
| 16858 | # | |
| 9816 | # prefix non-zero octal with "0", non-zero hex with "0x" | |
| 16859 | | |
| 9817 | number minimum field width | |
| 16860 | | |
| 9818 | .number "precision": digits after decimal point for | |
| 9819 | floating-point, max length for string, minimum length | |
| 9820 | for integer | |
| 9821 | l interpret integer as C type "long" or "unsigned long" | |
| 9822 | h interpret integer as C type "short" or "unsigned short" | |
| 9823 | If no flags, interpret integer as C type "int" or "unsigned" | |
| 16861 | 9824 | |
| 16862 | =end original | |
| 16863 | ||
| 16864 | space 非負数の前に空白をつける | |
| 16865 | + 非負数の前にプラス記号をつける | |
| 16866 | - フィールド内で左詰めする | |
| 16867 | 0 右詰めに空白ではなくゼロを使う | |
| 16868 | # 8 進数では確実に先頭に "0" をつける; | |
| 16869 | 非 0 の 16 進数では "0x" か "0X" をつける; | |
| 16870 | 非 0 の 2 進数では "0b" か "0B" をつける | |
| 16871 | ||
| 16872 | 9825 | =begin original |
| 16873 | 9826 | |
| 16874 | ||
| 9827 | There are also two Perl-specific flags: | |
| 16875 | 9828 | |
| 16876 | 9829 | =end original |
| 16877 | 9830 | |
| 16878 | ||
| 9831 | さらに Perl 独自の 2 つのフラグがあります: | |
| 16879 | 9832 | |
| 16880 | | |
| 9833 | V interpret integer as Perl's standard integer type | |
| 16881 | | |
| 9834 | v interpret string as a vector of integers, output as | |
| 16882 | pri | |
| 9835 | numbers separated either by dots, or by an arbitrary | |
| 16883 | | |
| 9836 | string received from the argument list when the flag | |
| 16884 | | |
| 9837 | is preceded by C<*> | |
| 16885 | printf '<%+d>', -12; # prints "<-12>" | |
| 16886 | printf '<%6s>', 12; # prints "< 12>" | |
| 16887 | printf '<%-6s>', 12; # prints "<12 >" | |
| 16888 | printf '<%06s>', 12; # prints "<000012>" | |
| 16889 | printf '<%#o>', 12; # prints "<014>" | |
| 16890 | printf '<%#x>', 12; # prints "<0xc>" | |
| 16891 | printf '<%#X>', 12; # prints "<0XC>" | |
| 16892 | printf '<%#b>', 12; # prints "<0b1100>" | |
| 16893 | printf '<%#B>', 12; # prints "<0B1100>" | |
| 16894 | 9838 | |
| 16895 | 9839 | =begin original |
| 16896 | 9840 | |
| 16897 | Whe | |
| 9841 | Where a number would appear in the flags, an asterisk (C<*>) may be | |
| 16898 | ||
| 9842 | used instead, in which case Perl uses the next item in the parameter | |
| 9843 | list as the given number (that is, as the field width or precision). | |
| 16900 | =end original | |
| 16901 | ||
| 16902 | 空白とプラス記号がフラグとして同時に与えられると、 | |
| 16903 | 空白は無視されます。 | |
| 16904 | ||
| 16905 | printf '<%+ d>', 12; # prints "<+12>" | |
| 16906 | printf '<% +d>', 12; # prints "<+12>" | |
| 16907 | ||
| 16908 | =begin original | |
| 16909 | ||
| 16910 | When the # flag and a precision are given in the %o conversion, | |
| 16911 | the precision is incremented if it's necessary for the leading "0". | |
| 16912 | ||
| 16913 | =end original | |
| 16914 | ||
| 16915 | %o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は | |
| 16916 | 精度に 1 が加えられます。 | |
| 16917 | ||
| 16918 | printf '<%#.5o>', 012; # prints "<00012>" | |
| 16919 | printf '<%#.5o>', 012345; # prints "<012345>" | |
| 16920 | printf '<%#.0o>', 0; # prints "<0>" | |
| 16921 | ||
| 16922 | =item vector flag | |
| 16923 | ||
| 16924 | (ベクタフラグ) | |
| 16925 | ||
| 16926 | =begin original | |
| 16927 | ||
| 16928 | This flag tells Perl to interpret the supplied string as a vector of | |
| 16929 | integers, one for each character in the string. Perl applies the format to | |
| 16930 | each integer in turn, then joins the resulting strings with a separator (a | |
| 16931 | dot C<.> by default). This can be useful for displaying ordinal values of | |
| 16932 | characters in arbitrary strings: | |
| 16933 | ||
| 16934 | =end original | |
| 16935 | ||
| 16936 | このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして | |
| 16937 | 解釈させます。 | |
| 16938 | Perl は各数値をフォーマットし、それから結果の文字列をセパレータ | |
| 16939 | (デフォルトでは C<.>)で連結します。 | |
| 16940 | これは任意の文字列の文字を順序付きの値として表示するのに便利です: | |
| 16941 | ||
| 16942 | printf "%vd", "AB\x{100}"; # prints "65.66.256" | |
| 16943 | printf "version is v%vd\n", $^V; # Perl's version | |
| 16944 | ||
| 16945 | =begin original | |
| 16946 | ||
| 16947 | Put an asterisk C<*> before the C<v> to override the string to | |
| 16948 | use to separate the numbers: | |
| 16949 | ||
| 16950 | =end original | |
| 16951 | ||
| 16952 | アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を | |
| 16953 | 上書きします: | |
| 16954 | ||
| 16955 | printf "address is %*vX\n", ":", $addr; # IPv6 address | |
| 16956 | printf "bits are %0*v8b\n", " ", $bits; # random bitstring | |
| 16957 | ||
| 16958 | =begin original | |
| 16959 | ||
| 16960 | You can also explicitly specify the argument number to use for | |
| 16961 | the join string using something like C<*2$v>; for example: | |
| 16962 | ||
| 16963 | =end original | |
| 16964 | ||
| 16965 | また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に | |
| 16966 | 指定できます; 例えば: | |
| 16967 | ||
| 16968 | printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses | |
| 16969 | @addr[1..3], ":"; | |
| 16970 | ||
| 16971 | =item (minimum) width | |
| 16972 | ||
| 16973 | ((最小)幅) | |
| 16974 | ||
| 16975 | =begin original | |
| 16976 | ||
| 16977 | Arguments are usually formatted to be only as wide as required to | |
| 16978 | display the given value. You can override the width by putting | |
| 16979 | a number here, or get the width from the next argument (with C<*>) | |
| 16980 | or from a specified argument (e.g., with C<*2$>): | |
| 16981 | ||
| 16982 | =end original | |
| 16983 | ||
| 16984 | 引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。 | |
| 16985 | ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で | |
| 16986 | 幅を上書きできます。 | |
| 16987 | ||
| 16988 | printf "<%s>", "a"; # prints "<a>" | |
| 16989 | printf "<%6s>", "a"; # prints "< a>" | |
| 16990 | printf "<%*s>", 6, "a"; # prints "< a>" | |
| 16991 | printf '<%*2$s>', "a", 6; # prints "< a>" | |
| 16992 | printf "<%2s>", "long"; # prints "<long>" (does not truncate) | |
| 16993 | ||
| 16994 | =begin original | |
| 16995 | ||
| 16996 | 9844 | If a field width obtained through C<*> is negative, it has the same |
| 16997 | 9845 | effect as the C<-> flag: left-justification. |
| 16998 | 9846 | |
| 16999 | 9847 | =end original |
| 17000 | 9848 | |
| 9849 | フラグとして数値を使えるところでは、代わりにアスタリスク (C<*>) を | |
| 9850 | 使うことができます: その場合、Perl はパラメータリストの次の要素を | |
| 9851 | 与えられた数値(フィールド幅か精度)として使います。 | |
| 17001 | 9852 | C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと |
| 17002 | 9853 | 同様の効果 (左詰め) があります。 |
| 17003 | 9854 | |
| 17004 | =item precision, or maximum width | |
| 17005 | X<precision> | |
| 17006 | ||
| 17007 | (精度あるいは最大幅) | |
| 17008 | ||
| 17009 | 9855 | =begin original |
| 17010 | 9856 | |
| 17011 | ||
| 9857 | The C<v> flag is useful for displaying ordinal values of characters | |
| 17012 | ||
| 9858 | in arbitrary strings: | |
| 17013 | For floating-point formats except C<g> and C<G>, this specifies | |
| 17014 | how many places right of the decimal point to show (the default being 6). | |
| 17015 | For example: | |
| 17016 | 9859 | |
| 17017 | 9860 | =end original |
| 17018 | 9861 | |
| 17019 | C< | |
| 9862 | C<v> フラグは任意の文字列の文字を順序付きの値として表示するのに | |
| 17020 | ||
| 9863 | 便利です: | |
| 17021 | 小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の | |
| 17022 | 桁数を指定します(デフォルトは 6 です)。 | |
| 17023 | 例えば: | |
| 17024 | 9864 | |
| 17025 | | |
| 9865 | printf "version is v%vd\n", $^V; # Perl's version | |
| 17026 | printf | |
| 9866 | printf "address is %*vX\n", ":", $addr; # IPv6 address | |
| 17027 | printf | |
| 9867 | printf "bits are %*vb\n", " ", $bits; # random bitstring | |
| 17028 | printf '<%.0f>', 1; # prints "<1>" | |
| 17029 | printf '<%e>', 10; # prints "<1.000000e+01>" | |
| 17030 | printf '<%.1e>', 10; # prints "<1.0e+01>" | |
| 17031 | 9868 | |
| 17032 | 9869 | =begin original |
| 17033 | 9870 | |
| 17034 | ||
| 9871 | If C<use locale> is in effect, the character used for the decimal | |
| 17035 | ||
| 9872 | point in formatted real numbers is affected by the LC_NUMERIC locale. | |
| 9873 | See L<perllocale>. | |
| 17036 | 9874 | |
| 17037 | 9875 | =end original |
| 17038 | 9876 | |
| 17039 | ||
| 9877 | C<use locale> が有効の場合、フォーマットされた実数の小数点として | |
| 9878 | 使われる文字は LC_NUMERIC ロケールの影響を受けます。 | |
| 9879 | L<perllocale> を参照してください。 | |
| 17040 | 9880 | |
| 17041 | # These examples are subject to system-specific variation. | |
| 17042 | printf '<%g>', 1; # prints "<1>" | |
| 17043 | printf '<%.10g>', 1; # prints "<1>" | |
| 17044 | printf '<%g>', 100; # prints "<100>" | |
| 17045 | printf '<%.1g>', 100; # prints "<1e+02>" | |
| 17046 | printf '<%.2g>', 100.01; # prints "<1e+02>" | |
| 17047 | printf '<%.5g>', 100.01; # prints "<100.01>" | |
| 17048 | printf '<%.4g>', 100.01; # prints "<100>" | |
| 17049 | printf '<%.1g>', 0.0111; # prints "<0.01>" | |
| 17050 | printf '<%.2g>', 0.0111; # prints "<0.011>" | |
| 17051 | printf '<%.3g>', 0.0111; # prints "<0.0111>" | |
| 17052 | ||
| 17053 | 9881 | =begin original |
| 17054 | 9882 | |
| 17055 | ||
| 9883 | If Perl understands "quads" (64-bit integers) (this requires | |
| 17056 | ||
| 9884 | either that the platform natively support quads or that Perl | |
| 17057 | ||
| 9885 | be specifically compiled to support quads), the characters | |
| 17058 | 9886 | |
| 17059 | 9887 | =end original |
| 17060 | 9888 | |
| 17061 | 整数 | |
| 9889 | Perl が 64 ビット整数を理解する場合(これにはプラットフォームが内部で | |
| 17062 | ||
| 9890 | 64 ビット整数に対応しているか、Perl が特別に 64ビット整数に対応するように | |
| 17063 | ||
| 9891 | コンパイルされている必要があります)、以下の文字には: | |
| 17064 | 9892 | |
| 17065 | ||
| 9893 | d u o x X b i D U O | |
| 17066 | printf '<%+.6d>', 1; # prints "<+000001>" | |
| 17067 | printf '<%-10.6d>', 1; # prints "<000001 >" | |
| 17068 | printf '<%10.6d>', 1; # prints "< 000001>" | |
| 17069 | printf '<%010.6d>', 1; # prints "< 000001>" | |
| 17070 | printf '<%+10.6d>', 1; # prints "< +000001>" | |
| 17071 | 9894 | |
| 17072 | printf '<%.6x>', 1; # prints "<000001>" | |
| 17073 | printf '<%#.6x>', 1; # prints "<0x000001>" | |
| 17074 | printf '<%-10.6x>', 1; # prints "<000001 >" | |
| 17075 | printf '<%10.6x>', 1; # prints "< 000001>" | |
| 17076 | printf '<%010.6x>', 1; # prints "< 000001>" | |
| 17077 | printf '<%#10.6x>', 1; # prints "< 0x000001>" | |
| 17078 | ||
| 17079 | 9895 | =begin original |
| 17080 | 9896 | |
| 17081 | ||
| 9897 | print quads, and they may optionally be preceded by | |
| 17082 | to fit the specified width: | |
| 17083 | 9898 | |
| 17084 | 9899 | =end original |
| 17085 | 9900 | |
| 17086 | ||
| 9901 | 64 ビット整数を表示し、また以下のフラグを前につけることができます: | |
| 17087 | 切り詰めます: | |
| 17088 | 9902 | |
| 17089 | | |
| 9903 | ll L q | |
| 17090 | printf '<%10.5s>', "truncated"; # prints "< trunc>" | |
| 17091 | 9904 | |
| 17092 | 9905 | =begin original |
| 17093 | 9906 | |
| 17094 | ||
| 9907 | For example | |
| 17095 | specified argument (e.g., with C<.*2$>): | |
| 17096 | 9908 | |
| 17097 | 9909 | =end original |
| 17098 | 9910 | |
| 17099 | ||
| 9911 | 例えば以下のようにします: | |
| 17100 | (C<.*2$> のように) 指定した引数から取ったりすることもできます: | |
| 17101 | 9912 | |
| 17102 | | |
| 9913 | %lld %16LX %qo | |
| 17103 | printf '<%.*x>', 6, 1; # prints "<000001>" | |
| 17104 | 9914 | |
| 17105 | printf '<%.*2$x>', 1, 6; # prints "<000001>" | |
| 17106 | ||
| 17107 | printf '<%6.*2$x>', 1, 4; # prints "< 0001>" | |
| 17108 | ||
| 17109 | 9915 | =begin original |
| 17110 | 9916 | |
| 17111 | If a precision obtained through C<*> is negative, it counts | |
| 17112 | as having no precision at all. | |
| 17113 | ||
| 17114 | =end original | |
| 17115 | ||
| 17116 | C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と | |
| 17117 | 同じ効果となります。 | |
| 17118 | ||
| 17119 | printf '<%.*s>', 7, "string"; # prints "<string>" | |
| 17120 | printf '<%.*s>', 3, "string"; # prints "<str>" | |
| 17121 | printf '<%.*s>', 0, "string"; # prints "<>" | |
| 17122 | printf '<%.*s>', -1, "string"; # prints "<string>" | |
| 17123 | ||
| 17124 | printf '<%.*d>', 1, 0; # prints "<0>" | |
| 17125 | printf '<%.*d>', 0, 0; # prints "<>" | |
| 17126 | printf '<%.*d>', -1, 0; # prints "<0>" | |
| 17127 | ||
| 17128 | =item size | |
| 17129 | ||
| 17130 | (サイズ) | |
| 17131 | ||
| 17132 | =begin original | |
| 17133 | ||
| 17134 | For numeric conversions, you can specify the size to interpret the | |
| 17135 | number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer | |
| 17136 | conversions (C<d u o x X b i D U O>), numbers are usually assumed to be | |
| 17137 | whatever the default integer size is on your platform (usually 32 or 64 | |
| 17138 | bits), but you can override this to use instead one of the standard C types, | |
| 17139 | as supported by the compiler used to build Perl: | |
| 17140 | ||
| 17141 | =end original | |
| 17142 | ||
| 17143 | 数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の | |
| 17144 | 大きさを指定できます。 | |
| 17145 | 整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの | |
| 17146 | デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、 | |
| 17147 | これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで | |
| 17148 | 上書きできます: | |
| 17149 | ||
| 17150 | =begin original | |
| 17151 | ||
| 17152 | hh interpret integer as C type "char" or "unsigned | |
| 17153 | char" on Perl 5.14 or later | |
| 17154 | h interpret integer as C type "short" or | |
| 17155 | "unsigned short" | |
| 17156 | j interpret integer as C type "intmax_t" on Perl | |
| 17157 | 5.14 or later; and prior to Perl 5.30, only with | |
| 17158 | a C99 compiler (unportable) | |
| 17159 | l interpret integer as C type "long" or | |
| 17160 | "unsigned long" | |
| 17161 | q, L, or ll interpret integer as C type "long long", | |
| 17162 | "unsigned long long", or "quad" (typically | |
| 17163 | 64-bit integers) | |
| 17164 | t interpret integer as C type "ptrdiff_t" on Perl | |
| 17165 | 5.14 or later | |
| 17166 | z interpret integer as C type "size_t" on Perl 5.14 | |
| 17167 | or later | |
| 17168 | ||
| 17169 | =end original | |
| 17170 | ||
| 17171 | hh Perl 5.14 以降で整数を C の "char" または "unsigned char" | |
| 17172 | 型として解釈する | |
| 17173 | h 整数を C の "char" または "unsigned char" 型として解釈する | |
| 17174 | j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を | |
| 17175 | C の "intmax_t" 型として解釈する (移植性なし) | |
| 17176 | l 整数を C の "long" または "unsigned long" と解釈する | |
| 17177 | h 整数を C の "short" または "unsigned short" と解釈する | |
| 17178 | q, L or ll 整数を C の "long long", "unsigned long long", | |
| 17179 | "quads"(典型的には 64 ビット整数) のどれかと解釈する | |
| 17180 | t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する | |
| 17181 | z Perl 5.14 以降で整数を C の "size_t" 型として解釈する | |
| 17182 | ||
| 17183 | =begin original | |
| 17184 | ||
| 17185 | As of 5.14, none of these raises an exception if they are not supported on | |
| 17186 | your platform. However, if warnings are enabled, a warning of the | |
| 17187 | L<C<printf>|warnings> warning class is issued on an unsupported | |
| 17188 | conversion flag. Should you instead prefer an exception, do this: | |
| 17189 | ||
| 17190 | =end original | |
| 17191 | ||
| 17192 | 5.14 から、プラットフォームがこれらに対応していないときでも例外が | |
| 17193 | 発生しなくなりました。 | |
| 17194 | しかし、もし警告が有効になっているなら、 | |
| 17195 | 非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。 | |
| 17196 | 例外の方がお好みなら、以下のようにします: | |
| 17197 | ||
| 17198 | use warnings FATAL => "printf"; | |
| 17199 | ||
| 17200 | =begin original | |
| 17201 | ||
| 17202 | If you would like to know about a version dependency before you | |
| 17203 | start running the program, put something like this at its top: | |
| 17204 | ||
| 17205 | =end original | |
| 17206 | ||
| 17207 | プログラムの実行開始前にバージョン依存について知りたいなら、先頭に | |
| 17208 | 以下のようなものを書きます: | |
| 17209 | ||
| 17210 | use 5.014; # for hh/j/t/z/ printf modifiers | |
| 17211 | ||
| 17212 | =begin original | |
| 17213 | ||
| 17214 | 9917 | You can find out whether your Perl supports quads via L<Config>: |
| 17215 | 9918 | |
| 17216 | 9919 | =end original |
| 17217 | 9920 | |
| 17218 | 9921 | Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って |
| 17219 | 9922 | 調べられます: |
| 17220 | 9923 | |
| 17221 | ||
| 9924 | use Config; | |
| 17222 | ||
| 9925 | ($Config{use64bitint} eq 'define' || $Config{longsize} == 8) && | |
| 17223 | ||
| 9926 | print "quads\n"; | |
| 17224 | print "Nice quads!\n"; | |
| 17225 | } | |
| 17226 | 9927 | |
| 17227 | 9928 | =begin original |
| 17228 | 9929 | |
| 17229 | ||
| 9930 | If Perl understands "long doubles" (this requires that the platform | |
| 17230 | ||
| 9931 | support long doubles), the flags | |
| 17231 | but you can force "long double" with C<q>, C<L>, or C<ll> if your | |
| 17232 | platform supports them. You can find out whether your Perl supports long | |
| 17233 | doubles via L<Config>: | |
| 17234 | 9932 | |
| 17235 | 9933 | =end original |
| 17236 | 9934 | |
| 17237 | ||
| 9935 | Perl が "long double" を理解する場合(これにはプラットフォームが | |
| 17238 | ||
| 9936 | long double に対応している必要があります)、以下の文字には: | |
| 17239 | プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して | |
| 17240 | "long double" を強制できます。 | |
| 17241 | Perl が long double に対応しているかどうかは L<Config> を使って | |
| 17242 | 調べられます: | |
| 17243 | 9937 | |
| 17244 | | |
| 9938 | e f g E F G | |
| 17245 | print "long doubles\n" if $Config{d_longdbl} eq "define"; | |
| 17246 | 9939 | |
| 17247 | 9940 | =begin original |
| 17248 | 9941 | |
| 17249 | ||
| 9942 | may optionally be preceded by | |
| 17250 | floating-point size to use on your platform via L<Config>: | |
| 17251 | 9943 | |
| 17252 | 9944 | =end original |
| 17253 | 9945 | |
| 17254 | ||
| 9946 | 以下のフラグを前につけることができます: | |
| 17255 | L<Config> を使って調べられます: | |
| 17256 | 9947 | |
| 17257 | | |
| 9948 | ll L | |
| 17258 | if ($Config{uselongdouble} eq "define") { | |
| 17259 | print "long doubles by default\n"; | |
| 17260 | } | |
| 17261 | 9949 | |
| 17262 | 9950 | =begin original |
| 17263 | 9951 | |
| 17264 | ||
| 9952 | For example | |
| 17265 | 9953 | |
| 17266 | 9954 | =end original |
| 17267 | 9955 | |
| 17268 | ||
| 9956 | 例えば以下のようにします: | |
| 17269 | 9957 | |
| 17270 | ||
| 9958 | %llf %Lg | |
| 17271 | ($Config{doublesize} == $Config{longdblsize}) && | |
| 17272 | print "doubles are long doubles\n"; | |
| 17273 | 9959 | |
| 17274 | 9960 | =begin original |
| 17275 | 9961 | |
| 17276 | ||
| 9962 | You can find out whether your Perl supports long doubles via L<Config>: | |
| 17277 | compatibility with XS code. It means "use the standard size for a Perl | |
| 17278 | integer or floating-point number", which is the default. | |
| 17279 | 9963 | |
| 17280 | 9964 | =end original |
| 17281 | 9965 | |
| 17282 | ||
| 9966 | Perl が long double に対応しているかどうかは L<Config> を使って | |
| 17283 | ||
| 9967 | 調べられます: | |
| 17284 | これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを | |
| 17285 | 意味し、これはデフォルトです。 | |
| 17286 | 9968 | |
| 17287 | ||
| 9969 | use Config; | |
| 9970 | $Config{d_longdbl} eq 'define' && print "long doubles\n"; | |
| 17288 | 9971 | |
| 17289 | ||
| 9972 | =item sqrt EXPR | |
| 17290 | 9973 | |
| 17291 | = | |
| 9974 | =item sqrt | |
| 17292 | 9975 | |
| 17293 | Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused | |
| 17294 | argument as the value to | |
| 17295 | format for each format specification. If the format specification | |
| 17296 | uses C<*> to require additional arguments, these are consumed from | |
| 17297 | the argument list in the order they appear in the format | |
| 17298 | specification I<before> the value to format. Where an argument is | |
| 17299 | specified by an explicit index, this does not affect the normal | |
| 17300 | order for the arguments, even when the explicitly specified index | |
| 17301 | would have been the next argument. | |
| 17302 | ||
| 17303 | =end original | |
| 17304 | ||
| 17305 | 通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、 | |
| 17306 | 使われていない次の引数を | |
| 17307 | フォーマットする値として使います。 | |
| 17308 | 追加の引数を要求するためにフォーマット指定 C<*> を使うと、 | |
| 17309 | これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に | |
| 17310 | 引数リストから消費されます。 | |
| 17311 | 引数の位置が明示的なインデックスを使って指定された場合、 | |
| 17312 | (明示的に指定したインデックスが次の引数の場合でも) | |
| 17313 | これは通常の引数の順番に影響を与えません。 | |
| 17314 | ||
| 17315 | 9976 | =begin original |
| 17316 | 9977 | |
| 17317 | ||
| 9978 | Return the square root of EXPR. If EXPR is omitted, returns square | |
| 9979 | root of C<$_>. Only works on non-negative operands, unless you've | |
| 9980 | loaded the standard Math::Complex module. | |
| 17318 | 9981 | |
| 17319 | 9982 | =end original |
| 17320 | 9983 | |
| 17321 | ||
| 9984 | EXPR の平方根を返します。 | |
| 9985 | EXPR を省略すると、C<$_> の平方根を返します。 | |
| 9986 | 標準の Math::Complex モジュールを使わない場合は、 | |
| 9987 | 負の数の引数は扱えません。 | |
| 17322 | 9988 | |
| 17323 | | |
| 9989 | use Math::Complex; | |
| 9990 | print sqrt(-2); # prints 1.4142135623731i | |
| 17324 | 9991 | |
| 17325 | = | |
| 9992 | =item srand EXPR | |
| 17326 | 9993 | |
| 17327 | ||
| 9994 | =item srand | |
| 17328 | as the value to format; while: | |
| 17329 | 9995 | |
| 17330 | =end original | |
| 17331 | ||
| 17332 | とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に | |
| 17333 | 使います; 一方: | |
| 17334 | ||
| 17335 | printf '<%*1$.*s>', $a, $b; | |
| 17336 | ||
| 17337 | 9996 | =begin original |
| 17338 | 9997 | |
| 17339 | ||
| 9998 | Sets the random number seed for the C<rand> operator. If EXPR is | |
| 17340 | value t | |
| 9999 | omitted, uses a semi-random value supplied by the kernel (if it supports | |
| 10000 | the F</dev/urandom> device) or based on the current time and process | |
| 10001 | ID, among other things. In versions of Perl prior to 5.004 the default | |
| 10002 | seed was just the current C<time>. This isn't a particularly good seed, | |
| 10003 | so many old programs supply their own seed value (often C<time ^ $$> or | |
| 10004 | C<time ^ ($$ + ($$ << 15))>), but that isn't necessary any more. | |
| 17341 | 10005 | |
| 17342 | 10006 | =end original |
| 17343 | 10007 | |
| 17344 | ||
| 10008 | rand 演算子のためのシード値を設定します。 | |
| 10009 | EXPR を省略すると、カーネルで提供されるもの | |
| 10010 | (F</dev/urandom> デバイスに対応している場合)または | |
| 10011 | 現在時刻やプロセス ID やその他のものを基礎にした | |
| 10012 | 擬似乱数を使います。 | |
| 10013 | 5.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。 | |
| 10014 | これは特によいシード値ではありませんでしたので、 | |
| 10015 | 多くの古いプログラムは自力でシード値を指定しています | |
| 10016 | (C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、 | |
| 10017 | もはやこれは必要ありません。 | |
| 17345 | 10018 | |
| 17346 | 10019 | =begin original |
| 17347 | 10020 | |
| 17348 | ||
| 10021 | In fact, it's usually not necessary to call C<srand> at all, because if | |
| 17349 | index, t | |
| 10022 | it is not called explicitly, it is called implicitly at the first use of | |
| 10023 | the C<rand> operator. However, this was not the case in version of Perl | |
| 10024 | before 5.004, so if your script will run under older Perl versions, it | |
| 10025 | should call C<srand>. | |
| 17350 | 10026 | |
| 17351 | 10027 | =end original |
| 17352 | 10028 | |
| 17353 | ||
| 10029 | 実際、普通は C<srand> を呼び出す必要は全くありません。 | |
| 17354 | ||
| 10030 | 明示的に呼び出されない場合、C<rand> 演算子を最初に使ったときに | |
| 10031 | 自動的に呼び出されるからです。 | |
| 10032 | しかし、5.004 以前のバージョンの Perl ではこれは行われないので、 | |
| 10033 | 古い Perl で動作させる可能性がある場合は、C<srand> を呼び出すべきです。 | |
| 17355 | 10034 | |
| 17356 | printf "%2\$d %d\n", 12, 34; # will print "34 12\n" | |
| 17357 | printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n" | |
| 17358 | printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n" | |
| 17359 | printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n" | |
| 17360 | printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n" | |
| 17361 | ||
| 17362 | =back | |
| 17363 | ||
| 17364 | 10035 | =begin original |
| 17365 | 10036 | |
| 17366 | ||
| 10037 | Note that you need something much more random than the default seed for | |
| 17367 | is | |
| 10038 | cryptographic purposes. Checksumming the compressed output of one or more | |
| 17368 | cal | |
| 10039 | rapidly changing operating system status programs is the usual method. For | |
| 17369 | ||
| 10040 | example: | |
| 17370 | numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale> | |
| 17371 | and L<POSIX>. | |
| 17372 | 10041 | |
| 17373 | 10042 | =end original |
| 17374 | 10043 | |
| 17375 | ||
| 10044 | 暗号処理には、 | |
| 17376 | ||
| 10045 | もっとランダムな値を使う必要があります。急激に変化する | |
| 17377 | ||
| 10046 | OS のステータス値プログラムの出力をひとつ | |
| 17378 | ||
| 10047 | または複数用い、圧縮してチェックサムをとる、 | |
| 17379 | ||
| 10048 | というようなことが普通、行なわれます。 | |
| 10049 | 例えば: | |
| 17380 | 10050 | |
| 17381 | ||
| 10051 | srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); | |
| 17382 | X<sqrt> X<root> X<square root> | |
| 17383 | 10052 | |
| 17384 | =item sqrt | |
| 17385 | ||
| 17386 | =for Pod::Functions square root function | |
| 17387 | ||
| 17388 | 10053 | =begin original |
| 17389 | 10054 | |
| 17390 | ||
| 10055 | If you're particularly concerned with this, see the C<Math::TrulyRandom> | |
| 17391 | ||
| 10056 | module in CPAN. | |
| 17392 | loaded the L<C<Math::Complex>|Math::Complex> module. | |
| 17393 | 10057 | |
| 17394 | 10058 | =end original |
| 17395 | 10059 | |
| 17396 | ||
| 10060 | 特にこのようなことに関心がある場合は、 | |
| 17397 | ||
| 10061 | CPAN の C<Math::TrulyRandom> モジュールを参照して下さい。 | |
| 17398 | L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は | |
| 17399 | 扱えません。 | |
| 17400 | 10062 | |
| 17401 | use Math::Complex; | |
| 17402 | print sqrt(-4); # prints 2i | |
| 17403 | ||
| 17404 | =item srand EXPR | |
| 17405 | X<srand> X<seed> X<randseed> | |
| 17406 | ||
| 17407 | =item srand | |
| 17408 | ||
| 17409 | =for Pod::Functions seed the random number generator | |
| 17410 | ||
| 17411 | 10063 | =begin original |
| 17412 | 10064 | |
| 17413 | ||
| 10065 | Do I<not> call C<srand> multiple times in your program unless you know | |
| 17414 | ||
| 10066 | exactly what you're doing and why you're doing it. The point of the | |
| 10067 | function is to "seed" the C<rand> function so that C<rand> can produce | |
| 10068 | a different sequence each time you run your program. Just do it once at the | |
| 10069 | top of your program, or you I<won't> get random numbers out of C<rand>! | |
| 17415 | 10070 | |
| 17416 | 10071 | =end original |
| 17417 | 10072 | |
| 17418 | ||
| 10073 | 何をしようとしているか、そしてなぜそうするのかを正確に把握していない限り、 | |
| 10074 | C<srand> をプログラム中でI<複数回呼び出してはいけません>。 | |
| 10075 | この関数のポイントは、プログラムを実行するごとに C<rand> 関数が | |
| 10076 | 異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。 | |
| 10077 | 単にプログラムの先頭で一回だけ呼び出してください。 | |
| 10078 | さもなければ C<rand> で乱数を I<得られません>! | |
| 17419 | 10079 | |
| 17420 | 10080 | =begin original |
| 17421 | 10081 | |
| 17422 | ||
| 10082 | Frequently called programs (like CGI scripts) that simply use | |
| 17423 | function so that L<C<rand>|/rand EXPR> can produce a different sequence | |
| 17424 | each time you run your program. When called with a parameter, | |
| 17425 | L<C<srand>|/srand EXPR> uses that for the seed; otherwise it | |
| 17426 | (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, | |
| 17427 | it returns the seed. To signal that your code will work I<only> on Perls | |
| 17428 | of a recent vintage: | |
| 17429 | 10083 | |
| 17430 | 10084 | =end original |
| 17431 | 10085 | |
| 17432 | ||
| 10086 | (CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に | |
| 17433 | 異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を | |
| 17434 | 設定することです。 | |
| 17435 | L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います; | |
| 17436 | さもなければ(だいたい)ランダムに種を選びます。 | |
| 17437 | どちらの場合でも、Perl 5.14 からは種を返します。 | |
| 17438 | 特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします: | |
| 17439 | 10087 | |
| 17440 | | |
| 10088 | time ^ $$ | |
| 17441 | 10089 | |
| 17442 | 10090 | =begin original |
| 17443 | 10091 | |
| 17444 | ||
| 10092 | for a seed can fall prey to the mathematical property that | |
| 17445 | implicitly without a parameter at the first use of the | |
| 17446 | L<C<rand>|/rand EXPR> operator. However, there are a few situations | |
| 17447 | where programs are likely to want to call L<C<srand>|/srand EXPR>. One | |
| 17448 | is for generating predictable results, generally for testing or | |
| 17449 | debugging. There, you use C<srand($seed)>, with the same C<$seed> each | |
| 17450 | time. Another case is that you may want to call L<C<srand>|/srand EXPR> | |
| 17451 | after a L<C<fork>|/fork> to avoid child processes sharing the same seed | |
| 17452 | value as the parent (and consequently each other). | |
| 17453 | 10093 | |
| 17454 | 10094 | =end original |
| 17455 | 10095 | |
| 17456 | ||
| 10096 | を種として使うと、3 回に 1 回は以下の数学特性 | |
| 17457 | L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。 | |
| 17458 | しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を | |
| 17459 | 呼び出したいであろう状況がいくつかあります。 | |
| 17460 | 一つはテストやデバッグのために予測可能な結果を生成するためです。 | |
| 17461 | この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。 | |
| 17462 | もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を | |
| 17463 | 共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を | |
| 17464 | 呼び出したいかもしれません。 | |
| 17465 | 10097 | |
| 17466 | ||
| 10098 | a^b == (a+1)^(b+1) | |
| 17467 | 10099 | |
| 17468 | Do B<not> call C<srand()> (i.e., without an argument) more than once per | |
| 17469 | process. The internal state of the random number generator should | |
| 17470 | contain more entropy than can be provided by any seed, so calling | |
| 17471 | L<C<srand>|/srand EXPR> again actually I<loses> randomness. | |
| 17472 | ||
| 17473 | =end original | |
| 17474 | ||
| 17475 | L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回 | |
| 17476 | 呼び出しては B<いけません>。 | |
| 17477 | 乱数生成器の内部状態はどのような種によって提供されるものよりも | |
| 17478 | 高いエントロピーを持っているので、C<srand()> を再び呼び出すと | |
| 17479 | ランダム性が I<失われます>。 | |
| 17480 | ||
| 17481 | 10100 | =begin original |
| 17482 | 10101 | |
| 17483 | ||
| 10102 | one-third of the time. So don't do that. | |
| 17484 | silently | |
| 17485 | truncate decimal numbers. This means C<srand(42)> will usually | |
| 17486 | produce the same results as C<srand(42.1)>. To be safe, always pass | |
| 17487 | L<C<srand>|/srand EXPR> an integer. | |
| 17488 | 10103 | |
| 17489 | 10104 | =end original |
| 17490 | 10105 | |
| 17491 | ||
| 10106 | の餌食になります。 | |
| 17492 | ||
| 10107 | 従ってこのようなことはしてはいけません。 | |
| 17493 | これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。 | |
| 17494 | 安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。 | |
| 17495 | 10108 | |
| 17496 | =begin original | |
| 17497 | ||
| 17498 | A typical use of the returned seed is for a test program which has too many | |
| 17499 | combinations to test comprehensively in the time available to it each run. It | |
| 17500 | can test a random subset each time, and should there be a failure, log the seed | |
| 17501 | used for that run so that it can later be used to reproduce the same results. | |
| 17502 | ||
| 17503 | =end original | |
| 17504 | ||
| 17505 | 返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に | |
| 17506 | 行うには組み合わせが多すぎるテストプログラム用です。 | |
| 17507 | 毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った | |
| 17508 | 種をログに出力することで、後で同じ結果を再現するために使えます。 | |
| 17509 | ||
| 17510 | =begin original | |
| 17511 | ||
| 17512 | B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely | |
| 17513 | on it in security-sensitive situations.> As of this writing, a | |
| 17514 | number of third-party CPAN modules offer random number generators | |
| 17515 | intended by their authors to be cryptographically secure, | |
| 17516 | including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
| 17517 | and L<Math::TrulyRandom>. | |
| 17518 | ||
| 17519 | =end original | |
| 17520 | ||
| 17521 | B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。 | |
| 17522 | セキュリティ的に重要な状況でこれに頼るべきではありません。> | |
| 17523 | これを書いている時点で、いくつかのサードパーティ CPAN モジュールが | |
| 17524 | 作者によって暗号学的に安全であることを目的とした乱数生成器を | |
| 17525 | 提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>, | |
| 17526 | L<Math::TrulyRandom> などです。 | |
| 17527 | ||
| 17528 | 10109 | =item stat FILEHANDLE |
| 17529 | X<stat> X<file, status> X<ctime> | |
| 17530 | 10110 | |
| 17531 | 10111 | =item stat EXPR |
| 17532 | 10112 | |
| 17533 | =item stat DIRHANDLE | |
| 17534 | ||
| 17535 | 10113 | =item stat |
| 17536 | 10114 | |
| 17537 | =for Pod::Functions get a file's status information | |
| 17538 | ||
| 17539 | 10115 | =begin original |
| 17540 | 10116 | |
| 17541 | 10117 | Returns a 13-element list giving the status info for a file, either |
| 17542 | the file opened via FILEHANDLE | |
| 10118 | the file opened via FILEHANDLE, or named by EXPR. If EXPR is omitted, | |
| 17543 | ||
| 10119 | it stats C<$_>. Returns a null list if the stat fails. Typically used | |
| 17544 | ||
| 10120 | as follows: | |
| 17545 | used as follows: | |
| 17546 | 10121 | |
| 17547 | 10122 | =end original |
| 17548 | 10123 | |
| 17549 | FILEHANDLE | |
| 10124 | FILEHANDLE を通じてオープンされているファイルか、 | |
| 17550 | 10125 | EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。 |
| 17551 | EXPR が省略されると、 | |
| 10126 | EXPR が省略されると、 C<$_> が用いられます。 | |
| 17552 | ||
| 10127 | stat に失敗した場合には、空リストを返します。 | |
| 17553 | L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。 | |
| 17554 | 10128 | 普通は、以下のようにして使います: |
| 17555 | 10129 | |
| 17556 | | |
| 10130 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
| 17557 | | |
| 10131 | $atime,$mtime,$ctime,$blksize,$blocks) | |
| 17558 | 10132 | = stat($filename); |
| 17559 | 10133 | |
| 17560 | 10134 | =begin original |
| 17561 | 10135 | |
| 17562 | 10136 | Not all fields are supported on all filesystem types. Here are the |
| 17563 | meaning | |
| 10137 | meaning of the fields: | |
| 17564 | 10138 | |
| 17565 | 10139 | =end original |
| 17566 | 10140 | |
| 17567 | 10141 | 全てのファイルシステムで全てのフィールドに対応しているわけではありません。 |
| 17568 | 10142 | フィールドの意味は以下の通りです。 |
| 17569 | 10143 | |
| 17570 | 10144 | =begin original |
| 17571 | 10145 | |
| 17572 | 10146 | 0 dev device number of filesystem |
| 17573 | 10147 | 1 ino inode number |
| 17574 | 10148 | 2 mode file mode (type and permissions) |
| 17575 | 10149 | 3 nlink number of (hard) links to the file |
| 17576 | 10150 | 4 uid numeric user ID of file's owner |
| 17577 | 10151 | 5 gid numeric group ID of file's owner |
| 17578 | 10152 | 6 rdev the device identifier (special files only) |
| 17579 | 10153 | 7 size total size of file, in bytes |
| 17580 | 10154 | 8 atime last access time in seconds since the epoch |
| 17581 | 10155 | 9 mtime last modify time in seconds since the epoch |
| 17582 | 10 ctime inode change time in seconds since the epoch | |
| 10156 | 10 ctime inode change time (NOT creation time!) in seconds since the epoch | |
| 17583 | 11 blksize preferred | |
| 10157 | 11 blksize preferred block size for file system I/O | |
| 17584 | | |
| 10158 | 12 blocks actual number of blocks allocated | |
| 17585 | 12 blocks actual number of system-specific blocks allocated | |
| 17586 | on disk (often, but not always, 512 bytes each) | |
| 17587 | 10159 | |
| 10160 | (The epoch was at 00:00 January 1, 1970 GMT.) | |
| 10161 | ||
| 17588 | 10162 | =end original |
| 17589 | 10163 | |
| 17590 | 10164 | 0 dev ファイルシステムのデバイス番号 |
| 17591 | 10165 | 1 ino inode 番号 |
| 17592 | 10166 | 2 mode ファイルモード (タイプとパーミッション) |
| 17593 | 10167 | 3 nlink ファイルへの(ハード)リンクの数 |
| 17594 | 10168 | 4 uid ファイル所有者のユーザー ID の数値 |
| 17595 | 10169 | 5 gid ファイル所有者のグループ ID の数値 |
| 17596 | 10170 | 6 rdev デバイス識別子(特殊ファイルのみ) |
| 17597 | 10171 | 7 size ファイルサイズ(バイト単位) |
| 17598 | 10172 | 8 atime 紀元から、最後にアクセスされた時刻までの秒数 |
| 17599 | 10173 | 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数 |
| 17600 | 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 | |
| 10174 | 10 ctime 紀元から、inode 変更(change)された時刻(作成された時刻ではない!)までの秒数 | |
| 17601 | 11 blksize ファイル | |
| 10175 | 11 blksize ファイルシステム I/O に適したブロックサイズ | |
| 17602 | | |
| 10176 | 12 blocks 実際に割り当てられているブロックの数 | |
| 17603 | 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは | |
| 17604 | ありませんがたいていはそれぞれ 512 バイト)の数 | |
| 17605 | 10177 | |
| 17606 | ||
| 10178 | (紀元は GMT で 1970/01/01 00:00:00) | |
| 17607 | 10179 | |
| 17608 | (The epoch was at 00:00 January 1, 1970 GMT.) | |
| 17609 | ||
| 17610 | =end original | |
| 17611 | ||
| 17612 | (紀元は GMT で 1970/01/01 00:00:00。) | |
| 17613 | ||
| 17614 | 10180 | =begin original |
| 17615 | 10181 | |
| 17616 | ||
| 10182 | If stat is passed the special filehandle consisting of an underline, no | |
| 17617 | ||
| 10183 | stat is done, but the current contents of the stat structure from the | |
| 17618 | ||
| 10184 | last stat or filetest are returned. Example: | |
| 17619 | 10185 | |
| 17620 | 10186 | =end original |
| 17621 | 10187 | |
| 17622 | ||
| 10188 | 下線だけの _ という特別なファイルハンドルを stat に渡すと、 | |
| 17623 | ||
| 10189 | 実際には stat を行なわず、stat 構造体に残っている | |
| 17624 | ||
| 10190 | 前回の stat やファイルテストの情報が返されます。 | |
| 17625 | 特に、これから「作成時刻」を想定することは出来ません; | |
| 17626 | 詳細については L<perlport/"Files and Filesystems"> を参照してください。 | |
| 17627 | ||
| 17628 | =begin original | |
| 17629 | ||
| 17630 | If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle | |
| 17631 | consisting of an underline, no stat is done, but the current contents of | |
| 17632 | the stat structure from the last L<C<stat>|/stat FILEHANDLE>, | |
| 17633 | L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example: | |
| 17634 | ||
| 17635 | =end original | |
| 17636 | ||
| 17637 | 下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に | |
| 17638 | 渡すと、実際には stat を行なわず、stat 構造体に残っている | |
| 17639 | 前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や | |
| 17640 | ファイルテストの情報が返されます。 | |
| 17641 | 10191 | 例: |
| 17642 | 10192 | |
| 17643 | 10193 | if (-x $file && (($d) = stat(_)) && $d < 0) { |
| 17644 | ||
| 10194 | print "$file is executable NFS file\n"; | |
| 17645 | 10195 | } |
| 17646 | 10196 | |
| 17647 | 10197 | =begin original |
| 17648 | 10198 | |
| 17649 | 10199 | (This works on machines only for which the device number is negative |
| 17650 | 10200 | under NFS.) |
| 17651 | 10201 | |
| 17652 | 10202 | =end original |
| 17653 | 10203 | |
| 17654 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
| 10204 | (これは、NFS のもとでデバイス番号が負になるマシンで | |
| 10205 | のみ動作します。) | |
| 17655 | 10206 | |
| 17656 | 10207 | =begin original |
| 17657 | 10208 | |
| 17658 | On some platforms inode numbers are of a type larger than perl knows how | |
| 17659 | to handle as integer numerical values. If necessary, an inode number will | |
| 17660 | be returned as a decimal string in order to preserve the entire value. | |
| 17661 | If used in a numeric context, this will be converted to a floating-point | |
| 17662 | numerical value, with rounding, a fate that is best avoided. Therefore, | |
| 17663 | you should prefer to compare inode numbers using C<eq> rather than C<==>. | |
| 17664 | C<eq> will work fine on inode numbers that are represented numerically, | |
| 17665 | as well as those represented as strings. | |
| 17666 | ||
| 17667 | =end original | |
| 17668 | ||
| 17669 | 一部のプラットフォームでは、inode 番号は perl が整数値として | |
| 17670 | 扱い方を知っているものよりも大きい型になっています。 | |
| 17671 | もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として | |
| 17672 | 返されます。 | |
| 17673 | 数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、 | |
| 17674 | できるだけ避けるべき結果になります。 | |
| 17675 | 従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。 | |
| 17676 | C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても | |
| 17677 | うまく動作します。 | |
| 17678 | ||
| 17679 | =begin original | |
| 17680 | ||
| 17681 | 10209 | Because the mode contains both the file type and its permissions, you |
| 17682 | should mask off the file type portion and (s)printf using a C<"%o"> | |
| 10210 | should mask off the file type portion and (s)printf using a C<"%o"> | |
| 17683 | 10211 | if you want to see the real permissions. |
| 17684 | 10212 | |
| 17685 | 10213 | =end original |
| 17686 | 10214 | |
| 17687 | 10215 | モードにはファイルタイプとその権限の両方が含まれているので、 |
| 17688 | 10216 | 本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで |
| 17689 | 10217 | ファイルタイプをマスクするべきです。 |
| 17690 | 10218 | |
| 17691 | | |
| 10219 | $mode = (stat($filename))[2]; | |
| 17692 | 10220 | printf "Permissions are %04o\n", $mode & 07777; |
| 17693 | 10221 | |
| 17694 | 10222 | =begin original |
| 17695 | 10223 | |
| 17696 | In scalar context, | |
| 10224 | In scalar context, C<stat> returns a boolean value indicating success | |
| 17697 | indicating success | |
| 17698 | 10225 | or failure, and, if successful, sets the information associated with |
| 17699 | 10226 | the special filehandle C<_>. |
| 17700 | 10227 | |
| 17701 | 10228 | =end original |
| 17702 | 10229 | |
| 17703 | スカラコンテキストでは、 | |
| 10230 | スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、 | |
| 17704 | ||
| 10231 | 成功した場合は、特別なファイルハンドル C<_> に結び付けられた | |
| 17705 | 10232 | 情報をセットします。 |
| 17706 | 10233 | |
| 17707 | 10234 | =begin original |
| 17708 | 10235 | |
| 17709 | The | |
| 10236 | The File::stat module provides a convenient, by-name access mechanism: | |
| 17710 | 10237 | |
| 17711 | 10238 | =end original |
| 17712 | 10239 | |
| 17713 | ||
| 10240 | File::stat モジュールは、便利な名前によるアクセス機構を提供します。 | |
| 17714 | 10241 | |
| 17715 | 10242 | use File::stat; |
| 17716 | | |
| 10243 | $sb = stat($filename); | |
| 17717 | printf "File is %s, size is %s, perm %04o, mtime %s\n", | |
| 10244 | printf "File is %s, size is %s, perm %04o, mtime %s\n", | |
| 17718 | ||
| 10245 | $filename, $sb->size, $sb->mode & 07777, | |
| 17719 | ||
| 10246 | scalar localtime $sb->mtime; | |
| 17720 | 10247 | |
| 17721 | 10248 | =begin original |
| 17722 | 10249 | |
| 17723 | 10250 | You can import symbolic mode constants (C<S_IF*>) and functions |
| 17724 | (C<S_IS*>) from the | |
| 10251 | (C<S_IS*>) from the Fcntl module: | |
| 17725 | 10252 | |
| 17726 | 10253 | =end original |
| 17727 | 10254 | |
| 17728 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を | |
| 10255 | モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから | |
| 17729 | 10256 | インポートできます。 |
| 17730 | 10257 | |
| 17731 | 10258 | use Fcntl ':mode'; |
| 17732 | 10259 | |
| 17733 | | |
| 10260 | $mode = (stat($filename))[2]; | |
| 17734 | 10261 | |
| 17735 | | |
| 10262 | $user_rwx = ($mode & S_IRWXU) >> 6; | |
| 17736 | | |
| 10263 | $group_read = ($mode & S_IRGRP) >> 3; | |
| 17737 | | |
| 10264 | $other_execute = $mode & S_IXOTH; | |
| 17738 | 10265 | |
| 17739 | printf "Permissions are %04o\n", S_IMODE($mode), "\n"; | |
| 10266 | printf "Permissions are %04o\n", S_ISMODE($mode), "\n"; | |
| 17740 | 10267 | |
| 17741 | | |
| 10268 | $is_setuid = $mode & S_ISUID; | |
| 17742 | | |
| 10269 | $is_setgid = S_ISDIR($mode); | |
| 17743 | 10270 | |
| 17744 | 10271 | =begin original |
| 17745 | 10272 | |
| 17746 | 10273 | You could write the last two using the C<-u> and C<-d> operators. |
| 17747 | ||
| 10274 | The commonly available S_IF* constants are | |
| 17748 | 10275 | |
| 17749 | 10276 | =end original |
| 17750 | 10277 | |
| 17751 | 10278 | 最後の二つは C<-u> と C<-d> 演算子を使っても書けます。 |
| 17752 | 一般に利用可能な | |
| 10279 | 一般に利用可能な S_IF* 定数は以下のものです。 | |
| 17753 | 10280 | |
| 17754 | 10281 | # Permissions: read, write, execute, for user, group, others. |
| 17755 | 10282 | |
| 17756 | 10283 | S_IRWXU S_IRUSR S_IWUSR S_IXUSR |
| 17757 | 10284 | S_IRWXG S_IRGRP S_IWGRP S_IXGRP |
| 17758 | 10285 | S_IRWXO S_IROTH S_IWOTH S_IXOTH |
| 17759 | 10286 | |
| 17760 | # Setuid/Setgid/Stickiness | |
| 10287 | # Setuid/Setgid/Stickiness. | |
| 17761 | # Note that the exact meaning of these is system-dependent. | |
| 17762 | 10288 | |
| 17763 | 10289 | S_ISUID S_ISGID S_ISVTX S_ISTXT |
| 17764 | 10290 | |
| 17765 | # File types. Not | |
| 10291 | # File types. Not necessarily all are available on your system. | |
| 17766 | # your system. | |
| 17767 | 10292 | |
| 17768 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_I | |
| 10293 | S_IFREG S_IFDIR S_IFLNK S_IFBLK S_ISCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT | |
| 17769 | S_IFIFO S_IFSOCK S_IFWHT S_ENFMT | |
| 17770 | 10294 | |
| 17771 | # The following are compatibility aliases for S_IRUSR, | |
| 10295 | # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR. | |
| 17772 | # S_IWUSR, and S_IXUSR. | |
| 17773 | 10296 | |
| 17774 | 10297 | S_IREAD S_IWRITE S_IEXEC |
| 17775 | 10298 | |
| 17776 | 10299 | =begin original |
| 17777 | 10300 | |
| 17778 | and the | |
| 10301 | and the S_IF* functions are | |
| 17779 | 10302 | |
| 17780 | 10303 | =end original |
| 17781 | 10304 | |
| 17782 | 一般に利用可能な | |
| 10305 | 一般に利用可能な S_IF* 関数は以下のものです。 | |
| 17783 | 10306 | |
| 17784 | S_IMODE($mode) | |
| 10307 | S_IFMODE($mode) the part of $mode containing the permission bits | |
| 17785 | ||
| 10308 | and the setuid/setgid/sticky bits | |
| 17786 | 10309 | |
| 17787 | S_IFMT($mode) | |
| 10310 | S_IFMT($mode) the part of $mode containing the file type | |
| 17788 | ||
| 10311 | which can be bit-anded with e.g. S_IFREG | |
| 17789 | | |
| 10312 | or with the following functions | |
| 17790 | 10313 | |
| 17791 | # The operators -f, -d, -l, -b, -c, -p, and - | |
| 10314 | # The operators -f, -d, -l, -b, -c, -p, and -s. | |
| 17792 | 10315 | |
| 17793 | 10316 | S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) |
| 17794 | 10317 | S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) |
| 17795 | 10318 | |
| 17796 | 10319 | # No direct -X operator counterpart, but for the first one |
| 17797 | 10320 | # the -g operator is often equivalent. The ENFMT stands for |
| 17798 | 10321 | # record flocking enforcement, a platform-dependent feature. |
| 17799 | 10322 | |
| 17800 | 10323 | S_ISENFMT($mode) S_ISWHT($mode) |
| 17801 | 10324 | |
| 17802 | 10325 | =begin original |
| 17803 | 10326 | |
| 17804 | See your native | |
| 10327 | See your native chmod(2) and stat(2) documentation for more details | |
| 17805 | about the | |
| 10328 | about the S_* constants. | |
| 17806 | instead of the target file behind the link, use the | |
| 17807 | L<C<lstat>|/lstat FILEHANDLE> function. | |
| 17808 | 10329 | |
| 17809 | 10330 | =end original |
| 17810 | 10331 | |
| 17811 | ||
| 10332 | S_* 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の | |
| 17812 | ドキュメントを参照して | |
| 10333 | ドキュメントを参照して下さい。 | |
| 17813 | リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を | |
| 17814 | 得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。 | |
| 17815 | 10334 | |
| 17816 | =begin original | |
| 17817 | ||
| 17818 | Portability issues: L<perlport/stat>. | |
| 17819 | ||
| 17820 | =end original | |
| 17821 | ||
| 17822 | 移植性の問題: L<perlport/stat>。 | |
| 17823 | ||
| 17824 | =item state VARLIST | |
| 17825 | X<state> | |
| 17826 | ||
| 17827 | =item state TYPE VARLIST | |
| 17828 | ||
| 17829 | =item state VARLIST : ATTRS | |
| 17830 | ||
| 17831 | =item state TYPE VARLIST : ATTRS | |
| 17832 | ||
| 17833 | =for Pod::Functions +state declare and assign a persistent lexical variable | |
| 17834 | ||
| 17835 | =begin original | |
| 17836 | ||
| 17837 | L<C<state>|/state VARLIST> declares a lexically scoped variable, just | |
| 17838 | like L<C<my>|/my VARLIST>. | |
| 17839 | However, those variables will never be reinitialized, contrary to | |
| 17840 | lexical variables that are reinitialized each time their enclosing block | |
| 17841 | is entered. | |
| 17842 | See L<perlsub/"Persistent Private Variables"> for details. | |
| 17843 | ||
| 17844 | =end original | |
| 17845 | ||
| 17846 | L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、 | |
| 17847 | レキシカルなスコープの変数を宣言します。 | |
| 17848 | しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、 | |
| 17849 | この変数は決して再初期化されません。 | |
| 17850 | 詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。 | |
| 17851 | ||
| 17852 | =begin original | |
| 17853 | ||
| 17854 | If more than one variable is listed, the list must be placed in | |
| 17855 | parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be | |
| 17856 | used as a | |
| 17857 | dummy placeholder. However, since initialization of state variables in | |
| 17858 | such lists is currently not possible this would serve no purpose. | |
| 17859 | ||
| 17860 | =end original | |
| 17861 | ||
| 17862 | 複数の変数を指定する場合、かっこで囲まなければなりません。 | |
| 17863 | かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの | |
| 17864 | プレースホルダとして使えます。 | |
| 17865 | しかし、そのようなリストでの state 変数の初期化は現在のところできないので、 | |
| 17866 | これは無意味です。 | |
| 17867 | ||
| 17868 | =begin original | |
| 17869 | ||
| 17870 | L<C<state>|/state VARLIST> is available only if the | |
| 17871 | L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is | |
| 17872 | prefixed with C<CORE::>. The | |
| 17873 | L<C<"state"> feature|feature/The 'state' feature> is enabled | |
| 17874 | automatically with a C<use v5.10> (or higher) declaration in the current | |
| 17875 | scope. | |
| 17876 | ||
| 17877 | =end original | |
| 17878 | ||
| 17879 | L<C<state>|/state VARLIST> は | |
| 17880 | L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を | |
| 17881 | 前置した場合にのみ利用可能です。 | |
| 17882 | L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで | |
| 17883 | C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。 | |
| 17884 | ||
| 17885 | 10335 | =item study SCALAR |
| 17886 | X<study> | |
| 17887 | 10336 | |
| 17888 | 10337 | =item study |
| 17889 | 10338 | |
| 17890 | =for Pod::Functions no-op, formerly optimized input data for repeated searches | |
| 17891 | ||
| 17892 | 10339 | =begin original |
| 17893 | 10340 | |
| 17894 | ||
| 10341 | Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of | |
| 10342 | doing many pattern matches on the string before it is next modified. | |
| 10343 | This may or may not save time, depending on the nature and number of | |
| 10344 | patterns you are searching on, and on the distribution of character | |
| 10345 | frequencies in the string to be searched--you probably want to compare | |
| 10346 | run times with and without it to see which runs faster. Those loops | |
| 10347 | which scan for many short constant strings (including the constant | |
| 10348 | parts of more complex patterns) will benefit most. You may have only | |
| 10349 | one C<study> active at a time--if you study a different scalar the first | |
| 10350 | is "unstudied". (The way C<study> works is this: a linked list of every | |
| 10351 | character in the string to be searched is made, so we know, for | |
| 10352 | example, where all the C<'k'> characters are. From each search string, | |
| 10353 | the rarest character is selected, based on some static frequency tables | |
| 10354 | constructed from some C programs and English text. Only those places | |
| 10355 | that contain this "rarest" character are examined.) | |
| 17895 | 10356 | |
| 17896 | 10357 | =end original |
| 17897 | 10358 | |
| 17898 | ||
| 10359 | 次に変更される前に、何回も文字列に対するパターンマッチを | |
| 17899 | ||
| 10360 | 行なうアプリケーションで、 | |
| 10361 | そのような文字列 SCALAR(省略時には C<$_>) を予め学習しておきます。 | |
| 10362 | これは、検索のために、どのようなパターンを何回使うかによって、 | |
| 10363 | また、検索される文字列内の文字頻度の分布によって、 | |
| 10364 | 時間を節約することになるかもしれませんし、逆に浪費する | |
| 10365 | ことになるかもしれません。 | |
| 10366 | 予習をした場合と、しない場合の実行時間を比較して、 | |
| 10367 | どちらが速いか調べることが、必要でしょう。 | |
| 10368 | 短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん | |
| 10369 | 検索するループで、もっとも効果があるでしょう。 | |
| 10370 | 同時には、一つの C<study>だけが有効です。 | |
| 10371 | 別のスカラを study した場合には、以前に学習した内容は | |
| 10372 | 「忘却」されてしまいます。 | |
| 10373 | (この C<study> の仕組みは、まず、検索される文字列内の | |
| 10374 | すべての文字のリンクされたリストが作られ、たとえば、 | |
| 10375 | すべての C<'k'> がどこにあるかがわかるようになります。 | |
| 10376 | 各々の検索文字列から、C プログラムや英語のテキストから作られた | |
| 10377 | 頻度の統計情報に基づいて、もっとも珍しい文字が選ばれます。 | |
| 10378 | この「珍しい」文字を含む場所だけが調べられるのです。) | |
| 17900 | 10379 | |
| 17901 | 10380 | =begin original |
| 17902 | 10381 | |
| 17903 | ||
| 10382 | For example, here is a loop that inserts index producing entries | |
| 17904 | ||
| 10383 | before any line containing a certain pattern: | |
| 17905 | matching a pattern, the rarest character from the pattern would be looked up in | |
| 17906 | this index. Rarity was based on some static frequency tables constructed from | |
| 17907 | some C programs and English text. | |
| 17908 | 10384 | |
| 17909 | 10385 | =end original |
| 17910 | 10386 | |
| 17911 | ||
| 10387 | たとえば、特定のパターンを含む行の前にインデックスを | |
| 17912 | ||
| 10388 | 付けるエントリを入れる例を示します。 | |
| 17913 | 現れた全ての文字の転置インデックスを作ります。 | |
| 17914 | パターンにマッチングしたとき、 | |
| 17915 | パターン中の最も頻度の少ない文字がこのインデックスから探されます。 | |
| 17916 | 頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを | |
| 17917 | 基にしています。 | |
| 17918 | 10389 | |
| 17919 | ||
| 10390 | while (<>) { | |
| 17920 | ||
| 10391 | study; | |
| 10392 | print ".IX foo\n" if /\bfoo\b/; | |
| 10393 | print ".IX bar\n" if /\bbar\b/; | |
| 10394 | print ".IX blurfl\n" if /\bblurfl\b/; | |
| 10395 | # ... | |
| 10396 | print; | |
| 10397 | } | |
| 17921 | 10398 | |
| 17922 | =item sub NAME (PROTO) BLOCK | |
| 17923 | ||
| 17924 | =item sub NAME : ATTRS BLOCK | |
| 17925 | ||
| 17926 | =item sub NAME (PROTO) : ATTRS BLOCK | |
| 17927 | ||
| 17928 | =for Pod::Functions declare a subroutine, possibly anonymously | |
| 17929 | ||
| 17930 | 10399 | =begin original |
| 17931 | 10400 | |
| 17932 | ||
| 10401 | In searching for C</\bfoo\b/>, only those locations in C<$_> that contain C<f> | |
| 17933 | ||
| 10402 | will be looked at, because C<f> is rarer than C<o>. In general, this is | |
| 17934 | ||
| 10403 | a big win except in pathological cases. The only question is whether | |
| 17935 | ||
| 10404 | it saves you more time than it took to build the linked list in the | |
| 10405 | first place. | |
| 17936 | 10406 | |
| 17937 | 10407 | =end original |
| 17938 | 10408 | |
| 17939 | ||
| 10409 | C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> で C<f> を | |
| 17940 | ||
| 10410 | 含む場所だけが探されます。 | |
| 17941 | ||
| 10411 | 一般に、病的な場合を除いて、かなりの結果が得られます。 | |
| 17942 | ||
| 10412 | 唯一の問題は、節約できる時間が、最初にリンクリストを作る | |
| 17943 | ||
| 10413 | 時間よりも多いかどうかです、 | |
| 17944 | 10414 | |
| 17945 | 10415 | =begin original |
| 17946 | 10416 | |
| 17947 | ||
| 10417 | Note that if you have to look for strings that you don't know till | |
| 17948 | r | |
| 10418 | runtime, you can build an entire loop as a string and C<eval> that to | |
| 17949 | ||
| 10419 | avoid recompiling all your patterns all the time. Together with | |
| 10420 | undefining C<$/> to input entire files as one record, this can be very | |
| 10421 | fast, often faster than specialized programs like fgrep(1). The following | |
| 10422 | scans a list of files (C<@files>) for a list of words (C<@words>), and prints | |
| 10423 | out the names of those files that contain a match: | |
| 17950 | 10424 | |
| 17951 | 10425 | =end original |
| 17952 | 10426 | |
| 17953 | ||
| 10427 | 実行時まで、探そうとする文字列がわからないときには、 | |
| 17954 | ||
| 10428 | ループ全体を文字列として組み立てて、C<eval> すれば、 | |
| 17955 | ||
| 10429 | いつも、すべてのパターンを再コンパイルするという事態は | |
| 10430 | 避けられます。 | |
| 10431 | ファイル全体を一つのレコードとして入力するために、 | |
| 10432 | C<$/> を未定義にすれば、かなり速くなり、 | |
| 10433 | 多くの場合 fgrep(1) のような専用のプログラムより速くなります。 | |
| 10434 | 以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を | |
| 10435 | 探して、マッチするものがあったファイル名を出力します。 | |
| 17956 | 10436 | |
| 17957 | =i | |
| 10437 | $search = 'while (<>) { study;'; | |
| 17958 | ||
| 10438 | foreach $word (@words) { | |
| 10439 | $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n"; | |
| 10440 | } | |
| 10441 | $search .= "}"; | |
| 10442 | @ARGV = @files; | |
| 10443 | undef $/; | |
| 10444 | eval $search; # this screams | |
| 10445 | $/ = "\n"; # put back to normal input delimiter | |
| 10446 | foreach $file (sort keys(%seen)) { | |
| 10447 | print $file, "\n"; | |
| 10448 | } | |
| 17959 | 10449 | |
| 17960 | = | |
| 10450 | =item sub BLOCK | |
| 17961 | 10451 | |
| 17962 | = | |
| 10452 | =item sub NAME | |
| 17963 | 10453 | |
| 17964 | ||
| 10454 | =item sub NAME BLOCK | |
| 17965 | L<C<undef>|/undef EXPR> outside of a subroutine. | |
| 17966 | 10455 | |
| 17967 | =end original | |
| 17968 | ||
| 17969 | 現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では | |
| 17970 | L<C<undef>|/undef EXPR>。 | |
| 17971 | ||
| 17972 | 10456 | =begin original |
| 17973 | 10457 | |
| 17974 | Th | |
| 10458 | This is subroutine definition, not a real function I<per se>. With just a | |
| 17975 | ||
| 10459 | NAME (and possibly prototypes or attributes), it's just a forward declaration. | |
| 10460 | Without a NAME, it's an anonymous function declaration, and does actually | |
| 10461 | return a value: the CODE ref of the closure you just created. See L<perlsub> | |
| 10462 | and L<perlref> for details. | |
| 17976 | 10463 | |
| 17977 | 10464 | =end original |
| 17978 | 10465 | |
| 17979 | ||
| 10466 | これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。 | |
| 17980 | ||
| 10467 | NAME (とプロトタイプや属性) のみの場合は、単なる前方定義です。 | |
| 10468 | NAME なしの場合は、無名関数定義であり、実際には値(作成したブロックの | |
| 10469 | コードリファレンス)を返します。 | |
| 10470 | 詳しくは L<perlsub> と L<perlref> を参照して下さい。 | |
| 17981 | 10471 | |
| 17982 | =begin original | |
| 17983 | ||
| 17984 | This token is only available under C<use v5.16> or the | |
| 17985 | L<C<"current_sub"> feature|feature/The 'current_sub' feature>. | |
| 17986 | See L<feature>. | |
| 17987 | ||
| 17988 | =end original | |
| 17989 | ||
| 17990 | このトークンは C<use v5.16> または | |
| 17991 | L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ | |
| 17992 | 利用可能です。 | |
| 17993 | L<feature> を参照してください。 | |
| 17994 | ||
| 17995 | 10472 | =item substr EXPR,OFFSET,LENGTH,REPLACEMENT |
| 17996 | X<substr> X<substring> X<mid> X<left> X<right> | |
| 17997 | 10473 | |
| 17998 | 10474 | =item substr EXPR,OFFSET,LENGTH |
| 17999 | 10475 | |
| 18000 | 10476 | =item substr EXPR,OFFSET |
| 18001 | 10477 | |
| 18002 | =for Pod::Functions get or alter a portion of a string | |
| 18003 | ||
| 18004 | 10478 | =begin original |
| 18005 | 10479 | |
| 18006 | 10480 | Extracts a substring out of EXPR and returns it. First character is at |
| 18007 | offset | |
| 10481 | offset C<0>, or whatever you've set C<$[> to (but don't do that). | |
| 18008 | ||
| 10482 | If OFFSET is negative (or more precisely, less than C<$[>), starts | |
| 18009 | ||
| 10483 | that far from the end of the string. If LENGTH is omitted, returns | |
| 10484 | everything to the end of the string. If LENGTH is negative, leaves that | |
| 18010 | 10485 | many characters off the end of the string. |
| 18011 | 10486 | |
| 18012 | 10487 | =end original |
| 18013 | 10488 | |
| 18014 | 10489 | EXPR から、部分文字列を取り出して返します。 |
| 18015 | 最初の文字がオフセット 0 | |
| 10490 | 最初の文字がオフセット C<0> もしくは、C<$[> に設定した値 | |
| 18016 | ||
| 10491 | (しかしこれを使ってはいけません)となります。 | |
| 10492 | OFFSET に負の値(より厳密には、C<$[>より小さい値)を設定すると、 | |
| 10493 | EXPR の終わりからのオフセットとなります。 | |
| 18017 | 10494 | LENGTH を省略すると、EXPR の最後まですべてが返されます。 |
| 18018 | 10495 | LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。 |
| 18019 | 10496 | |
| 18020 | my $s = "The black cat climbed the green tree"; | |
| 18021 | my $color = substr $s, 4, 5; # black | |
| 18022 | my $middle = substr $s, 4, -11; # black cat climbed the | |
| 18023 | my $end = substr $s, 14; # climbed the green tree | |
| 18024 | my $tail = substr $s, -4; # tree | |
| 18025 | my $z = substr $s, -4, 2; # tr | |
| 18026 | ||
| 18027 | 10497 | =begin original |
| 18028 | 10498 | |
| 18029 | You can use the | |
| 10499 | You can use the substr() function as an lvalue, in which case EXPR | |
| 18030 | function as an lvalue, in which case EXPR | |
| 18031 | 10500 | must itself be an lvalue. If you assign something shorter than LENGTH, |
| 18032 | 10501 | the string will shrink, and if you assign something longer than LENGTH, |
| 18033 | 10502 | the string will grow to accommodate it. To keep the string the same |
| 18034 | length | |
| 10503 | length you may need to pad or chop your value using C<sprintf>. | |
| 18035 | L<C<sprintf>|/sprintf FORMAT, LIST>. | |
| 18036 | 10504 | |
| 18037 | 10505 | =end original |
| 18038 | 10506 | |
| 18039 | ||
| 10507 | substr() を左辺値として使用することも可能で、その場合には、 | |
| 18040 | ||
| 10508 | EXPR が自身左辺値でなければなりません。 | |
| 18041 | 10509 | LENGTH より短いものを代入したときには、 |
| 18042 | 10510 | EXPR は短くなり、LENGTH より長いものを代入したときには、 |
| 18043 | 10511 | EXPR はそれに合わせて伸びることになります。 |
| 18044 | EXPR の長さを一定に保つためには、 | |
| 10512 | EXPR の長さを一定に保つためには、C<sprintf> を使って、 | |
| 18045 | ||
| 10513 | 代入する値の長さを調整することが、必要になるかもしれません。 | |
| 18046 | 10514 | |
| 18047 | 10515 | =begin original |
| 18048 | 10516 | |
| 18049 | 10517 | If OFFSET and LENGTH specify a substring that is partly outside the |
| 18050 | 10518 | string, only the part within the string is returned. If the substring |
| 18051 | is beyond either end of the string, | |
| 10519 | is beyond either end of the string, substr() returns the undefined | |
| 18052 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined | |
| 18053 | 10520 | value and produces a warning. When used as an lvalue, specifying a |
| 18054 | substring that is entirely outside the string | |
| 10521 | substring that is entirely outside the string is a fatal error. | |
| 18055 | 10522 | Here's an example showing the behavior for boundary cases: |
| 18056 | 10523 | |
| 18057 | 10524 | =end original |
| 18058 | 10525 | |
| 18059 | 10526 | OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、 |
| 18060 | 10527 | 文字列の内側の部分だけが返されます。 |
| 18061 | 部分文字列が文字列の両端の外側の場合、 | |
| 10528 | 部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、 | |
| 18062 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、 | |
| 18063 | 10529 | 警告が出力されます。 |
| 18064 | 10530 | 左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると |
| 18065 | ||
| 10531 | 致命的エラーになります。 | |
| 18066 | 10532 | 以下は境界条件の振る舞いを示す例です: |
| 18067 | 10533 | |
| 18068 | 10534 | my $name = 'fred'; |
| 18069 | substr($name, 4) = 'dy'; | |
| 10535 | substr($name, 4) = 'dy'; # $name is now 'freddy' | |
| 18070 | my $null = substr $name, 6, 2; | |
| 10536 | my $null = substr $name, 6, 2; # returns '' (no warning) | |
| 18071 | my $oops = substr $name, 7; | |
| 10537 | my $oops = substr $name, 7; # returns undef, with warning | |
| 18072 | substr($name, 7) = 'gap'; | |
| 10538 | substr($name, 7) = 'gap'; # fatal error | |
| 18073 | 10539 | |
| 18074 | 10540 | =begin original |
| 18075 | 10541 | |
| 18076 | An alternative to using | |
| 10542 | An alternative to using substr() as an lvalue is to specify the | |
| 18077 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to | |
| 18078 | specify the | |
| 18079 | 10543 | replacement string as the 4th argument. This allows you to replace |
| 18080 | 10544 | parts of the EXPR and return what was there before in one operation, |
| 18081 | just as you can with | |
| 10545 | just as you can with splice(). | |
| 18082 | L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>. | |
| 18083 | 10546 | |
| 18084 | 10547 | =end original |
| 18085 | 10548 | |
| 18086 | ||
| 10549 | substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の | |
| 18087 | ||
| 10550 | 引数として指定することです。 | |
| 18088 | 10551 | これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、 |
| 18089 | ということを( | |
| 10552 | ということを(splice() と同様) 1 動作で行えます。 | |
| 18090 | 1 動作で行えます。 | |
| 18091 | 10553 | |
| 18092 | my $s = "The black cat climbed the green tree"; | |
| 18093 | my $z = substr $s, 14, 7, "jumped from"; # climbed | |
| 18094 | # $s is now "The black cat jumped from the green tree" | |
| 18095 | ||
| 18096 | =begin original | |
| 18097 | ||
| 18098 | Note that the lvalue returned by the three-argument version of | |
| 18099 | L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as | |
| 18100 | a 'magic bullet'; each time it is assigned to, it remembers which part | |
| 18101 | of the original string is being modified; for example: | |
| 18102 | ||
| 18103 | =end original | |
| 18104 | ||
| 18105 | 3 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された | |
| 18106 | 左辺値は「魔法の弾丸」のように振舞うことに注意してください; | |
| 18107 | これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます; | |
| 18108 | 例えば: | |
| 18109 | ||
| 18110 | my $x = '1234'; | |
| 18111 | for (substr($x,1,2)) { | |
| 18112 | $_ = 'a'; print $x,"\n"; # prints 1a4 | |
| 18113 | $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 | |
| 18114 | $x = '56789'; | |
| 18115 | $_ = 'pq'; print $x,"\n"; # prints 5pq9 | |
| 18116 | } | |
| 18117 | ||
| 18118 | =begin original | |
| 18119 | ||
| 18120 | With negative offsets, it remembers its position from the end of the string | |
| 18121 | when the target string is modified: | |
| 18122 | ||
| 18123 | =end original | |
| 18124 | ||
| 18125 | 負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの | |
| 18126 | 位置を覚えます: | |
| 18127 | ||
| 18128 | my $x = '1234'; | |
| 18129 | for (substr($x, -3, 2)) { | |
| 18130 | $_ = 'a'; print $x,"\n"; # prints 1a4, as above | |
| 18131 | $x = 'abcdefg'; | |
| 18132 | print $_,"\n"; # prints f | |
| 18133 | } | |
| 18134 | ||
| 18135 | =begin original | |
| 18136 | ||
| 18137 | Prior to Perl version 5.10, the result of using an lvalue multiple times was | |
| 18138 | unspecified. Prior to 5.16, the result with negative offsets was | |
| 18139 | unspecified. | |
| 18140 | ||
| 18141 | =end original | |
| 18142 | ||
| 18143 | バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は | |
| 18144 | 未定義でした。 | |
| 18145 | 5.16 より前では、負のオフセットの結果は未定義です。 | |
| 18146 | ||
| 18147 | 10554 | =item symlink OLDFILE,NEWFILE |
| 18148 | X<symlink> X<link> X<symbolic link> X<link, symbolic> | |
| 18149 | 10555 | |
| 18150 | =for Pod::Functions create a symbolic link to a file | |
| 18151 | ||
| 18152 | 10556 | =begin original |
| 18153 | 10557 | |
| 18154 | 10558 | Creates a new filename symbolically linked to the old filename. |
| 18155 | 10559 | Returns C<1> for success, C<0> otherwise. On systems that don't support |
| 18156 | symbolic links, r | |
| 10560 | symbolic links, produces a fatal error at run time. To check for that, | |
| 18157 | 10561 | use eval: |
| 18158 | 10562 | |
| 18159 | 10563 | =end original |
| 18160 | 10564 | |
| 18161 | 10565 | NEWFILE として、OLDFILE へのシンボリックリンクを生成します。 |
| 18162 | 10566 | 成功時には C<1> を返し、失敗時には C<0> を返します。 |
| 18163 | 10567 | シンボリックリンクをサポートしていないシステムでは、 |
| 18164 | ||
| 10568 | 実行時に致命的エラーが発生します。 | |
| 18165 | 10569 | これをチェックするには、eval を使用します: |
| 18166 | 10570 | |
| 18167 | | |
| 10571 | $symlink_exists = eval { symlink("",""); 1 }; | |
| 18168 | 10572 | |
| 18169 | = | |
| 10573 | =item syscall LIST | |
| 18170 | 10574 | |
| 18171 | Portability issues: L<perlport/symlink>. | |
| 18172 | ||
| 18173 | =end original | |
| 18174 | ||
| 18175 | 移植性の問題: L<perlport/symlink>。 | |
| 18176 | ||
| 18177 | =item syscall NUMBER, LIST | |
| 18178 | X<syscall> X<system call> | |
| 18179 | ||
| 18180 | =for Pod::Functions execute an arbitrary system call | |
| 18181 | ||
| 18182 | 10575 | =begin original |
| 18183 | 10576 | |
| 18184 | 10577 | Calls the system call specified as the first element of the list, |
| 18185 | 10578 | passing the remaining elements as arguments to the system call. If |
| 18186 | unimplemented, r | |
| 10579 | unimplemented, produces a fatal error. The arguments are interpreted | |
| 18187 | 10580 | as follows: if a given argument is numeric, the argument is passed as |
| 18188 | 10581 | an int. If not, the pointer to the string value is passed. You are |
| 18189 | 10582 | responsible to make sure a string is pre-extended long enough to |
| 18190 | 10583 | receive any result that might be written into a string. You can't use a |
| 18191 | string literal (or other read-only string) as an argument to | |
| 10584 | string literal (or other read-only string) as an argument to C<syscall> | |
| 18192 | ||
| 10585 | because Perl has to assume that any string pointer might be written | |
| 18193 | ||
| 10586 | through. If your | |
| 18194 | 10587 | integer arguments are not literals and have never been interpreted in a |
| 18195 | 10588 | numeric context, you may need to add C<0> to them to force them to look |
| 18196 | like numbers. This emulates the | |
| 10589 | like numbers. This emulates the C<syswrite> function (or vice versa): | |
| 18197 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or | |
| 18198 | vice versa): | |
| 18199 | 10590 | |
| 18200 | 10591 | =end original |
| 18201 | 10592 | |
| 18202 | 10593 | LIST の最初の要素で指定するシステムコールを、残りの要素をその |
| 18203 | 10594 | システムコールの引数として呼び出します。 |
| 18204 | 実装されていない | |
| 10595 | 実装されていないときには、致命的エラーとなります。 | |
| 18205 | 10596 | 引数は、以下のように解釈されます: 引数が数字であれば、int として |
| 18206 | 10597 | 引数を渡します。 |
| 18207 | 10598 | そうでなければ、文字列値へのポインタが渡されます。 |
| 18208 | 10599 | 文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、 |
| 18209 | 10600 | 文字列を予め伸ばしておく必要があります。 |
| 18210 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を | |
| 10601 | 文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の | |
| 18211 | ||
| 10602 | 引数として使うことはできません。 | |
| 18212 | 10603 | Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。 |
| 18213 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
| 10604 | 整数引数が、リテラルでなく、数値コンテキストで評価されたことの | |
| 18214 | ものであれば、数値として解釈されるように、 | |
| 10605 | ないものであれば、数値として解釈されるように、 | |
| 18215 | 10606 | C<0> を足しておく必要があるかもしれません。 |
| 18216 | 以下は | |
| 10607 | 以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。 | |
| 18217 | その逆)をエミュレートします。 | |
| 18218 | 10608 | |
| 18219 | require 'syscall.ph'; | |
| 10609 | require 'syscall.ph'; # may need to run h2ph | |
| 18220 | | |
| 10610 | $s = "hi there\n"; | |
| 18221 | syscall(SYS_write | |
| 10611 | syscall(&SYS_write, fileno(STDOUT), $s, length $s); | |
| 18222 | 10612 | |
| 18223 | 10613 | =begin original |
| 18224 | 10614 | |
| 18225 | Note that Perl supports passing of up to only 14 arguments to your syscall, | |
| 10615 | Note that Perl supports passing of up to only 14 arguments to your system call, | |
| 18226 | which in practice should | |
| 10616 | which in practice should usually suffice. | |
| 18227 | 10617 | |
| 18228 | 10618 | =end original |
| 18229 | 10619 | |
| 18230 | 10620 | Perl は、システムコールに最大 14 個の引数しか渡せませんが、 |
| 18231 | ||
| 10621 | 実用上問題はないでしょう。 | |
| 18232 | 10622 | |
| 18233 | 10623 | =begin original |
| 18234 | 10624 | |
| 18235 | 10625 | Syscall returns whatever value returned by the system call it calls. |
| 18236 | If the system call fails, | |
| 10626 | If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno). | |
| 18237 | ||
| 10627 | Note that some system calls can legitimately return C<-1>. The proper | |
| 18238 | ||
| 10628 | way to handle such calls is to assign C<$!=0;> before the call and | |
| 18239 | ||
| 10629 | check the value of C<$!> if syscall returns C<-1>. | |
| 18240 | check the value of L<C<$!>|perlvar/$!> if | |
| 18241 | L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>. | |
| 18242 | 10630 | |
| 18243 | 10631 | =end original |
| 18244 | 10632 | |
| 18245 | 10633 | syscall は、呼び出したシステムコールが返した値を返します。 |
| 18246 | システムコールが失敗すると、 | |
| 10634 | システムコールが失敗すると、C<syscall> は C<-1> を返し、 | |
| 18247 | ||
| 10635 | C<$!>(errno) を設定します。 | |
| 18248 | システムコールが正常に C<-1> を返す | |
| 10636 | システムコールが正常に C<-1> を返す場合があることに注意してください。 | |
| 18249 | 10637 | このようなシステムコールを正しく扱うには、 |
| 18250 | C<$! | |
| 10638 | C<$!=0;> をシステムコールの前に実行し、 | |
| 18251 | ||
| 10639 | syscall が C<-1> を返した時には C<$!> の値を調べてください。 | |
| 18252 | L<C<$!>|perlvar/$!> の値を調べてください。 | |
| 18253 | 10640 | |
| 18254 | 10641 | =begin original |
| 18255 | 10642 | |
| 18256 | There's a problem with C<syscall(SYS_pipe | |
| 10643 | There's a problem with C<syscall(&SYS_pipe)>: it returns the file | |
| 18257 | number of the read end of the pipe it creates | |
| 10644 | number of the read end of the pipe it creates. There is no way | |
| 18258 | to retrieve the file number of the other end. You can avoid this | |
| 10645 | to retrieve the file number of the other end. You can avoid this | |
| 18259 | problem by using | |
| 10646 | problem by using C<pipe> instead. | |
| 18260 | 10647 | |
| 18261 | 10648 | =end original |
| 18262 | 10649 | |
| 18263 | C<syscall(&SYS_pipe)> には問題があり、 | |
| 10650 | C<syscall(&SYS_pipe)> には問題があり、 | |
| 18264 | ファイル番号を返しますが、 | |
| 10651 | 作ったパイプの、読み出し側のファイル番号を返しますが、 | |
| 18265 | ||
| 10652 | もう一方のファイル番号を得る方法がありません。 | |
| 18266 | 使ってください。 | |
| 10653 | この問題を避けるためには、代わりに C<pipe> を使ってください。 | |
| 18267 | 10654 | |
| 18268 | =begin original | |
| 18269 | ||
| 18270 | Portability issues: L<perlport/syscall>. | |
| 18271 | ||
| 18272 | =end original | |
| 18273 | ||
| 18274 | 移植性の問題: L<perlport/syscall>。 | |
| 18275 | ||
| 18276 | 10655 | =item sysopen FILEHANDLE,FILENAME,MODE |
| 18277 | X<sysopen> | |
| 18278 | 10656 | |
| 18279 | 10657 | =item sysopen FILEHANDLE,FILENAME,MODE,PERMS |
| 18280 | 10658 | |
| 18281 | =for Pod::Functions +5.002 open a file, pipe, or descriptor | |
| 18282 | ||
| 18283 | 10659 | =begin original |
| 18284 | 10660 | |
| 18285 | Opens the file whose filename is given by FILENAME, and associates it | |
| 10661 | Opens the file whose filename is given by FILENAME, and associates it | |
| 18286 | FILEHANDLE. If FILEHANDLE is an expression, its value is used as | |
| 10662 | with FILEHANDLE. If FILEHANDLE is an expression, its value is used as | |
| 18287 | filehandle wanted | |
| 10663 | the name of the real filehandle wanted. This function calls the | |
| 18288 | ||
| 10664 | underlying operating system's C<open> function with the parameters | |
| 18289 | ||
| 10665 | FILENAME, MODE, PERMS. | |
| 18290 | 10666 | |
| 18291 | 10667 | =end original |
| 18292 | 10668 | |
| 18293 | 10669 | FILENAME で与えられたファイル名のファイルをオープンし、 |
| 18294 | 10670 | FILEHANDLE と結び付けます。 |
| 18295 | FILEHANDLE が式の場合、その値は実際 | |
| 10671 | FILEHANDLE が式の場合、その値は実際に求めているファイルハンドルの名前として | |
| 18296 | 扱われます | |
| 10672 | 扱われます。 | |
| 18297 | この関数呼び出しはシステムの | |
| 10673 | この関数呼び出しはシステムの C<open> 関数を FILENAME, MODE, PERMS の | |
| 18298 | 10674 | 引数で呼び出すことを基礎としています。 |
| 18299 | 10675 | |
| 18300 | 10676 | =begin original |
| 18301 | 10677 | |
| 18302 | Returns true on success and L<C<undef>|/undef EXPR> otherwise. | |
| 18303 | ||
| 18304 | =end original | |
| 18305 | ||
| 18306 | 成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。 | |
| 18307 | ||
| 18308 | =begin original | |
| 18309 | ||
| 18310 | 10678 | The possible values and flag bits of the MODE parameter are |
| 18311 | system-dependent; they are available via the standard module | |
| 10679 | system-dependent; they are available via the standard module C<Fcntl>. | |
| 18312 | ||
| 10680 | See the documentation of your operating system's C<open> to see which | |
| 18313 | ||
| 10681 | values and flag bits are available. You may combine several flags | |
| 18314 | which values and flag bits are available. You may combine several flags | |
| 18315 | 10682 | using the C<|>-operator. |
| 18316 | 10683 | |
| 18317 | 10684 | =end original |
| 18318 | 10685 | |
| 18319 | 10686 | MODE パラメータに指定できるフラグビットと値はシステム依存です; |
| 18320 | これは標準モジュール | |
| 10687 | これは標準モジュール C<Fcntl> 経由で利用可能です。 | |
| 18321 | 10688 | どのようなフラグビットと値が利用可能であるかについては、 |
| 18322 | OS の | |
| 10689 | OS の C<open> に関する文書を参照してください。 | |
| 18323 | 10690 | C<|> 演算子を使って複数のフラグを結合することができます。 |
| 18324 | 10691 | |
| 18325 | 10692 | =begin original |
| 18326 | 10693 | |
| 18327 | 10694 | Some of the most common values are C<O_RDONLY> for opening the file in |
| 18328 | 10695 | read-only mode, C<O_WRONLY> for opening the file in write-only mode, |
| 18329 | and C<O_RDWR> for opening the file in read-write mode. | |
| 10696 | and C<O_RDWR> for opening the file in read-write mode, and. | |
| 18330 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> | |
| 18331 | 10697 | |
| 18332 | 10698 | =end original |
| 18333 | 10699 | |
| 18334 | 10700 | もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、 |
| 18335 | 10701 | ファイルを書き込み専用で開く C<O_WRONLY>、 |
| 18336 | 10702 | ファイルを読み書き両用で開く C<O_RDWR> です。 |
| 18337 | X<O_RDONLY> X<O_RDWR> X<O_WRONLY> | |
| 18338 | 10703 | |
| 18339 | 10704 | =begin original |
| 18340 | 10705 | |
| 18341 | 10706 | For historical reasons, some values work on almost every system |
| 18342 | supported by | |
| 10707 | supported by perl: zero means read-only, one means write-only, and two | |
| 18343 | 10708 | means read/write. We know that these values do I<not> work under |
| 18344 | OS/390 and on the Macintosh; you probably don't want to | |
| 10709 | OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to | |
| 18345 | 10710 | use them in new code. |
| 18346 | 10711 | |
| 18347 | 10712 | =end original |
| 18348 | 10713 | |
| 18349 | 歴史的な理由により、 | |
| 10714 | 歴史的な理由により、perl が対応しているほとんどのシステムで | |
| 18350 | あり | |
| 10715 | 使える値があります。 | |
| 18351 | ||
| 10716 | 0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。 | |
| 10717 | OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています; | |
| 18352 | 10718 | 新しく書くコードではこれらは使わないほうがよいでしょう。 |
| 18353 | 10719 | |
| 18354 | 10720 | =begin original |
| 18355 | 10721 | |
| 18356 | If the file named by FILENAME does not exist and the | |
| 10722 | If the file named by FILENAME does not exist and the C<open> call creates | |
| 18357 | L<C<open>|/open FILEHANDLE,EXPR> call creates | |
| 18358 | 10723 | it (typically because MODE includes the C<O_CREAT> flag), then the value of |
| 18359 | 10724 | PERMS specifies the permissions of the newly created file. If you omit |
| 18360 | the PERMS argument to | |
| 10725 | the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>. | |
| 18361 | Perl uses the octal value C<0666>. | |
| 18362 | 10726 | These permission values need to be in octal, and are modified by your |
| 18363 | process's current | |
| 10727 | process's current C<umask>. | |
| 18364 | X<O_CREAT> | |
| 18365 | 10728 | |
| 18366 | 10729 | =end original |
| 18367 | 10730 | |
| 18368 | 10731 | FILENAME という名前のファイルが存在せず、(典型的には MODE が |
| 18369 | C<O_CREAT> フラグを含んでいたために) | |
| 10732 | C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、 | |
| 18370 | L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、 | |
| 18371 | 10733 | PERMS の値は新しく作られたファイルの権限を指定します。 |
| 18372 | ||
| 10734 | C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。 | |
| 18373 | ||
| 10735 | これらの権限は 8 進数である必要があり、プロセスの現在の C<umask> で | |
| 18374 | ||
| 10736 | 修正されます。 | |
| 18375 | L<C<umask>|/umask EXPR> で修正されます。 | |
| 18376 | X<O_CREAT> | |
| 18377 | 10737 | |
| 18378 | 10738 | =begin original |
| 18379 | 10739 | |
| 18380 | 10740 | In many systems the C<O_EXCL> flag is available for opening files in |
| 18381 | 10741 | exclusive mode. This is B<not> locking: exclusiveness means here that |
| 18382 | if the file already exists, | |
| 10742 | if the file already exists, sysopen() fails. The C<O_EXCL> wins | |
| 18383 | ||
| 10743 | C<O_TRUNC>. | |
| 18384 | not work | |
| 18385 | on network filesystems, and has no effect unless the C<O_CREAT> flag | |
| 18386 | is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from | |
| 18387 | being opened if it is a symbolic link. It does not protect against | |
| 18388 | symbolic links in the file's path. | |
| 18389 | X<O_EXCL> | |
| 18390 | 10744 | |
| 18391 | 10745 | =end original |
| 18392 | 10746 | |
| 18393 | 10747 | 多くのシステムではファイルを排他モードで開くために C<O_EXCL> が |
| 18394 | 10748 | 利用可能です。 |
| 18395 | 10749 | これはロック B<ではありません>: 排他性というのは既にファイルが |
| 18396 | 存在していた場合、 | |
| 10750 | 存在していた場合、sysopen() が失敗することを意味します。 | |
| 18397 | ||
| 10751 | C<O_EXCL> は C<O_TRUNC> より優先します。 | |
| 18398 | C<O_EXCL> はネットワークファイルシステムでは動作せず、 | |
| 18399 | またC<O_CREAT> フラグも有効でない限りは効果がありません。 | |
| 18400 | C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は | |
| 18401 | ファイルを開くことを妨げます。 | |
| 18402 | これはファイルパス中のシンボリックリンクは守りません。 | |
| 18403 | X<O_EXCL> | |
| 18404 | 10752 | |
| 18405 | 10753 | =begin original |
| 18406 | 10754 | |
| 18407 | Sometimes you may want to truncate an already-existing file | |
| 10755 | Sometimes you may want to truncate an already-existing file: C<O_TRUNC>. | |
| 18408 | can be done using the C<O_TRUNC> flag. The behavior of | |
| 18409 | C<O_TRUNC> with C<O_RDONLY> is undefined. | |
| 18410 | X<O_TRUNC> | |
| 18411 | 10756 | |
| 18412 | 10757 | =end original |
| 18413 | 10758 | |
| 18414 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません | |
| 10759 | 既に存在しているファイルを切り詰めたい場合もあるかもしれません: C<O_TRUNC> | |
| 18415 | これは C<O_TRUNC> フラグを使うことで行えます。 | |
| 18416 | C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。 | |
| 18417 | X<O_TRUNC> | |
| 18418 | 10760 | |
| 18419 | 10761 | =begin original |
| 18420 | 10762 | |
| 18421 | You should seldom if ever use C<0644> as argument to | |
| 10763 | You should seldom if ever use C<0644> as argument to C<sysopen>, because | |
| 18422 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because | |
| 18423 | 10764 | that takes away the user's option to have a more permissive umask. |
| 18424 | Better to omit it. See | |
| 10765 | Better to omit it. See the perlfunc(1) entry on C<umask> for more | |
| 10766 | on this. | |
| 18425 | 10767 | |
| 18426 | 10768 | =end original |
| 18427 | 10769 | |
| 18428 | めったなことでは | |
| 10770 | めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう: | |
| 18429 | C<0644> を指定するべきではないでしょう: | |
| 18430 | 10771 | ユーザーがより寛大な umask を指定する選択肢を奪うからです。 |
| 18431 | 10772 | 省略した方がいいです。 |
| 18432 | これに関するさらなる情報については | |
| 10773 | これに関するさらなる情報については perlfunc(1) の C<umask> を | |
| 18433 | 10774 | 参照してください。 |
| 18434 | 10775 | |
| 18435 | 10776 | =begin original |
| 18436 | 10777 | |
| 18437 | Note that | |
| 10778 | Note that C<sysopen> depends on the fdopen() C library function. | |
| 18438 | ||
| 10779 | On many UNIX systems, fdopen() is known to fail when file descriptors | |
| 18439 | ||
| 10780 | exceed a certain value, typically 255. If you need more file | |
| 18440 | ||
| 10781 | descriptors than that, consider rebuilding Perl to use the C<sfio> | |
| 18441 | y | |
| 10782 | library, or perhaps using the POSIX::open() function. | |
| 18442 | L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later, | |
| 18443 | PerlIO is (most often) the default. | |
| 18444 | 10783 | |
| 18445 | 10784 | =end original |
| 18446 | 10785 | |
| 18447 | ||
| 10786 | C<sysopen> は C の fdopen() ライブラリ関数に依存していることに注意してください。 | |
| 18448 | ||
| 10787 | 多くの UNIX システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると | |
| 18449 | ||
| 10788 | 失敗することが知られています。 | |
| 18450 | 多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を | |
| 18451 | 超えると失敗することが知られています。 | |
| 18452 | 10789 | これより多くのファイル記述子が必要な場合は、 |
| 18453 | ||
| 10790 | Perl を C<sfio> ライブラリを使って再ビルドするか、 | |
| 18454 | Pe | |
| 10791 | POSIX::open() 関数を使うことを健闘してください。 | |
| 18455 | 10792 | |
| 18456 | 10793 | =begin original |
| 18457 | 10794 | |
| 18458 | 10795 | See L<perlopentut> for a kinder, gentler explanation of opening files. |
| 18459 | 10796 | |
| 18460 | 10797 | =end original |
| 18461 | 10798 | |
| 18462 | ファイル | |
| 10799 | ファイル操作に関するより親切な説明については L<perlopentut> を参照して下さい。 | |
| 18463 | 参照してください。 | |
| 18464 | 10800 | |
| 18465 | =begin original | |
| 18466 | ||
| 18467 | Portability issues: L<perlport/sysopen>. | |
| 18468 | ||
| 18469 | =end original | |
| 18470 | ||
| 18471 | 移植性の問題: L<perlport/sysopen>。 | |
| 18472 | ||
| 18473 | 10801 | =item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 18474 | X<sysread> | |
| 18475 | 10802 | |
| 18476 | 10803 | =item sysread FILEHANDLE,SCALAR,LENGTH |
| 18477 | 10804 | |
| 18478 | =for Pod::Functions fixed-length unbuffered input from a filehandle | |
| 18479 | ||
| 18480 | 10805 | =begin original |
| 18481 | 10806 | |
| 18482 | 10807 | Attempts to read LENGTH bytes of data into variable SCALAR from the |
| 18483 | specified FILEHANDLE, using | |
| 10808 | specified FILEHANDLE, using the system call read(2). It bypasses stdio, | |
| 18484 | ||
| 10809 | so mixing this with other kinds of reads, C<print>, C<write>, | |
| 18485 | ||
| 10810 | C<seek>, C<tell>, or C<eof> can cause confusion because stdio | |
| 18486 | ||
| 10811 | usually buffers data. Returns the number of bytes actually read, C<0> | |
| 18487 | ||
| 10812 | at end of file, or undef if there was an error. SCALAR will be grown or | |
| 18488 | confusion because the | |
| 18489 | perlio or stdio layers usually buffer data. Returns the number of | |
| 18490 | bytes actually read, C<0> at end of file, or undef if there was an | |
| 18491 | error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will | |
| 18492 | be grown or | |
| 18493 | 10813 | shrunk so that the last byte actually read is the last byte of the |
| 18494 | 10814 | scalar after the read. |
| 18495 | 10815 | |
| 18496 | 10816 | =end original |
| 18497 | 10817 | |
| 18498 | ||
| 10818 | システムコール read(2) を用いて、指定した FILEHANDLE | |
| 18499 | データの読み込みを試みます。 | |
| 10819 | から、変数 SCALAR へ、LENGTH バイトのデータの読み込みを試みます。 | |
| 18500 | これは、 | |
| 10820 | これは、stdio ルーチンを通りませんから、 | |
| 18501 | ||
| 10821 | 他の入力関数, C<print>, C<write>, | |
| 18502 | ||
| 10822 | C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなる | |
| 18503 | ||
| 10823 | かもしれません。stdio は普通データをバッファリングするからです。 | |
| 18504 | ||
| 10824 | ファイルの最後では C<0>が、 | |
| 18505 | ||
| 10825 | エラー時には undef が、 | |
| 18506 | 読み込まれたデータの長さが返されます | |
| 10826 | それ以外では実際に読み込まれたデータの長さが返されます。 | |
| 18507 | セットされます)。 | |
| 18508 | 10827 | 実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、 |
| 18509 | 10828 | SCALAR は伸び縮みします。 |
| 18510 | 10829 | |
| 18511 | 10830 | =begin original |
| 18512 | 10831 | |
| 18513 | 10832 | An OFFSET may be specified to place the read data at some place in the |
| 18514 | 10833 | string other than the beginning. A negative OFFSET specifies |
| 18515 | placement at that many | |
| 10834 | placement at that many bytes counting backwards from the end of the | |
| 18516 | ||
| 10835 | string. A positive OFFSET greater than the length of SCALAR results | |
| 18517 | ||
| 10836 | in the string being padded to the required size with C<"\0"> bytes before | |
| 18518 | ||
| 10837 | the result of the read is appended. | |
| 18519 | 10838 | |
| 18520 | 10839 | =end original |
| 18521 | 10840 | |
| 18522 | OFFSET を指定すると、 | |
| 10841 | OFFSET を指定すると、 | |
| 18523 | ||
| 10842 | SCALAR の先頭以外の場所から、読み込みを行なうことができます。 | |
| 10843 | OFFSET に負の値を指定すると、文字列の最後から逆向きに何バイト目かで | |
| 18524 | 10844 | 位置を指定します。 |
| 18525 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、 | |
| 10845 | OFFSET が正の値で、SCALAR の長さよりも大きかった場合、 | |
| 18526 | ||
| 10846 | 必要なサイズになるまで C<"\0"> でパッディングされ、その後に | |
| 10847 | 読み込み結果が追加されます。 | |
| 18527 | 10848 | |
| 18528 | 10849 | =begin original |
| 18529 | 10850 | |
| 18530 | There is no syseof() function, which is ok, since | |
| 10851 | There is no syseof() function, which is ok, since eof() doesn't work | |
| 18531 | ||
| 10852 | very well on device files (like ttys) anyway. Use sysread() and check | |
| 18532 | an | |
| 10853 | for a return value for 0 to decide whether you're done. | |
| 18533 | check for a return value of 0 to decide whether you're done. | |
| 18534 | 10854 | |
| 18535 | 10855 | =end original |
| 18536 | 10856 | |
| 18537 | syseof() 関数はありませんが、問題ありません | |
| 10857 | syseof() 関数はありませんが、問題ありません。 | |
| 18538 | ||
| 10858 | どちらにしろ eof() は(tty のような)デバイスファイルに対しては | |
| 18539 | ||
| 10859 | うまく動作しないからです。 | |
| 18540 | ||
| 10860 | sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを | |
| 18541 | ||
| 10861 | 判断してください。 | |
| 18542 | 10862 | |
| 18543 | =begin original | |
| 18544 | ||
| 18545 | Note that if the filehandle has been marked as C<:utf8>, C<sysread> will | |
| 18546 | throw an exception. The C<:encoding(...)> layer implicitly | |
| 18547 | introduces the C<:utf8> layer. See | |
| 18548 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 18549 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
| 18550 | ||
| 18551 | =end original | |
| 18552 | ||
| 18553 | ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
| 18554 | C<sysread> は例外を投げます。 | |
| 18555 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 | |
| 18556 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>, | |
| 18557 | L<open> プラグマを参照してください。 | |
| 18558 | ||
| 18559 | 10863 | =item sysseek FILEHANDLE,POSITION,WHENCE |
| 18560 | X<sysseek> X<lseek> | |
| 18561 | 10864 | |
| 18562 | =for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite | |
| 18563 | ||
| 18564 | 10865 | =begin original |
| 18565 | 10866 | |
| 18566 | Sets FILEHANDLE's system position | |
| 10867 | Sets FILEHANDLE's system position using the system call lseek(2). It | |
| 18567 | b | |
| 10868 | bypasses stdio, so mixing this with reads (other than C<sysread>), | |
| 18568 | ||
| 10869 | C<print>, C<write>, C<seek>, C<tell>, or C<eof> may cause confusion. | |
| 18569 | ||
| 10870 | FILEHANDLE may be an expression whose value gives the name of the | |
| 18570 | ||
| 10871 | filehandle. The values for WHENCE are C<0> to set the new position to | |
| 10872 | POSITION, C<1> to set the it to the current position plus POSITION, | |
| 10873 | and C<2> to set it to EOF plus POSITION (typically negative). For | |
| 10874 | WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, and | |
| 10875 | C<SEEK_END> (start of the file, current position, end of the file) | |
| 10876 | from the Fcntl module. | |
| 18571 | 10877 | |
| 18572 | 10878 | =end original |
| 18573 | 10879 | |
| 18574 | FILEHANDLE のシステム位置を | |
| 10880 | FILEHANDLE のシステム位置を lseek(2) システムコールを使って設定します。 | |
| 18575 | ||
| 10881 | これは stdio をバイパスしますので、 | |
| 18576 | ||
| 10882 | (C<sysread>以外の)読み込み、 | |
| 18577 | C< | |
| 10883 | C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと | |
| 18578 | ||
| 10884 | 混乱を引き起こします。 | |
| 18579 | ||
| 10885 | FILEHANDLE は式でも構いません。その場合はその値がファイルハンドルの | |
| 10886 | 名前となります。 | |
| 10887 | WHENCE の値が、C<0> ならば、 | |
| 10888 | 新しい位置を POSITION の位置へ、C<1> ならば、現在位置から | |
| 10889 | POSITION 加えた位置へ、C<2> ならば、EOF から POSITION | |
| 10890 | だけ加えた位置へ、新しい位置を設定します。 | |
| 10891 | この値には、Fcntl モジュールで使われている C<SEEK_SET>、 | |
| 10892 | C<SEEK_CUR>、C<SEEK_END> | |
| 10893 | (ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。 | |
| 18580 | 10894 | |
| 18581 | 10895 | =begin original |
| 18582 | 10896 | |
| 18583 | Note the emphasis on bytes: even if the filehandle has been set to operate | |
| 18584 | on characters (for example using the C<:encoding(UTF-8)> I/O layer), the | |
| 18585 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 18586 | L<C<tell>|/tell FILEHANDLE>, and | |
| 18587 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 18588 | family of functions use byte offsets, not character offsets, | |
| 18589 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 18590 | ||
| 18591 | =end original | |
| 18592 | ||
| 18593 | バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして) | |
| 18594 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 | |
| 18595 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 18596 | L<C<tell>|/tell FILEHANDLE>, | |
| 18597 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 18598 | 文字オフセットではなくバイトオフセットを使います; | |
| 18599 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 18600 | ||
| 18601 | =begin original | |
| 18602 | ||
| 18603 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal | |
| 18604 | buffered IO, so mixing it with reads other than | |
| 18605 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example | |
| 18606 | L<C<readline>|/readline EXPR> or | |
| 18607 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>), | |
| 18608 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 18609 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 18610 | L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause | |
| 18611 | confusion. | |
| 18612 | ||
| 18613 | =end original | |
| 18614 | ||
| 18615 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を | |
| 18616 | バイパスしますので、 | |
| 18617 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば | |
| 18618 | L<C<readline>|/readline EXPR> や | |
| 18619 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、 | |
| 18620 | L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>, | |
| 18621 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>, | |
| 18622 | L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。 | |
| 18623 | ||
| 18624 | =begin original | |
| 18625 | ||
| 18626 | For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>, | |
| 18627 | and C<SEEK_END> (start of the file, current position, end of the file) | |
| 18628 | from the L<Fcntl> module. Use of the constants is also more portable | |
| 18629 | than relying on 0, 1, and 2. For example to define a "systell" function: | |
| 18630 | ||
| 18631 | =end original | |
| 18632 | ||
| 18633 | WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>, | |
| 18634 | C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を | |
| 18635 | 使うこともできます。 | |
| 18636 | 定数の使用は 0, 1, 2 に依存するよりも移植性があります。 | |
| 18637 | 例えば "systell" 関数を定義するには: | |
| 18638 | ||
| 18639 | use Fcntl 'SEEK_CUR'; | |
| 18640 | sub systell { sysseek($_[0], 0, SEEK_CUR) } | |
| 18641 | ||
| 18642 | =begin original | |
| 18643 | ||
| 18644 | 10897 | Returns the new position, or the undefined value on failure. A position |
| 18645 | of zero is returned as the string C<"0 but true">; thus | |
| 10898 | of zero is returned as the string C<"0 but true">; thus C<sysseek> returns | |
| 18646 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns | |
| 18647 | 10899 | true on success and false on failure, yet you can still easily determine |
| 18648 | 10900 | the new position. |
| 18649 | 10901 | |
| 18650 | 10902 | =end original |
| 18651 | 10903 | |
| 18652 | 新しい位置を返します | |
| 10904 | 新しい位置を返します。失敗したときは未定義値を返します。 | |
| 18653 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます | |
| 10905 | 位置がゼロの場合は、C<"0 but true"> の文字列として返されます。 | |
| 18654 | ||
| 10906 | 従って C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、 | |
| 18655 | ||
| 10907 | 簡単に新しい位置を判定できます。 | |
| 18656 | 10908 | |
| 18657 | 10909 | =item system LIST |
| 18658 | X<system> X<shell> | |
| 18659 | 10910 | |
| 18660 | 10911 | =item system PROGRAM LIST |
| 18661 | 10912 | |
| 18662 | =for Pod::Functions run a separate program | |
| 18663 | ||
| 18664 | 10913 | =begin original |
| 18665 | 10914 | |
| 18666 | Does exactly the same thing as | |
| 10915 | Does exactly the same thing as C<exec LIST>, except that a fork is | |
| 18667 | done first and the parent process waits for the child process to | |
| 10916 | done first, and the parent process waits for the child process to | |
| 18668 | e | |
| 10917 | complete. Note that argument processing varies depending on the | |
| 18669 | 10918 | number of arguments. If there is more than one argument in LIST, |
| 18670 | 10919 | or if LIST is an array with more than one value, starts the program |
| 18671 | 10920 | given by the first element of the list with arguments given by the |
| 18672 | 10921 | rest of the list. If there is only one scalar argument, the argument |
| 18673 | 10922 | is checked for shell metacharacters, and if there are any, the |
| 18674 | 10923 | entire argument is passed to the system's command shell for parsing |
| 18675 | 10924 | (this is C</bin/sh -c> on Unix platforms, but varies on other |
| 18676 | 10925 | platforms). If there are no shell metacharacters in the argument, |
| 18677 | 10926 | it is split into words and passed directly to C<execvp>, which is |
| 18678 | more efficient. | |
| 10927 | more efficient. | |
| 18679 | reliably avoid using the shell; C<system LIST>, even with more than one | |
| 18680 | element, will fall back to the shell if the first spawn fails. | |
| 18681 | 10928 | |
| 18682 | 10929 | =end original |
| 18683 | 10930 | |
| 18684 | ||
| 10931 | C<exec LIST> とほとんど同じですが、まず fork を行ない、 | |
| 18685 | 10932 | 親プロセスではチャイルドプロセスが終了するのを wait します。 |
| 18686 | 10933 | exec の項で述べたように、引数の処理は、引数の数によって異なることに |
| 18687 | 10934 | 注意してください。 |
| 18688 | 10935 | LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 |
| 18689 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を | |
| 10936 | リストの最初の要素で与えられるプログラムを、リストの残りの要素を | |
| 18690 | 起動します。 | |
| 10937 | 引数として起動します。 | |
| 18691 | スカラの引数が一つだけの場合、 | |
| 10938 | スカラの引数が一つだけの場合、 | |
| 18692 | ||
| 10939 | 引数はシェルのメタキャラクタをチェックされ、もしあれば | |
| 18693 | ||
| 10940 | パーズのために引数全体がシステムコマンドシェル | |
| 18694 | ||
| 10941 | (これは Unix プラットフォームでは C</bin/sh -c> ですが、 | |
| 18695 | ||
| 10942 | 他のプラットフォームでは異なります)に渡されます。 | |
| 18696 | ||
| 10943 | シェルメタキャラクタがなかった場合、 | |
| 18697 | ||
| 10944 | 引数は単語に分解されて直接 C<execvp> に渡されます。 | |
| 18698 | ||
| 10945 | この方がより効率的です。 | |
| 18699 | シェルにフォールバックします。 | |
| 18700 | 10946 | |
| 18701 | 10947 | =begin original |
| 18702 | 10948 | |
| 18703 | Perl will attempt to flush all files opened for | |
| 10949 | Beginning with v5.6.0, Perl will attempt to flush all files opened for | |
| 18704 | 10950 | output before any operation that may do a fork, but this may not be |
| 18705 | 10951 | supported on some platforms (see L<perlport>). To be safe, you may need |
| 18706 | to set | |
| 10952 | to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method | |
| 18707 | o | |
| 10953 | of C<IO::Handle> on any open handles. | |
| 18708 | on any open handles. | |
| 18709 | 10954 | |
| 18710 | 10955 | =end original |
| 18711 | 10956 | |
| 18712 | v5.6.0 | |
| 10957 | v5.6.0から、Perl は fork を行うようなあらゆる動作の前に | |
| 18713 | ||
| 10958 | 出力用にオープンしていた全てのファイルをフラッシュしようとします。 | |
| 18714 | プラットフォームもあります(L<perlport> | |
| 10959 | しかしこれをサポートしていないプラットフォームもあります(L<perlport> 参照)。 | |
| 18715 | 安全のために、 | |
| 10960 | 安全のためには、C<$l>(English モジュールを使っているなら $AUTOFLUSH)を | |
| 18716 | ||
| 10961 | 設定するか、あらゆるオープン済みハンドルにおいて C<IO::Handle> の C<autoflush()> | |
| 18717 | ||
| 10962 | メソッドが必要となるかもしれません。 | |
| 18718 | 呼び出す必要があるかもしれません。 | |
| 18719 | 10963 | |
| 18720 | 10964 | =begin original |
| 18721 | 10965 | |
| 18722 | The return value is the exit status of the program as | |
| 10966 | The return value is the exit status of the program as | |
| 18723 | ||
| 10967 | returned by the C<wait> call. To get the actual exit value divide by | |
| 18724 | ||
| 10968 | 256. See also L</exec>. This is I<not> what you want to use to capture | |
| 18725 | ||
| 10969 | the output from a command, for that you should use merely backticks or | |
| 18726 | s | |
| 10970 | C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1 | |
| 18727 | ||
| 10971 | indicates a failure to start the program (inspect $! for the reason). | |
| 18728 | L<perlop/"`STRING`">. Return value of -1 indicates a failure to start | |
| 18729 | the program or an error of the L<wait(2)> system call (inspect | |
| 18730 | L<C<$!>|perlvar/$!> for the reason). | |
| 18731 | 10972 | |
| 18732 | 10973 | =end original |
| 18733 | 10974 | |
| 18734 | 返り値は、 | |
| 10975 | 返り値は、C<wait> が返すプログラムの exit 状態です。 | |
| 18735 | 実際の exit 値を得るには | |
| 10976 | 実際の exit 値を得るには 256 で割ってください。 | |
| 18736 | L< | |
| 10977 | L</exec> も参照してください。 | |
| 18737 | これはコマンドからの出力を捕らえるために使うものI<ではありません> | |
| 10978 | これはコマンドからの出力を捕らえるために使うものI<ではありません>。 | |
| 18738 | 10979 | そのような用途には、L<perlop/"`STRING`"> に記述されている |
| 18739 | 逆クォートや | |
| 10980 | 逆クォートや C<qx//> を使用してください。 | |
| 18740 | -1 の返り値はプログラムを開始させることに失敗した | |
| 10981 | -1 の返り値はプログラムを開始させることに失敗したことを示します | |
| 18741 | ||
| 10982 | (理由は $! を調べてください)。 | |
| 18742 | (理由は L<C<$!>|perlvar/$!> を調べてください)。 | |
| 18743 | 10983 | |
| 18744 | 10984 | =begin original |
| 18745 | 10985 | |
| 18746 | ||
| 10986 | Like C<exec>, C<system> allows you to lie to a program about its name if | |
| 18747 | ||
| 10987 | you use the C<system PROGRAM LIST> syntax. Again, see L</exec>. | |
| 18748 | 10988 | |
| 18749 | 10989 | =end original |
| 18750 | 10990 | |
| 18751 | ||
| 10991 | C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を | |
| 18752 | ||
| 10992 | 使うことで、プログラムに対してその名前を嘘をつくことができます。 | |
| 10993 | 再び、L</exec> を参照して下さい。 | |
| 18753 | 10994 | |
| 18754 | 10995 | =begin original |
| 18755 | 10996 | |
| 18756 | ||
| 10997 | Because C<system> and backticks block C<SIGINT> and C<SIGQUIT>, killing the | |
| 18757 | ||
| 10998 | program they're running doesn't actually interrupt your program. | |
| 18758 | syntax. Again, see L<C<exec>|/exec LIST>. | |
| 18759 | 10999 | |
| 18760 | 11000 | =end original |
| 18761 | 11001 | |
| 18762 | ||
| 11002 | C<system> とバッククォートは C<SIGINT> と C<SIGQUIT> をブロックするので、 | |
| 18763 | ||
| 11003 | これらが実行したプログラムを kill しても実際に元のプログラムを | |
| 18764 | ||
| 11004 | 中断させることはありません。 | |
| 18765 | 再び、L<C<exec>|/exec LIST> を参照してください。 | |
| 18766 | 11005 | |
| 18767 | ||
| 11006 | @args = ("command", "arg1", "arg2"); | |
| 18768 | ||
| 18769 | Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of | |
| 18770 | L<C<system>|/system LIST>, if you expect your program to terminate on | |
| 18771 | receipt of these signals you will need to arrange to do so yourself | |
| 18772 | based on the return value. | |
| 18773 | ||
| 18774 | =end original | |
| 18775 | ||
| 18776 | C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、 | |
| 18777 | これらのシグナルを受信して終了させることを想定したプログラムの場合、 | |
| 18778 | 返り値を利用するように変更する必要があります。 | |
| 18779 | ||
| 18780 | my @args = ("command", "arg1", "arg2"); | |
| 18781 | 11007 | system(@args) == 0 |
| 18782 | | |
| 11008 | or die "system @args failed: $?" | |
| 18783 | 11009 | |
| 18784 | 11010 | =begin original |
| 18785 | 11011 | |
| 18786 | ||
| 11012 | You can check all the failure possibilities by inspecting | |
| 18787 | ||
| 11013 | C<$?> like this: | |
| 18788 | L<C<$?>|perlvar/$?> like this: | |
| 18789 | 11014 | |
| 18790 | 11015 | =end original |
| 18791 | 11016 | |
| 18792 | ||
| 11017 | 以下のように C<$?> を調べることで、全ての失敗の可能性を | |
| 18793 | ||
| 11018 | チェックすることができます: | |
| 18794 | 11019 | |
| 18795 | i | |
| 11020 | $exit_value = $? >> 8; | |
| 18796 | | |
| 11021 | $signal_num = $? & 127; | |
| 18797 | | |
| 11022 | $dumped_core = $? & 128; | |
| 18798 | elsif ($? & 127) { | |
| 18799 | printf "child died with signal %d, %s coredump\n", | |
| 18800 | ($? & 127), ($? & 128) ? 'with' : 'without'; | |
| 18801 | } | |
| 18802 | else { | |
| 18803 | printf "child exited with value %d\n", $? >> 8; | |
| 18804 | } | |
| 18805 | 11023 | |
| 18806 | 11024 | =begin original |
| 18807 | 11025 | |
| 18808 | ||
| 11026 | When the arguments get executed via the system shell, results | |
| 18809 | ||
| 11027 | and return codes will be subject to its quirks and capabilities. | |
| 18810 | L< | |
| 11028 | See L<perlop/"`STRING`"> and L</exec> for details. | |
| 18811 | 11029 | |
| 18812 | 11030 | =end original |
| 18813 | 11031 | |
| 18814 | ||
| 11032 | 引数がシステムシェル経由で実行された場合、 | |
| 18815 | ||
| 11033 | 結果と返り値はシェルの癖と能力によって変更されることがあります。 | |
| 18816 | ||
| 11034 | 詳細については L<perlop/"`STRING`"> と L</exec> を参照して下さい。 | |
| 18817 | 11035 | |
| 18818 | =begin original | |
| 18819 | ||
| 18820 | When L<C<system>|/system LIST>'s arguments are executed indirectly by | |
| 18821 | the shell, results and return codes are subject to its quirks. | |
| 18822 | See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details. | |
| 18823 | ||
| 18824 | =end original | |
| 18825 | ||
| 18826 | L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、 | |
| 18827 | 結果と返り値はシェルの癖によって変更されることがあります。 | |
| 18828 | 詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を | |
| 18829 | 参照してください。 | |
| 18830 | ||
| 18831 | =begin original | |
| 18832 | ||
| 18833 | Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and | |
| 18834 | L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for | |
| 18835 | details. | |
| 18836 | ||
| 18837 | =end original | |
| 18838 | ||
| 18839 | L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、 | |
| 18840 | C<SIGCHLD> ハンドラの影響を受けます。 | |
| 18841 | 詳しくは L<perlipc> を参照してください。 | |
| 18842 | ||
| 18843 | =begin original | |
| 18844 | ||
| 18845 | Portability issues: L<perlport/system>. | |
| 18846 | ||
| 18847 | =end original | |
| 18848 | ||
| 18849 | 移植性の問題: L<perlport/system>。 | |
| 18850 | ||
| 18851 | 11036 | =item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET |
| 18852 | X<syswrite> | |
| 18853 | 11037 | |
| 18854 | 11038 | =item syswrite FILEHANDLE,SCALAR,LENGTH |
| 18855 | 11039 | |
| 18856 | 11040 | =item syswrite FILEHANDLE,SCALAR |
| 18857 | 11041 | |
| 18858 | =for Pod::Functions fixed-length unbuffered output to a filehandle | |
| 18859 | ||
| 18860 | 11042 | =begin original |
| 18861 | 11043 | |
| 18862 | 11044 | Attempts to write LENGTH bytes of data from variable SCALAR to the |
| 18863 | specified FILEHANDLE, using | |
| 11045 | specified FILEHANDLE, using the system call write(2). If LENGTH | |
| 18864 | not specified, writes whole SCALAR. It bypasses | |
| 11046 | is not specified, writes whole SCALAR. It bypasses stdio, so mixing | |
| 18865 | ||
| 11047 | this with reads (other than C<sysread())>, C<print>, C<write>, | |
| 18866 | ||
| 11048 | C<seek>, C<tell>, or C<eof> may cause confusion because stdio | |
| 18867 | ||
| 11049 | usually buffers data. Returns the number of bytes actually written, | |
| 18868 | ||
| 11050 | or C<undef> if there was an error. If the LENGTH is greater than | |
| 18869 | ||
| 11051 | the available data in the SCALAR after the OFFSET, only as much | |
| 18870 | ||
| 11052 | data as is available will be written. | |
| 18871 | if there was an error (in this case the errno variable | |
| 18872 | L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the | |
| 18873 | data available in the SCALAR after the OFFSET, only as much data as is | |
| 18874 | available will be written. | |
| 18875 | 11053 | |
| 18876 | 11054 | =end original |
| 18877 | 11055 | |
| 18878 | ||
| 11056 | write(2) システムコールを使って、指定した FILEHANDLEへ、 | |
| 18879 | データの書き込みを試みます。 | |
| 11057 | 変数 SCALAR から、LENGTH バイトのデータの書き込みを試みます。 | |
| 18880 | 11058 | LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。 |
| 18881 | これは、 | |
| 11059 | これは、stdio ルーチンを通りませんから、 | |
| 18882 | (C<sysread> | |
| 11060 | 他の入力関数(C<sysread()>以外), C<print>, C<write>, | |
| 18883 | ||
| 11061 | C<seek>, C<tell>, or C<eof>と混ぜて使うと、 | |
| 18884 | ||
| 11062 | 出力がおかしくなるかもしれません。 | |
| 18885 | ||
| 11063 | stdio は普通データをバッファリングするからです。 | |
| 18886 | ||
| 11064 | 実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます。 | |
| 18887 | 実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が | |
| 18888 | 返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。 | |
| 18889 | 11065 | LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、 |
| 18890 | 11066 | 利用可能なデータのみが書き込まれます。 |
| 18891 | 11067 | |
| 18892 | 11068 | =begin original |
| 18893 | 11069 | |
| 18894 | 11070 | An OFFSET may be specified to write the data from some part of the |
| 18895 | 11071 | string other than the beginning. A negative OFFSET specifies writing |
| 18896 | that many | |
| 11072 | that many bytes counting backwards from the end of the string. In the | |
| 18897 | ||
| 11073 | case the SCALAR is empty you can use OFFSET but only zero offset. | |
| 18898 | 11074 | |
| 18899 | 11075 | =end original |
| 18900 | 11076 | |
| 18901 | 11077 | OFFSET を指定すると、SCALAR の先頭以外の場所から、 |
| 18902 | 11078 | データを取り出して、書き込みを行なうことができます。 |
| 18903 | 11079 | OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて |
| 18904 | 11080 | 何バイト目から書き込むかを示します。 |
| 18905 | SCALAR | |
| 11081 | SCALAR が空の場合、OFFSET はゼロのみ使用できます。 | |
| 18906 | 11082 | |
| 18907 | =begin original | |
| 18908 | ||
| 18909 | B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception. | |
| 18910 | The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer. | |
| 18911 | Alternately, if the handle is not marked with an encoding but you | |
| 18912 | attempt to write characters with code points over 255, raises an exception. | |
| 18913 | See L<C<binmode>|/binmode FILEHANDLE, LAYER>, | |
| 18914 | L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma. | |
| 18915 | ||
| 18916 | =end original | |
| 18917 | ||
| 18918 | B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、 | |
| 18919 | C<syswrite> は例外を投げます。 | |
| 18920 | C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。 | |
| 18921 | または、もしハンドルにエンコーディングが記録されていない状態で | |
| 18922 | 255 を超える符号位置の文字を書き込もうとすると、例外が発生します。 | |
| 18923 | L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>, | |
| 18924 | L<open> プラグマを参照してください。 | |
| 18925 | ||
| 18926 | 11083 | =item tell FILEHANDLE |
| 18927 | X<tell> | |
| 18928 | 11084 | |
| 18929 | 11085 | =item tell |
| 18930 | 11086 | |
| 18931 | =for Pod::Functions get current seekpointer on a filehandle | |
| 18932 | ||
| 18933 | 11087 | =begin original |
| 18934 | 11088 | |
| 18935 | Returns the current position | |
| 11089 | Returns the current position for FILEHANDLE, or -1 on error. FILEHANDLE | |
| 18936 | ||
| 11090 | may be an expression whose value gives the name of the actual filehandle. | |
| 18937 | ||
| 11091 | If FILEHANDLE is omitted, assumes the file last read. | |
| 18938 | last read. | |
| 18939 | 11092 | |
| 18940 | 11093 | =end original |
| 18941 | 11094 | |
| 18942 | FILEHANDLE の現在の位置を | |
| 11095 | FILEHANDLE の現在の位置を返します。エラーの場合は -1 を返します。 | |
| 18943 | 返します。 | |
| 18944 | 11096 | FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。 |
| 18945 | FILEHANDLE が省略された場合には、 | |
| 11097 | FILEHANDLE が省略された場合には、 | |
| 18946 | 調べます。 | |
| 11098 | 最後に読み込みを行なったファイルについて調べます。 | |
| 18947 | 11099 | |
| 18948 | 11100 | =begin original |
| 18949 | 11101 | |
| 18950 | ||
| 11102 | The return value of tell() for the standard streams like the STDIN | |
| 18951 | on | |
| 11103 | depends on the operating system: it may return -1 or something else. | |
| 18952 | ||
| 11104 | tell() on pipes, fifos, and sockets usually returns -1. | |
| 18953 | L<C<tell>|/tell FILEHANDLE>, and | |
| 18954 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> | |
| 18955 | family of functions use byte offsets, not character offsets, | |
| 18956 | because seeking to a character offset would be very slow in a UTF-8 file. | |
| 18957 | 11105 | |
| 18958 | 11106 | =end original |
| 18959 | 11107 | |
| 18960 | ||
| 11108 | STDIN のような標準ストリームに対する tell() の返り値は OS に依存します。 | |
| 18961 | ファイルハンドルが文字単位で処理するように設定されていたとしても、 | |
| 18962 | L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, | |
| 18963 | L<C<tell>|/tell FILEHANDLE>, | |
| 18964 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は | |
| 18965 | 文字オフセットではなくバイトオフセットを使います; | |
| 18966 | 文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。 | |
| 18967 | ||
| 18968 | =begin original | |
| 18969 | ||
| 18970 | The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams | |
| 18971 | like the STDIN depends on the operating system: it may return -1 or | |
| 18972 | something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and | |
| 18973 | sockets usually returns -1. | |
| 18974 | ||
| 18975 | =end original | |
| 18976 | ||
| 18977 | STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は | |
| 18978 | OS に依存します: | |
| 18979 | 11109 | -1 やその他の値が返ってくるかもしれません。 |
| 18980 | パイプ、FIFO、ソケットに対して | |
| 11110 | パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。 | |
| 18981 | -1 が返ります。 | |
| 18982 | 11111 | |
| 18983 | 11112 | =begin original |
| 18984 | 11113 | |
| 18985 | There is no C<systell> function. Use | |
| 11114 | There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that. | |
| 18986 | L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that. | |
| 18987 | 11115 | |
| 18988 | 11116 | =end original |
| 18989 | 11117 | |
| 18990 | 11118 | C<systell> 関数はありません。 |
| 18991 | 代わりに | |
| 11119 | 代わりに C<sysseek(FH, 0, 1)> を使ってください。 | |
| 18992 | 使ってください。 | |
| 18993 | 11120 | |
| 18994 | =begin original | |
| 18995 | ||
| 18996 | Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O | |
| 18997 | operations) on a filehandle that has been manipulated by | |
| 18998 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 18999 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or | |
| 19000 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions | |
| 19001 | ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not. | |
| 19002 | ||
| 19003 | =end original | |
| 19004 | ||
| 19005 | L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 19006 | L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, | |
| 19007 | L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された | |
| 19008 | ファイルハンドルに L<C<tell>|/tell FILEHANDLE> | |
| 19009 | (またはその他のバッファリング I/O 操作) を使わないでください。 | |
| 19010 | これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は | |
| 19011 | 違います。 | |
| 19012 | ||
| 19013 | 11121 | =item telldir DIRHANDLE |
| 19014 | X<telldir> | |
| 19015 | 11122 | |
| 19016 | =for Pod::Functions get current seekpointer on a directory handle | |
| 19017 | ||
| 19018 | 11123 | =begin original |
| 19019 | 11124 | |
| 19020 | Returns the current position of the | |
| 11125 | Returns the current position of the C<readdir> routines on DIRHANDLE. | |
| 19021 | ||
| 11126 | Value may be given to C<seekdir> to access a particular location in a | |
| 19022 | ||
| 11127 | directory. Has the same caveats about possible directory compaction as | |
| 19023 | ||
| 11128 | the corresponding system library routine. | |
| 19024 | about possible directory compaction as the corresponding system library | |
| 19025 | routine. | |
| 19026 | 11129 | |
| 19027 | 11130 | =end original |
| 19028 | 11131 | |
| 19029 | DIRHANDLE 上の | |
| 11132 | DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。 | |
| 19030 | 返します。 | |
| 19031 | 11133 | 値は、そのディレクトリで特定の位置をアクセスするため、 |
| 19032 | ||
| 11134 | C<seekdir> に渡すことができます。 | |
| 19033 | ||
| 11135 | 同名のシステムライブラリルーチンと同じく、 | |
| 19034 | 11136 | ディレクトリ縮小時の問題が考えられます。 |
| 19035 | 11137 | |
| 19036 | 11138 | =item tie VARIABLE,CLASSNAME,LIST |
| 19037 | X<tie> | |
| 19038 | 11139 | |
| 19039 | =for Pod::Functions +5.002 bind a variable to an object class | |
| 19040 | ||
| 19041 | 11140 | =begin original |
| 19042 | 11141 | |
| 19043 | 11142 | This function binds a variable to a package class that will provide the |
| 19044 | 11143 | implementation for the variable. VARIABLE is the name of the variable |
| 19045 | 11144 | to be enchanted. CLASSNAME is the name of a class implementing objects |
| 19046 | of correct type. Any additional arguments are passed to the | |
| 11145 | of correct type. Any additional arguments are passed to the C<new> | |
| 19047 | appropriate constructor | |
| 19048 | 11146 | method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, |
| 19049 | 11147 | or C<TIEHASH>). Typically these are arguments such as might be passed |
| 19050 | to the | |
| 11148 | to the C<dbm_open()> function of C. The object returned by the C<new> | |
| 19051 | ||
| 11149 | method is also returned by the C<tie> function, which would be useful | |
| 19052 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful | |
| 19053 | 11150 | if you want to access other methods in CLASSNAME. |
| 19054 | 11151 | |
| 19055 | 11152 | =end original |
| 19056 | 11153 | |
| 19057 | 11154 | この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 |
| 19058 | 11155 | VARIABLE は、魔法をかける変数の名前です。 |
| 19059 | 11156 | CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 |
| 19060 | 他に引数があれば、そのクラスの | |
| 11157 | 他に引数があれば、そのクラスの C<new> メソッドに渡されます | |
| 19061 | 11158 | (つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。 |
| 19062 | 通常、これらは、C の | |
| 11159 | 通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。 | |
| 19063 | ||
| 11160 | C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます。 | |
| 19064 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます; | |
| 19065 | 11161 | これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。 |
| 19066 | 11162 | |
| 19067 | 11163 | =begin original |
| 19068 | 11164 | |
| 19069 | Note that functions such as | |
| 11165 | Note that functions such as C<keys> and C<values> may return huge lists | |
| 19070 | ||
| 11166 | when used on large objects, like DBM files. You may prefer to use the | |
| 19071 | ||
| 11167 | C<each> function to iterate over such. Example: | |
| 19072 | HASH> function to iterate over such. Example: | |
| 19073 | 11168 | |
| 19074 | 11169 | =end original |
| 19075 | 11170 | |
| 19076 | DBM ファイルのような大きなオブジェクトでは、 | |
| 11171 | DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような | |
| 19077 | ||
| 11172 | 関数は、大きなリストを返す可能性があります。 | |
| 19078 | そのような場合では、 | |
| 11173 | そのような場合では、C<each> 関数を使って繰り返しを行なった方が | |
| 19079 | 11174 | よいかもしれません。 |
| 19080 | 11175 | 例: |
| 19081 | 11176 | |
| 19082 | 11177 | # print out history file offsets |
| 19083 | 11178 | use NDBM_File; |
| 19084 | tie( | |
| 11179 | tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0); | |
| 19085 | while ( | |
| 11180 | while (($key,$val) = each %HIST) { | |
| 19086 | ||
| 11181 | print $key, ' = ', unpack('L',$val), "\n"; | |
| 19087 | 11182 | } |
| 11183 | untie(%HIST); | |
| 19088 | 11184 | |
| 19089 | 11185 | =begin original |
| 19090 | 11186 | |
| 19091 | 11187 | A class implementing a hash should have the following methods: |
| 19092 | 11188 | |
| 19093 | 11189 | =end original |
| 19094 | 11190 | |
| 19095 | 11191 | ハッシュを実装するクラスでは、次のようなメソッドを用意します: |
| 19096 | 11192 | |
| 19097 | 11193 | TIEHASH classname, LIST |
| 19098 | 11194 | FETCH this, key |
| 19099 | 11195 | STORE this, key, value |
| 19100 | 11196 | DELETE this, key |
| 19101 | 11197 | CLEAR this |
| 19102 | 11198 | EXISTS this, key |
| 19103 | 11199 | FIRSTKEY this |
| 19104 | 11200 | NEXTKEY this, lastkey |
| 19105 | SCALAR this | |
| 19106 | 11201 | DESTROY this |
| 19107 | 11202 | UNTIE this |
| 19108 | 11203 | |
| 19109 | 11204 | =begin original |
| 19110 | 11205 | |
| 19111 | 11206 | A class implementing an ordinary array should have the following methods: |
| 19112 | 11207 | |
| 19113 | 11208 | =end original |
| 19114 | 11209 | |
| 19115 | 11210 | 通常の配列を実装するクラスでは、次のようなメソッドを用意します: |
| 19116 | 11211 | |
| 19117 | 11212 | TIEARRAY classname, LIST |
| 19118 | 11213 | FETCH this, key |
| 19119 | 11214 | STORE this, key, value |
| 19120 | 11215 | FETCHSIZE this |
| 19121 | 11216 | STORESIZE this, count |
| 19122 | 11217 | CLEAR this |
| 19123 | 11218 | PUSH this, LIST |
| 19124 | 11219 | POP this |
| 19125 | 11220 | SHIFT this |
| 19126 | 11221 | UNSHIFT this, LIST |
| 19127 | 11222 | SPLICE this, offset, length, LIST |
| 19128 | 11223 | EXTEND this, count |
| 19129 | DELETE this, key | |
| 19130 | EXISTS this, key | |
| 19131 | 11224 | DESTROY this |
| 19132 | 11225 | UNTIE this |
| 19133 | 11226 | |
| 19134 | 11227 | =begin original |
| 19135 | 11228 | |
| 19136 | A class implementing a filehandle should have the following methods: | |
| 11229 | A class implementing a file handle should have the following methods: | |
| 19137 | 11230 | |
| 19138 | 11231 | =end original |
| 19139 | 11232 | |
| 19140 | 11233 | ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します: |
| 19141 | 11234 | |
| 19142 | 11235 | TIEHANDLE classname, LIST |
| 19143 | 11236 | READ this, scalar, length, offset |
| 19144 | 11237 | READLINE this |
| 19145 | 11238 | GETC this |
| 19146 | 11239 | WRITE this, scalar, length, offset |
| 19147 | 11240 | PRINT this, LIST |
| 19148 | 11241 | PRINTF this, format, LIST |
| 19149 | 11242 | BINMODE this |
| 19150 | 11243 | EOF this |
| 19151 | 11244 | FILENO this |
| 19152 | 11245 | SEEK this, position, whence |
| 19153 | 11246 | TELL this |
| 19154 | 11247 | OPEN this, mode, LIST |
| 19155 | 11248 | CLOSE this |
| 19156 | 11249 | DESTROY this |
| 19157 | 11250 | UNTIE this |
| 19158 | 11251 | |
| 19159 | 11252 | =begin original |
| 19160 | 11253 | |
| 19161 | 11254 | A class implementing a scalar should have the following methods: |
| 19162 | 11255 | |
| 19163 | 11256 | =end original |
| 19164 | 11257 | |
| 19165 | 11258 | スカラ変数を実装するクラスでは、次のようなメソッドを用意します: |
| 19166 | 11259 | |
| 19167 | 11260 | TIESCALAR classname, LIST |
| 19168 | 11261 | FETCH this, |
| 19169 | 11262 | STORE this, value |
| 19170 | 11263 | DESTROY this |
| 19171 | 11264 | UNTIE this |
| 19172 | 11265 | |
| 19173 | 11266 | =begin original |
| 19174 | 11267 | |
| 19175 | 11268 | Not all methods indicated above need be implemented. See L<perltie>, |
| 19176 | 11269 | L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>. |
| 19177 | 11270 | |
| 19178 | 11271 | =end original |
| 19179 | 11272 | |
| 19180 | 11273 | 上記の全てのメソッドを実装する必要はありません。 |
| 19181 | 11274 | L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, |
| 19182 | L<Tie::Handle> を参照して | |
| 11275 | L<Tie::Handle> を参照して下さい。 | |
| 19183 | 11276 | |
| 19184 | 11277 | =begin original |
| 19185 | 11278 | |
| 19186 | Unlike | |
| 11279 | Unlike C<dbmopen>, the C<tie> function will not use or require a module | |
| 19187 | ||
| 11280 | for you--you need to do that explicitly yourself. See L<DB_File> | |
| 19188 | ||
| 11281 | or the F<Config> module for interesting C<tie> implementations. | |
| 19189 | module for you; you need to do that explicitly yourself. See L<DB_File> | |
| 19190 | or the L<Config> module for interesting | |
| 19191 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations. | |
| 19192 | 11282 | |
| 19193 | 11283 | =end original |
| 19194 | 11284 | |
| 19195 | ||
| 11285 | C<dbmopen> と違い、C<tie> 関数はモジュールを use したり | |
| 19196 | ||
| 11286 | require したりしません -- 自分で明示的に行う必要があります。 | |
| 19197 | ||
| 11287 | C<tie> の興味深い実装については L<DB_File> や F<Config> モジュールを | |
| 19198 | ||
| 11288 | 参照して下さい。 | |
| 19199 | 自分で明示的に行う必要があります。 | |
| 19200 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については | |
| 19201 | L<DB_File> や L<Config> モジュールを参照してください。 | |
| 19202 | 11289 | |
| 19203 | 11290 | =begin original |
| 19204 | 11291 | |
| 19205 | For further details see L<perltie>, L< | |
| 11292 | For further details see L<perltie>, L<"tied VARIABLE">. | |
| 19206 | 11293 | |
| 19207 | 11294 | =end original |
| 19208 | 11295 | |
| 19209 | 更なる詳細については L<perltie> や L< | |
| 11296 | 更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照して下さい。 | |
| 19210 | 参照してください。 | |
| 19211 | 11297 | |
| 19212 | 11298 | =item tied VARIABLE |
| 19213 | X<tied> | |
| 19214 | 11299 | |
| 19215 | =for Pod::Functions get a reference to the object underlying a tied variable | |
| 19216 | ||
| 19217 | 11300 | =begin original |
| 19218 | 11301 | |
| 19219 | 11302 | Returns a reference to the object underlying VARIABLE (the same value |
| 19220 | that was originally returned by the | |
| 11303 | that was originally returned by the C<tie> call that bound the variable | |
| 19221 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable | |
| 19222 | 11304 | to a package.) Returns the undefined value if VARIABLE isn't tied to a |
| 19223 | 11305 | package. |
| 19224 | 11306 | |
| 19225 | 11307 | =end original |
| 19226 | 11308 | |
| 19227 | 11309 | VARIABLE の基となるオブジェクトへのリファレンスを返します |
| 19228 | (変数をパッケージに結びつけるために | |
| 11310 | (変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの | |
| 19229 | L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの | |
| 19230 | 11311 | 返り値と同じものです)。 |
| 19231 | 11312 | VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。 |
| 19232 | 11313 | |
| 19233 | 11314 | =item time |
| 19234 | X<time> X<epoch> | |
| 19235 | 11315 | |
| 19236 | =for Pod::Functions return number of seconds since 1970 | |
| 19237 | ||
| 19238 | 11316 | =begin original |
| 19239 | 11317 | |
| 19240 | 11318 | Returns the number of non-leap seconds since whatever time the system |
| 19241 | considers to be the epoch | |
| 11319 | considers to be the epoch (that's 00:00:00, January 1, 1904 for MacOS, | |
| 19242 | ||
| 11320 | and 00:00:00 UTC, January 1, 1970 for most other systems). | |
| 19243 | ||
| 11321 | Suitable for feeding to C<gmtime> and C<localtime>. | |
| 19244 | a prominent exception being Mac OS Classic which uses 00:00:00, January 1, | |
| 19245 | 1904 in the current local time zone for its epoch. | |
| 19246 | 11322 | |
| 19247 | 11323 | =end original |
| 19248 | 11324 | |
| 19249 | ||
| 11325 | システムが紀元と考える時点 (MacOS では 1904 年 1 月 1 日 00:00:00、 | |
| 19250 | ||
| 11326 | その他のほとんどのシステムでは UTC 1970 年 1 月 1 日 00:00:00) からの | |
| 19251 | ||
| 11327 | 連続秒数を返します。 | |
| 19252 | ||
| 11328 | C<gmtime> や C<localtime> への入力形式にあっています。 | |
| 19253 | 1904 年 1 月 1 日 00:00:00 を紀元として使います。 | |
| 19254 | 11329 | |
| 19255 | 11330 | =begin original |
| 19256 | 11331 | |
| 19257 | For measuring time in better granularity than one second, | |
| 11332 | For measuring time in better granularity than one second, | |
| 19258 | ||
| 11333 | you may use either the Time::HiRes module from CPAN, or | |
| 19259 | if you have | |
| 11334 | if you have gettimeofday(2), you may be able to use the | |
| 19260 | ||
| 11335 | C<syscall> interface of Perl, see L<perlfaq8> for details. | |
| 19261 | for details. | |
| 19262 | 11336 | |
| 19263 | 11337 | =end original |
| 19264 | 11338 | |
| 19265 | 1 秒よりも細かい時間を計測するためには、 | |
| 11339 | 1 秒よりも細かい時間を計測するためには、 | |
| 19266 | CPAN | |
| 11340 | CPAN の Time::HiRes モジュールを使うか、 | |
| 19267 | ||
| 11341 | gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを | |
| 19268 | ||
| 11342 | 使った方がよいでしょう。 | |
| 19269 | 詳しくは L<perlfaq8> を参照して | |
| 11343 | 詳しくは L<perlfaq8> を参照して下さい。 | |
| 19270 | 11344 | |
| 19271 | =begin original | |
| 19272 | ||
| 19273 | For date and time processing look at the many related modules on CPAN. | |
| 19274 | For a comprehensive date and time representation look at the | |
| 19275 | L<DateTime> module. | |
| 19276 | ||
| 19277 | =end original | |
| 19278 | ||
| 19279 | 日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。 | |
| 19280 | 包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを | |
| 19281 | 参照してください。 | |
| 19282 | ||
| 19283 | 11345 | =item times |
| 19284 | X<times> | |
| 19285 | 11346 | |
| 19286 | =for Pod::Functions return elapsed time for self and child processes | |
| 19287 | ||
| 19288 | 11347 | =begin original |
| 19289 | 11348 | |
| 19290 | Returns a four-element list giving the user and system times in | |
| 11349 | Returns a four-element list giving the user and system times, in | |
| 19291 | seconds for this process and | |
| 11350 | seconds, for this process and the children of this process. | |
| 19292 | 11351 | |
| 19293 | 11352 | =end original |
| 19294 | 11353 | |
| 19295 | 現プロセス及び | |
| 11354 | 現プロセス及びその子プロセスに対する、ユーザ時間とシステム時間を | |
| 19296 | 11355 | 秒で示した、4 要素のリスト値を返します。 |
| 19297 | 11356 | |
| 19298 | | |
| 11357 | ($user,$system,$cuser,$csystem) = times; | |
| 19299 | 11358 | |
| 19300 | =begin original | |
| 19301 | ||
| 19302 | In scalar context, L<C<times>|/times> returns C<$user>. | |
| 19303 | ||
| 19304 | =end original | |
| 19305 | ||
| 19306 | スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。 | |
| 19307 | ||
| 19308 | =begin original | |
| 19309 | ||
| 19310 | Children's times are only included for terminated children. | |
| 19311 | ||
| 19312 | =end original | |
| 19313 | ||
| 19314 | 子プロセスに対する times は、終了した子プロセスのみ含められます。 | |
| 19315 | ||
| 19316 | =begin original | |
| 19317 | ||
| 19318 | Portability issues: L<perlport/times>. | |
| 19319 | ||
| 19320 | =end original | |
| 19321 | ||
| 19322 | 移植性の問題: L<perlport/times>。 | |
| 19323 | ||
| 19324 | 11359 | =item tr/// |
| 19325 | 11360 | |
| 19326 | =for Pod::Functions transliterate a string | |
| 19327 | ||
| 19328 | 11361 | =begin original |
| 19329 | 11362 | |
| 19330 | The transliteration operator. Same as | |
| 11363 | The transliteration operator. Same as C<y///>. See L<perlop>. | |
| 19331 | L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See | |
| 19332 | L<perlop/"Quote-Like Operators">. | |
| 19333 | 11364 | |
| 19334 | 11365 | =end original |
| 19335 | 11366 | |
| 19336 | ||
| 11367 | 変換演算子。C<y///>と同じです。 | |
| 19337 | L< | |
| 11368 | L<perlop> を参照してください。 | |
| 19338 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
| 19339 | 11369 | |
| 19340 | 11370 | =item truncate FILEHANDLE,LENGTH |
| 19341 | X<truncate> | |
| 19342 | 11371 | |
| 19343 | 11372 | =item truncate EXPR,LENGTH |
| 19344 | 11373 | |
| 19345 | =for Pod::Functions shorten a file | |
| 19346 | ||
| 19347 | 11374 | =begin original |
| 19348 | 11375 | |
| 19349 | 11376 | Truncates the file opened on FILEHANDLE, or named by EXPR, to the |
| 19350 | specified length. | |
| 11377 | specified length. Produces a fatal error if truncate isn't implemented | |
| 19351 | on your system. Returns true if successful, | |
| 11378 | on your system. Returns true if successful, the undefined value | |
| 19352 | er | |
| 11379 | otherwise. | |
| 19353 | 11380 | |
| 19354 | 11381 | =end original |
| 19355 | 11382 | |
| 19356 | 11383 | FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、 |
| 19357 | 11384 | 指定した長さに切り詰めます。 |
| 19358 | システム上に truncate が実装されていなければ、 | |
| 11385 | システム上に truncate が実装されていなければ、致命的エラーとなります。 | |
| 19359 | 成功すれば真を、 | |
| 11386 | 成功すれば真を、さもなければ未定義値を返します。 | |
| 19360 | 11387 | |
| 19361 | =begin original | |
| 19362 | ||
| 19363 | The behavior is undefined if LENGTH is greater than the length of the | |
| 19364 | file. | |
| 19365 | ||
| 19366 | =end original | |
| 19367 | ||
| 19368 | LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。 | |
| 19369 | ||
| 19370 | =begin original | |
| 19371 | ||
| 19372 | The position in the file of FILEHANDLE is left unchanged. You may want to | |
| 19373 | call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the | |
| 19374 | file. | |
| 19375 | ||
| 19376 | =end original | |
| 19377 | ||
| 19378 | FILEHANDLE のファイルの位置は変わりません。 | |
| 19379 | ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を | |
| 19380 | 呼び出したいかもしれません。 | |
| 19381 | ||
| 19382 | =begin original | |
| 19383 | ||
| 19384 | Portability issues: L<perlport/truncate>. | |
| 19385 | ||
| 19386 | =end original | |
| 19387 | ||
| 19388 | 移植性の問題: L<perlport/truncate>。 | |
| 19389 | ||
| 19390 | 11388 | =item uc EXPR |
| 19391 | X<uc> X<uppercase> X<toupper> | |
| 19392 | 11389 | |
| 19393 | 11390 | =item uc |
| 19394 | 11391 | |
| 19395 | =for Pod::Functions return upper-case version of a string | |
| 19396 | ||
| 19397 | 11392 | =begin original |
| 19398 | 11393 | |
| 19399 | 11394 | Returns an uppercased version of EXPR. This is the internal function |
| 19400 | 11395 | implementing the C<\U> escape in double-quoted strings. |
| 19401 | ||
| 11396 | Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale>. | |
| 19402 | ||
| 11397 | Under Unicode (C<use utf8>) it uses the standard Unicode uppercase mappings. (It | |
| 11398 | does not attempt to do titlecase mapping on initial letters. See C<ucfirst> for that.) | |
| 19403 | 11399 | |
| 11400 | If EXPR is omitted, uses C<$_>. | |
| 11401 | ||
| 19404 | 11402 | =end original |
| 19405 | 11403 | |
| 19406 | 11404 | EXPR を大文字に変換したものを返します。 |
| 19407 | 11405 | これは、ダブルクォート文字列における、C<\U> エスケープを |
| 19408 | 11406 | 実装する内部関数です。 |
| 19409 | ||
| 11407 | C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。 | |
| 19410 | ||
| 11408 | L<perllocale> を参照してください。 | |
| 11409 | (C<use utf8> を使った) Unicode では、標準 Unicode 大文字マッピングを | |
| 11410 | 使います。 | |
| 11411 | (元の文字の titlecase マッピングは試みません。 | |
| 11412 | このためには C<ucfirst> を参照してください。) | |
| 19411 | 11413 | |
| 19412 | ||
| 11414 | EXPR が省略されると、C<$_> を使います。 | |
| 19413 | 11415 | |
| 19414 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 19415 | ||
| 19416 | =end original | |
| 19417 | ||
| 19418 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 19419 | ||
| 19420 | =begin original | |
| 19421 | ||
| 19422 | This function behaves the same way under various pragmas, such as in a locale, | |
| 19423 | as L<C<lc>|/lc EXPR> does. | |
| 19424 | ||
| 19425 | =end original | |
| 19426 | ||
| 19427 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
| 19428 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 19429 | ||
| 19430 | 11416 | =item ucfirst EXPR |
| 19431 | X<ucfirst> X<uppercase> | |
| 19432 | 11417 | |
| 19433 | 11418 | =item ucfirst |
| 19434 | 11419 | |
| 19435 | =for Pod::Functions return a string with just the next letter in upper case | |
| 19436 | ||
| 19437 | 11420 | =begin original |
| 19438 | 11421 | |
| 19439 | Returns the value of EXPR with the first character | |
| 11422 | Returns the value of EXPR with the first character | |
| 19440 | (titlecase in Unicode). This is | |
| 11423 | in uppercase (titlecase in Unicode). This is | |
| 19441 | the C<\u> escape in double-quoted strings. | |
| 11424 | the internal function implementing the C<\u> escape in double-quoted strings. | |
| 11425 | Respects current LC_CTYPE locale if C<use locale> in force. See L<perllocale> | |
| 11426 | and L<utf8>. | |
| 19442 | 11427 | |
| 11428 | If EXPR is omitted, uses C<$_>. | |
| 11429 | ||
| 19443 | 11430 | =end original |
| 19444 | 11431 | |
| 19445 | 11432 | 最初の文字だけを大文字にした、EXPR を返します |
| 19446 | 11433 | (Unicode では titlecase)。 |
| 19447 | 11434 | これは、ダブルクォート文字列における、C<\u> エスケープを |
| 19448 | 11435 | 実装する内部関数です。 |
| 11436 | C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。 | |
| 11437 | L<perllocale> と L<utf8> を参照してください。 | |
| 19449 | 11438 | |
| 19450 | ||
| 11439 | EXPR が省略されると、C<$_> を使います。 | |
| 19451 | 11440 | |
| 19452 | If EXPR is omitted, uses L<C<$_>|perlvar/$_>. | |
| 19453 | ||
| 19454 | =end original | |
| 19455 | ||
| 19456 | EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。 | |
| 19457 | ||
| 19458 | =begin original | |
| 19459 | ||
| 19460 | This function behaves the same way under various pragmas, such as in a locale, | |
| 19461 | as L<C<lc>|/lc EXPR> does. | |
| 19462 | ||
| 19463 | =end original | |
| 19464 | ||
| 19465 | この関数は、ロケールのようなさまざまなプラグマの影響下では、 | |
| 19466 | L<C<lc>|/lc EXPR> と同様に振る舞います。 | |
| 19467 | ||
| 19468 | 11441 | =item umask EXPR |
| 19469 | X<umask> | |
| 19470 | 11442 | |
| 19471 | 11443 | =item umask |
| 19472 | 11444 | |
| 19473 | =for Pod::Functions set file creation mode mask | |
| 19474 | ||
| 19475 | 11445 | =begin original |
| 19476 | 11446 | |
| 19477 | 11447 | Sets the umask for the process to EXPR and returns the previous value. |
| 19478 | 11448 | If EXPR is omitted, merely returns the current umask. |
| 19479 | 11449 | |
| 19480 | 11450 | =end original |
| 19481 | 11451 | |
| 19482 | 11452 | 現在のプロセスの umask を EXPR に設定し、以前の値を返します。 |
| 19483 | 11453 | EXPR が省略されると、単にその時点の umask の値を返します。 |
| 19484 | 11454 | |
| 19485 | 11455 | =begin original |
| 19486 | 11456 | |
| 19487 | 11457 | The Unix permission C<rwxr-x---> is represented as three sets of three |
| 19488 | 11458 | bits, or three octal digits: C<0750> (the leading 0 indicates octal |
| 19489 | and isn't one of the digits). The | |
| 11459 | and isn't one of the digits). The C<umask> value is such a number | |
| 19490 | ||
| 11460 | representing disabled permissions bits. The permission (or "mode") | |
| 19491 | ||
| 11461 | values you pass C<mkdir> or C<sysopen> are modified by your umask, so | |
| 19492 | ||
| 11462 | even if you tell C<sysopen> to create a file with permissions C<0777>, | |
| 19493 | umask | |
| 11463 | if your umask is C<0022> then the file will actually be created with | |
| 19494 | ||
| 11464 | permissions C<0755>. If your C<umask> were C<0027> (group can't | |
| 19495 | ||
| 11465 | write; others can't read, write, or execute), then passing | |
| 19496 | ||
| 11466 | C<sysopen> C<0666> would create a file with mode C<0640> (C<0666 &~ | |
| 19497 | ||
| 11467 | 027> is C<0640>). | |
| 19498 | read, write, or execute), then passing | |
| 19499 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a | |
| 19500 | file with mode C<0640> (because C<0666 &~ 027> is C<0640>). | |
| 19501 | 11468 | |
| 19502 | 11469 | =end original |
| 19503 | 11470 | |
| 19504 | Unix パーミッション C<rwxr-x---> は 3 ビットの | |
| 11471 | Unix パーミッション C<rwxr-x---> は 3 ビットの 3 つの組、 | |
| 19505 | 11472 | または 3 桁の 8 進数として表現されます: |
| 19506 | 11473 | C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。 |
| 19507 | ||
| 11474 | C<umask> の値は無効にするパーミッションビットのこのような数値表現です。 | |
| 19508 | ||
| 11475 | C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の値は | |
| 19509 | ||
| 11476 | umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで | |
| 19510 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション | |
| 19511 | (または「モード」)の値は umask で修正され、たとえ | |
| 19512 | L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで | |
| 19513 | 11477 | ファイルを作るように指定しても、umask が C<0022> なら、 |
| 19514 | 11478 | 結果としてファイルは C<0755> のパーミッションで作成されます。 |
| 19515 | ||
| 11479 | C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、 | |
| 19516 | ||
| 11480 | 実行できない) のとき、C<sysopen> に C<0666> を渡すと、 | |
| 19517 | ||
| 11481 | ファイルはモード C<0640> (C<0666 &~ 027> は C<0640>)で作成されます。 | |
| 19518 | ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。 | |
| 19519 | 11482 | |
| 19520 | 11483 | =begin original |
| 19521 | 11484 | |
| 19522 | 11485 | Here's some advice: supply a creation mode of C<0666> for regular |
| 19523 | files (in | |
| 11486 | files (in C<sysopen>) and one of C<0777> for directories (in | |
| 19524 | C< | |
| 11487 | C<mkdir>) and executable files. This gives users the freedom of | |
| 19525 | executable files. This gives users the freedom of | |
| 19526 | 11488 | choice: if they want protected files, they might choose process umasks |
| 19527 | 11489 | of C<022>, C<027>, or even the particularly antisocial mask of C<077>. |
| 19528 | 11490 | Programs should rarely if ever make policy decisions better left to |
| 19529 | 11491 | the user. The exception to this is when writing files that should be |
| 19530 | kept private: mail files, web browser cookies, | |
| 11492 | kept private: mail files, web browser cookies, I<.rhosts> files, and | |
| 19531 | 11493 | so on. |
| 19532 | 11494 | |
| 19533 | 11495 | =end original |
| 19534 | 11496 | |
| 19535 | 以下は助言です: 作成モードとして、 | |
| 11497 | 以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは | |
| 19536 | ||
| 11498 | C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。 | |
| 19537 | C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは | |
| 19538 | C<0777> を指定しましょう。 | |
| 19539 | 11499 | これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、 |
| 19540 | 11500 | プロセスの umask として C<022>, C<027>, あるいは特に非社交的な |
| 19541 | 11501 | C<077> を選択できます。 |
| 19542 | 11502 | プログラムがユーザーより適切なポリシー選択ができることは稀です。 |
| 19543 | 11503 | 例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、 |
| 19544 | ||
| 11504 | I<.rhosts> ファイルなど)を書く場合です。 | |
| 19545 | 11505 | |
| 19546 | 11506 | =begin original |
| 19547 | 11507 | |
| 19548 | If | |
| 11508 | If umask(2) is not implemented on your system and you are trying to | |
| 19549 | restrict access for I<yourself> (i.e., | |
| 11509 | restrict access for I<yourself> (i.e., (EXPR & 0700) > 0), produces a | |
| 19550 | ||
| 11510 | fatal error at run time. If umask(2) is not implemented and you are | |
| 19551 | not trying to restrict access for yourself, returns | |
| 11511 | not trying to restrict access for yourself, returns C<undef>. | |
| 19552 | L<C<undef>|/undef EXPR>. | |
| 19553 | 11512 | |
| 19554 | 11513 | =end original |
| 19555 | 11514 | |
| 19556 | ||
| 11515 | umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを | |
| 19557 | 制限しようとした(つまり | |
| 11516 | 制限しようとした(つまり (EXPR & 0700) > 0)場合、実行時に致命的エラーが | |
| 19558 | ||
| 11517 | 発生します。 | |
| 19559 | ||
| 11518 | umask(2) が実装されていないシステムで、自分自身へのアクセスは | |
| 11519 | 制限しようとしなかった場合、C<undef> を返します。 | |
| 19560 | 11520 | |
| 19561 | 11521 | =begin original |
| 19562 | 11522 | |
| 19563 | 11523 | Remember that a umask is a number, usually given in octal; it is I<not> a |
| 19564 | string of octal digits. See also L< | |
| 11524 | string of octal digits. See also L</oct>, if all you have is a string. | |
| 19565 | is a string. | |
| 19566 | 11525 | |
| 19567 | 11526 | =end original |
| 19568 | 11527 | |
| 19569 | umask は通常 8 進数で与えられる数値であることを忘れないでください | |
| 11528 | umask は通常 8 進数で与えられる数値であることを忘れないでください。 | |
| 19570 | 文字列 I<ではありません>。 | |
| 11529 | 8 進数の文字列 I<ではありません>。 | |
| 19571 | 文字列しかない場合、 L< | |
| 11530 | 文字列しかない場合、 L</oct> も参照して下さい。 | |
| 19572 | 11531 | |
| 19573 | =begin original | |
| 19574 | ||
| 19575 | Portability issues: L<perlport/umask>. | |
| 19576 | ||
| 19577 | =end original | |
| 19578 | ||
| 19579 | 移植性の問題: L<perlport/umask>。 | |
| 19580 | ||
| 19581 | 11532 | =item undef EXPR |
| 19582 | X<undef> X<undefine> | |
| 19583 | 11533 | |
| 19584 | 11534 | =item undef |
| 19585 | 11535 | |
| 19586 | =for Pod::Functions remove a variable or function definition | |
| 19587 | ||
| 19588 | 11536 | =begin original |
| 19589 | 11537 | |
| 19590 | 11538 | Undefines the value of EXPR, which must be an lvalue. Use only on a |
| 19591 | 11539 | scalar value, an array (using C<@>), a hash (using C<%>), a subroutine |
| 19592 | (using C<&>), or a typeglob (using | |
| 11540 | (using C<&>), or a typeglob (using <*>). (Saying C<undef $hash{$key}> | |
| 19593 | 11541 | will probably not do what you expect on most predefined variables or |
| 19594 | DBM list values, so don't do that; see L< | |
| 11542 | DBM list values, so don't do that; see L<delete>.) Always returns the | |
| 19595 | ||
| 11543 | undefined value. You can omit the EXPR, in which case nothing is | |
| 19596 | You can omit the EXPR, in which case nothing is | |
| 19597 | 11544 | undefined, but you still get an undefined value that you could, for |
| 19598 | instance, return from a subroutine, assign to a variable | |
| 11545 | instance, return from a subroutine, assign to a variable or pass as a | |
| 19599 | 11546 | parameter. Examples: |
| 19600 | 11547 | |
| 19601 | 11548 | =end original |
| 19602 | 11549 | |
| 19603 | 11550 | 左辺値である EXPR の値を未定義にします。 |
| 19604 | スカラ値、(C<@> | |
| 11551 | スカラ値、(C<@>を使った)配列、(C<%>を使った)ハッシュ、(C<&> を使った) | |
| 19605 | サブルーチン、(C<*> | |
| 11552 | サブルーチン、(C<*>を使った)タイプグロブだけに使用します。 | |
| 19606 | 特殊変数や DBM リスト値に C<undef $hash{$key}> | |
| 11553 | (特殊変数や DBM リスト値に C<undef $hash{$key}>などとしても | |
| 19607 | おそらく期待通りの結果にはなりませんから、 | |
| 11554 | おそらく期待通りの結果にはなりませんから、 | |
| 19608 | L< | |
| 11555 | しないでください。L<delete>を参照してください。) | |
| 19609 | 11556 | 常に未定義値を返します。 |
| 19610 | 11557 | EXPR は省略することができ、その場合には何も未定義にされませんが |
| 19611 | 11558 | 未定義値は返されますので、それをたとえば、 |
| 19612 | 11559 | サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。 |
| 19613 | 11560 | 例: |
| 19614 | 11561 | |
| 19615 | 11562 | undef $foo; |
| 19616 | 11563 | undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'}; |
| 19617 | 11564 | undef @ary; |
| 19618 | 11565 | undef %hash; |
| 19619 | 11566 | undef &mysub; |
| 19620 | 11567 | undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc. |
| 19621 | 11568 | return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it; |
| 19622 | 11569 | select undef, undef, undef, 0.25; |
| 19623 | | |
| 11570 | ($a, $b, undef, $c) = &foo; # Ignore third value returned | |
| 19624 | 11571 | |
| 19625 | 11572 | =begin original |
| 19626 | 11573 | |
| 19627 | 11574 | Note that this is a unary operator, not a list operator. |
| 19628 | 11575 | |
| 19629 | 11576 | =end original |
| 19630 | 11577 | |
| 19631 | 11578 | これはリスト演算子ではなく、単項演算子であることに注意してください。 |
| 19632 | 11579 | |
| 19633 | 11580 | =item unlink LIST |
| 19634 | X<unlink> X<delete> X<remove> X<rm> X<del> | |
| 19635 | 11581 | |
| 19636 | 11582 | =item unlink |
| 19637 | 11583 | |
| 19638 | =for Pod::Functions remove one link to a file | |
| 19639 | ||
| 19640 | 11584 | =begin original |
| 19641 | 11585 | |
| 19642 | Deletes a list of files. | |
| 11586 | Deletes a list of files. Returns the number of files successfully | |
| 19643 | ||
| 11587 | deleted. | |
| 19644 | L<C<$!>|perlvar/$!> (errno): | |
| 19645 | 11588 | |
| 19646 | 11589 | =end original |
| 19647 | 11590 | |
| 19648 | 11591 | LIST に含まれるファイルを削除します。 |
| 19649 | ||
| 11592 | 削除に成功したファイルの数を返します。 | |
| 19650 | 失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします: | |
| 19651 | 11593 | |
| 19652 | | |
| 11594 | $cnt = unlink 'a', 'b', 'c'; | |
| 19653 | 11595 | unlink @goners; |
| 19654 | unlink | |
| 11596 | unlink <*.bak>; | |
| 19655 | 11597 | |
| 19656 | 11598 | =begin original |
| 19657 | 11599 | |
| 19658 | ||
| 11600 | Note: C<unlink> will not delete directories unless you are superuser and | |
| 19659 | ||
| 11601 | the B<-U> flag is supplied to Perl. Even if these conditions are | |
| 19660 | ||
| 11602 | met, be warned that unlinking a directory can inflict damage on your | |
| 19661 | ||
| 11603 | filesystem. Use C<rmdir> instead. | |
| 19662 | 11604 | |
| 19663 | ||
| 11605 | If LIST is omitted, uses C<$_>. | |
| 19664 | 11606 | |
| 19665 | エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを | |
| 19666 | 知らせません。 | |
| 19667 | どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください: | |
| 19668 | ||
| 19669 | foreach my $file ( @goners ) { | |
| 19670 | unlink $file or warn "Could not unlink $file: $!"; | |
| 19671 | } | |
| 19672 | ||
| 19673 | =begin original | |
| 19674 | ||
| 19675 | Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories | |
| 19676 | unless you are | |
| 19677 | superuser and the B<-U> flag is supplied to Perl. Even if these | |
| 19678 | conditions are met, be warned that unlinking a directory can inflict | |
| 19679 | damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on | |
| 19680 | directories is not supported on many operating systems. Use | |
| 19681 | L<C<rmdir>|/rmdir FILENAME> instead. | |
| 19682 | ||
| 19683 | 11607 | =end original |
| 19684 | 11608 | |
| 19685 | 注: スーパーユーザ権限で、Perl に | |
| 11609 | 注: スーパーユーザ権限で、Perl に -U を付けて実行した | |
| 19686 | ||
| 11610 | 場合でなければ、C<unlink> でディレクトリを削除することはありません。 | |
| 19687 | 11611 | この条件にあう場合にも、ディレクトリの削除は、 |
| 19688 | ファイルシステムに多大な損害を与える可能性があります | |
| 11612 | ファイルシステムに多大な損害を与える可能性がありますので、 | |
| 19689 | ||
| 11613 | 特に注意が必要です。C<rmdir> を代わりに使ってください。 | |
| 19690 | 対応していません。 | |
| 19691 | 代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。 | |
| 19692 | 11614 | |
| 19693 | ||
| 11615 | LIST が省略されると、C<$_> を使います。 | |
| 19694 | 11616 | |
| 19695 | If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>. | |
| 19696 | ||
| 19697 | =end original | |
| 19698 | ||
| 19699 | LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を | |
| 19700 | 使います。 | |
| 19701 | ||
| 19702 | 11617 | =item unpack TEMPLATE,EXPR |
| 19703 | X<unpack> | |
| 19704 | 11618 | |
| 19705 | =item unpack TEMPLATE | |
| 19706 | ||
| 19707 | =for Pod::Functions convert binary structure into normal perl variables | |
| 19708 | ||
| 19709 | 11619 | =begin original |
| 19710 | 11620 | |
| 19711 | ||
| 11621 | C<unpack> does the reverse of C<pack>: it takes a string | |
| 19712 | L<C<pack>|/pack TEMPLATE,LIST>: it takes a string | |
| 19713 | 11622 | and expands it out into a list of values. |
| 19714 | 11623 | (In scalar context, it returns merely the first value produced.) |
| 19715 | 11624 | |
| 19716 | 11625 | =end original |
| 19717 | 11626 | |
| 19718 | ||
| 11627 | C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、 | |
| 19719 | 行ないます: 構造体を表わす文字列をとり、 | |
| 19720 | 11628 | リスト値に展開し、その配列値を返します。 |
| 19721 | 11629 | (スカラコンテキストでは、単に最初の値を返します。) |
| 19722 | 11630 | |
| 19723 | 11631 | =begin original |
| 19724 | 11632 | |
| 19725 | If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string. | |
| 19726 | See L<perlpacktut> for an introduction to this function. | |
| 19727 | ||
| 19728 | =end original | |
| 19729 | ||
| 19730 | EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。 | |
| 19731 | この関数の説明については L<perlpacktut> を参照してください。 | |
| 19732 | ||
| 19733 | =begin original | |
| 19734 | ||
| 19735 | 11633 | The string is broken into chunks described by the TEMPLATE. Each chunk |
| 19736 | 11634 | is converted separately to a value. Typically, either the string is a result |
| 19737 | of | |
| 11635 | of C<pack>, or the bytes of the string represent a C structure of some | |
| 19738 | ||
| 11636 | kind. | |
| 19739 | 11637 | |
| 19740 | 11638 | =end original |
| 19741 | 11639 | |
| 19742 | 11640 | 文字列は TEMPLATE で示された固まりに分割されます。 |
| 19743 | 11641 | それぞれの固まりは別々に値に変換されます。 |
| 19744 | 典型的には、文字列は | |
| 11642 | 典型的には、文字列は C<pack> の結果あるいはある種の C の構造体の | |
| 19745 | ||
| 11643 | 文字列表現のバイト列です。 | |
| 19746 | 11644 | |
| 19747 | 11645 | =begin original |
| 19748 | 11646 | |
| 19749 | The TEMPLATE has the same format as in the | |
| 11647 | The TEMPLATE has the same format as in the C<pack> function. | |
| 19750 | L<C<pack>|/pack TEMPLATE,LIST> function. | |
| 19751 | 11648 | Here's a subroutine that does substring: |
| 19752 | 11649 | |
| 19753 | 11650 | =end original |
| 19754 | 11651 | |
| 19755 | TEMPLATE は、 | |
| 11652 | TEMPLATE は、C<pack> 関数と同じフォーマットを使います。 | |
| 19756 | 11653 | 部分文字列を取り出すうサブルーチンの例を示します: |
| 19757 | 11654 | |
| 19758 | 11655 | sub substr { |
| 19759 | ||
| 11656 | my($what,$where,$howmuch) = @_; | |
| 19760 | ||
| 11657 | unpack("x$where a$howmuch", $what); | |
| 19761 | 11658 | } |
| 19762 | 11659 | |
| 19763 | 11660 | =begin original |
| 19764 | 11661 | |
| 19765 | 11662 | and then there's |
| 19766 | 11663 | |
| 19767 | 11664 | =end original |
| 19768 | 11665 | |
| 19769 | 11666 | これもそうです。 |
| 19770 | 11667 | |
| 19771 | sub ordinal { unpack(" | |
| 11668 | sub ordinal { unpack("c",$_[0]); } # same as ord() | |
| 19772 | 11669 | |
| 19773 | 11670 | =begin original |
| 19774 | 11671 | |
| 19775 | In addition to fields allowed in | |
| 11672 | In addition to fields allowed in pack(), you may prefix a field with | |
| 19776 | ||
| 11673 | a %<number> to indicate that | |
| 19777 | 11674 | you want a <number>-bit checksum of the items instead of the items |
| 19778 | themselves. Default is a 16-bit checksum. | |
| 11675 | themselves. Default is a 16-bit checksum. Checksum is calculated by | |
| 19779 | 11676 | summing numeric values of expanded values (for string fields the sum of |
| 19780 | C<ord($char)> is taken | |
| 11677 | C<ord($char)> is taken, for bit fields the sum of zeroes and ones). | |
| 19781 | 11678 | |
| 19782 | 11679 | =end original |
| 19783 | 11680 | |
| 19784 | ||
| 11681 | pack() で利用可能なフィールドの他に、 | |
| 19785 | 11682 | フィールドの前に %<数値> というものを付けて、 |
| 19786 | 11683 | 項目自身の代わりに、その項目の <数値>-ビットのチェックサムを |
| 19787 | 11684 | 計算させることができます。 |
| 19788 | 11685 | デフォルトは、16-ビットチェックサムです。 |
| 19789 | 11686 | チェックサムは展開された値の数値としての値の合計 |
| 19790 | (文字列フィールドの場合は C<ord($char)> の合計 | |
| 11687 | (文字列フィールドの場合は C<ord($char)> の合計、 | |
| 19791 | 11688 | ビットフィールドの場合は 0 と 1 の合計) が用いられます。 |
| 19792 | 11689 | |
| 19793 | 11690 | =begin original |
| 19794 | 11691 | |
| 19795 | 11692 | For example, the following |
| 19796 | 11693 | computes the same number as the System V sum program: |
| 19797 | 11694 | |
| 19798 | 11695 | =end original |
| 19799 | 11696 | |
| 19800 | 11697 | たとえば、以下のコードは |
| 19801 | 11698 | System V の sum プログラムと同じ値を計算します。 |
| 19802 | 11699 | |
| 19803 | | |
| 11700 | $checksum = do { | |
| 19804 | ||
| 11701 | local $/; # slurp! | |
| 19805 | ||
| 11702 | unpack("%32C*",<>) % 65535; | |
| 19806 | 11703 | }; |
| 19807 | 11704 | |
| 19808 | 11705 | =begin original |
| 19809 | 11706 | |
| 19810 | 11707 | The following efficiently counts the number of set bits in a bit vector: |
| 19811 | 11708 | |
| 19812 | 11709 | =end original |
| 19813 | 11710 | |
| 19814 | 11711 | 以下は、効率的にビットベクターの設定されているビットを |
| 19815 | 11712 | 数えるものです。 |
| 19816 | 11713 | |
| 19817 | | |
| 11714 | $setbits = unpack("%32b*", $selectmask); | |
| 19818 | 11715 | |
| 19819 | 11716 | =begin original |
| 19820 | 11717 | |
| 19821 | 11718 | The C<p> and C<P> formats should be used with care. Since Perl |
| 19822 | has no way of checking whether the value passed to | |
| 11719 | has no way of checking whether the value passed to C<unpack()> | |
| 19823 | L<C<unpack>|/unpack TEMPLATE,EXPR> | |
| 19824 | 11720 | corresponds to a valid memory location, passing a pointer value that's |
| 19825 | 11721 | not known to be valid is likely to have disastrous consequences. |
| 19826 | 11722 | |
| 19827 | 11723 | =end original |
| 19828 | 11724 | |
| 19829 | 11725 | C<p> と C<P> は注意深く使うべきです。 |
| 19830 | Perl は | |
| 11726 | Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうかを | |
| 19831 | ||
| 11727 | 確認する方法がないので、有効かどうかわからないポインタ値を渡すと | |
| 19832 | ||
| 11728 | 悲惨な結果を引き起こすかもしれません。 | |
| 19833 | 11729 | |
| 19834 | 11730 | =begin original |
| 19835 | 11731 | |
| 19836 | If the | |
| 11732 | If the repeat count of a field is larger than what the remainder of | |
| 19837 | i | |
| 11733 | the input string allows, repeat count is decreased. If the input string | |
| 19838 | is | |
| 11734 | is longer than one described by the TEMPLATE, the rest is ignored. | |
| 19839 | L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros, | |
| 19840 | or it may raise an exception. | |
| 19841 | If the input string is longer than one described by the TEMPLATE, | |
| 19842 | the remainder of that input string is ignored. | |
| 19843 | 11735 | |
| 19844 | 11736 | =end original |
| 19845 | 11737 | |
| 19846 | ||
| 11738 | フィールドの繰り返し回数が入力文字列の残りより大きい場合、繰り返し回数は | |
| 19847 | 入力文字列の | |
| 11739 | 減らされます。もし入力文字列が TEMPLATE で表現されているものより | |
| 19848 | ||
| 11740 | 大きい場合、残りは無視されます。 | |
| 19849 | L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を | |
| 19850 | 返すこともありますし、例外が発生します。 | |
| 19851 | もし入力文字列が TEMPLATE で表現されているものより大きい場合、 | |
| 19852 | 入力文字列の残りは無視されます。 | |
| 19853 | 11741 | |
| 19854 | 11742 | =begin original |
| 19855 | 11743 | |
| 19856 | See L< | |
| 11744 | See L</pack> for more examples and notes. | |
| 19857 | 11745 | |
| 19858 | 11746 | =end original |
| 19859 | 11747 | |
| 19860 | さらなる例と注意に関しては L< | |
| 11748 | さらなる例と注意に関しては L</pack> を参照してください。 | |
| 19861 | 11749 | |
| 19862 | =item un | |
| 11750 | =item untie VARIABLE | |
| 19863 | X<unshift> | |
| 19864 | 11751 | |
| 19865 | =for Pod::Functions prepend more elements to the beginning of a list | |
| 19866 | ||
| 19867 | 11752 | =begin original |
| 19868 | 11753 | |
| 19869 | ||
| 11754 | Breaks the binding between a variable and a package. (See C<tie>.) | |
| 19870 | L<C<push>|/push ARRAY,LIST>, | |
| 19871 | depending on how you look at it. Prepends list to the front of the | |
| 19872 | array and returns the new number of elements in the array. | |
| 19873 | 11755 | |
| 19874 | 11756 | =end original |
| 19875 | 11757 | |
| 19876 | ||
| 11758 | 変数とパッケージの間の結合を解きます。 | |
| 19877 | ||
| 11759 | (L<tie> を参照してください。) | |
| 19878 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 | |
| 19879 | 11760 | |
| 19880 | | |
| 11761 | =item unshift ARRAY,LIST | |
| 19881 | 11762 | |
| 19882 | 11763 | =begin original |
| 19883 | 11764 | |
| 19884 | ||
| 11765 | Does the opposite of a C<shift>. Or the opposite of a C<push>, | |
| 19885 | ||
| 11766 | depending on how you look at it. Prepends list to the front of the | |
| 19886 | ||
| 11767 | array, and returns the new number of elements in the array. | |
| 19887 | 11768 | |
| 19888 | 11769 | =end original |
| 19889 | 11770 | |
| 19890 | ||
| 11771 | C<shift> の逆操作を行ないます。 | |
| 19891 | ||
| 11772 | 見方を変えれば、C<push>の逆操作とも考えられます。 | |
| 11773 | LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。 | |
| 19892 | 11774 | |
| 19893 | ||
| 11775 | unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/; | |
| 19894 | 11776 | |
| 19895 | Starting with Perl 5.14, an experimental feature allowed | |
| 19896 | L<C<unshift>|/unshift ARRAY,LIST> to take | |
| 19897 | a scalar expression. This experiment has been deemed unsuccessful, and was | |
| 19898 | removed as of Perl 5.24. | |
| 19899 | ||
| 19900 | =end original | |
| 19901 | ||
| 19902 | Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を | |
| 19903 | 取ることが出来るという実験的機能がありました。 | |
| 19904 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 19905 | ||
| 19906 | =item untie VARIABLE | |
| 19907 | X<untie> | |
| 19908 | ||
| 19909 | =for Pod::Functions break a tie binding to a variable | |
| 19910 | ||
| 19911 | 11777 | =begin original |
| 19912 | 11778 | |
| 19913 | ||
| 11779 | Note the LIST is prepended whole, not one element at a time, so the | |
| 19914 | ||
| 11780 | prepended elements stay in the same order. Use C<reverse> to do the | |
| 19915 | ||
| 11781 | reverse. | |
| 19916 | 11782 | |
| 19917 | 11783 | =end original |
| 19918 | 11784 | |
| 19919 | ||
| 11785 | LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。 | |
| 19920 | ||
| 11786 | 逆順に登録するには、C<reverse> を使ってください。 | |
| 19921 | 結合されていない場合は何も起きません。 | |
| 19922 | 11787 | |
| 19923 | 11788 | =item use Module VERSION LIST |
| 19924 | X<use> X<module> X<import> | |
| 19925 | 11789 | |
| 19926 | 11790 | =item use Module VERSION |
| 19927 | 11791 | |
| 19928 | 11792 | =item use Module LIST |
| 19929 | 11793 | |
| 19930 | 11794 | =item use Module |
| 19931 | 11795 | |
| 19932 | 11796 | =item use VERSION |
| 19933 | 11797 | |
| 19934 | =for Pod::Functions load in a module at compile time and import its namespace | |
| 19935 | ||
| 19936 | 11798 | =begin original |
| 19937 | 11799 | |
| 19938 | 11800 | Imports some semantics into the current package from the named module, |
| 19939 | 11801 | generally by aliasing certain subroutine or variable names into your |
| 19940 | 11802 | package. It is exactly equivalent to |
| 19941 | 11803 | |
| 19942 | ||
| 11804 | BEGIN { require Module; import Module LIST; } | |
| 19943 | 11805 | |
| 19944 | 指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; | |
| 19945 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 | |
| 19946 | 実現されています。 | |
| 19947 | これは、以下は等価ですが: | |
| 19948 | ||
| 19949 | BEGIN { require Module; Module->import( LIST ); } | |
| 19950 | ||
| 19951 | =begin original | |
| 19952 | ||
| 19953 | 11806 | except that Module I<must> be a bareword. |
| 19954 | The importation can be made conditional by using the L<if> module. | |
| 19955 | 11807 | |
| 19956 | 11808 | =end original |
| 19957 | 11809 | |
| 19958 | ||
| 11810 | 指定したモジュールから、現在のパッケージにさまざまな内容を | |
| 19959 | インポート | |
| 11811 | インポートします。 | |
| 11812 | 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 | |
| 11813 | 実現されています。これは、 | |
| 11814 | Module が I<単なる単語でなければならない> ことを除けば、 | |
| 19960 | 11815 | |
| 19961 | ||
| 11816 | BEGIN { require Module; import Module LIST; } | |
| 19962 | 11817 | |
| 19963 | ||
| 11818 | と等価です。 | |
| 19964 | v5.24.1, which will be compared to L<C<$^V>|perlvar/$^V> (aka | |
| 19965 | $PERL_VERSION), or a numeric argument of the form 5.024001, which will | |
| 19966 | be compared to L<C<$]>|perlvar/$]>. An exception is raised if VERSION | |
| 19967 | is greater than the version of the current Perl interpreter; Perl will | |
| 19968 | not attempt to parse the rest of the file. Compare with | |
| 19969 | L<C<require>|/require VERSION>, which can do a similar check at run | |
| 19970 | time. Symmetrically, C<no VERSION> allows you to specify that you | |
| 19971 | want a version of Perl older than the specified one. | |
| 19972 | 11819 | |
| 19973 | =end original | |
| 19974 | ||
| 19975 | C<use VERSION> の形式では、VERSION は v5.24.1 のような v-文字列 | |
| 19976 | (L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます) | |
| 19977 | か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で | |
| 19978 | 指定します。 | |
| 19979 | VERSION が Perl の現在のバージョンより大きいと、例外が発生します; | |
| 19980 | Perl はファイルの残りを読み込みません。 | |
| 19981 | L<C<require>|/require VERSION> と似ていますが、これは実行時に | |
| 19982 | チェックされます。 | |
| 19983 | 対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で | |
| 19984 | 動作させたいことを意味します。 | |
| 19985 | ||
| 19986 | 11820 | =begin original |
| 19987 | 11821 | |
| 19988 | ||
| 11822 | VERSION, which can be specified as a literal of the form v5.6.1, demands | |
| 19989 | ||
| 11823 | that the current version of Perl (C<$^V> or $PERL_VERSION) be at least | |
| 19990 | ||
| 11824 | as recent as that version. (For compatibility with older versions of Perl, | |
| 19991 | ||
| 11825 | a numeric literal will also be interpreted as VERSION.) If the version | |
| 11826 | of the running Perl interpreter is less than VERSION, then an error | |
| 11827 | message is printed and Perl exits immediately without attempting to | |
| 11828 | parse the rest of the file. Compare with L</require>, which can do a | |
| 11829 | similar check at run time. | |
| 19992 | 11830 | |
| 19993 | 11831 | =end original |
| 19994 | 11832 | |
| 19995 | VERSION | |
| 11833 | VERSION (v5.6.1 の形のリテラルとしても指定できます)を指定すると、 | |
| 19996 | ||
| 11834 | 現在の Perl のバージョン (C<$^V> or $PERL_VERSION) が少なくとも | |
| 19997 | ||
| 11835 | 指定されたものよりも最近であることを要求します。 | |
| 19998 | ||
| 11836 | (古いバージョンの Perl との互換性のために、数値リテラルも | |
| 19999 | ||
| 11837 | VERSIONとして解釈されます。) | |
| 11838 | もし動作している Perl インタプリタのバージョンが VERSION より低い場合、 | |
| 11839 | エラーメッセージが表示され、Perl はファイルの残りをパースせずに | |
| 11840 | 直ちに終了します。 | |
| 11841 | 似たようなチェックを実行時に行える L</require> と比較してください。 | |
| 20000 | 11842 | |
| 20001 | ||
| 11843 | use v5.6.1; # compile time version check | |
| 11844 | use 5.6.1; # ditto | |
| 11845 | use 5.005_03; # float version allowed for compatibility | |
| 20002 | 11846 | |
| 20003 | use v5.24.1; # compile time version check | |
| 20004 | use 5.24.1; # ditto | |
| 20005 | use 5.024_001; # ditto; older syntax compatible with perl 5.6 | |
| 20006 | ||
| 20007 | =end original | |
| 20008 | ||
| 20009 | use v5.24.1; # 実行時バージョンチェック | |
| 20010 | use 5.24.1; # 同様 | |
| 20011 | use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法 | |
| 20012 | ||
| 20013 | 11847 | =begin original |
| 20014 | 11848 | |
| 20015 | 11849 | This is often useful if you need to check the current Perl version before |
| 20016 | ||
| 11850 | C<use>ing library modules that have changed in incompatible ways from | |
| 20017 | ||
| 11851 | older versions of Perl. (We try not to do this more than we have to.) | |
| 20018 | (We try not to do this more than we have to.) | |
| 20019 | 11852 | |
| 20020 | 11853 | =end original |
| 20021 | 11854 | |
| 20022 | これは古いバージョンの Perl | |
| 11855 | これは古いバージョンの Perl から互換性のない形で変更されたライブラリ | |
| 20023 | ||
| 11856 | モジュール(我々は必要な場合以外にそのようなことがないように | |
| 11857 | 努力していますが)を C<use> する前に、現在の Perl のバージョンを | |
| 20024 | 11858 | 調べたい場合に有用です。 |
| 20025 | (我々は必要な場合以外にそのようなことがないように努力していますが。) | |
| 20026 | 11859 | |
| 20027 | 11860 | =begin original |
| 20028 | 11861 | |
| 20029 | ||
| 11862 | The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The | |
| 20030 | ||
| 11863 | C<require> makes sure the module is loaded into memory if it hasn't been | |
| 20031 | ||
| 11864 | yet. The C<import> is not a builtin--it's just an ordinary static method | |
| 20032 | Similarly, if the specified Perl version is greater than or equal to | |
| 20033 | 5.12.0, strictures are enabled lexically as | |
| 20034 | with L<C<use strict>|strict>. Any explicit use of | |
| 20035 | C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes | |
| 20036 | before it. Later use of C<use VERSION> | |
| 20037 | will override all behavior of a previous | |
| 20038 | C<use VERSION>, possibly removing the C<strict> and C<feature> added by | |
| 20039 | C<use VERSION>. C<use VERSION> does not | |
| 20040 | load the F<feature.pm> or F<strict.pm> | |
| 20041 | files. | |
| 20042 | ||
| 20043 | =end original | |
| 20044 | ||
| 20045 | C<use VERSION> は、L<feature> プラグマで定義されたように、指定された | |
| 20046 | バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の | |
| 20047 | 束にない機能をレキシカルに無効にします。 | |
| 20048 | L<feature> を参照してください。 | |
| 20049 | 同様に、指定された Perl のバージョンが 5.12.0 以上の場合、 | |
| 20050 | 制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。 | |
| 20051 | 明示的に C<use strict> や C<no strict> を使うと、例え先に | |
| 20052 | 指定されていたとしても、C<use VERSION> を上書きします。 | |
| 20053 | 後から使った C<use VERSION> は先の | |
| 20054 | C<use VERSION> の全ての振る舞いを上書きするので、 | |
| 20055 | C<use VERSION> によって追加された C<strict> と C<feature> を | |
| 20056 | 削除することがあります。 | |
| 20057 | C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。 | |
| 20058 | ||
| 20059 | =begin original | |
| 20060 | ||
| 20061 | The C<BEGIN> forces the L<C<require>|/require VERSION> and | |
| 20062 | L<C<import>|/import LIST> to happen at compile time. The | |
| 20063 | L<C<require>|/require VERSION> makes sure the module is loaded into | |
| 20064 | memory if it hasn't been yet. The L<C<import>|/import LIST> is not a | |
| 20065 | builtin; it's just an ordinary static method | |
| 20066 | 11865 | call into the C<Module> package to tell the module to import the list of |
| 20067 | 11866 | features back into the current package. The module can implement its |
| 20068 | ||
| 11867 | C<import> method any way it likes, though most modules just choose to | |
| 20069 | ||
| 11868 | derive their C<import> method via inheritance from the C<Exporter> class that | |
| 20070 | i | |
| 11869 | is defined in the C<Exporter> module. See L<Exporter>. If no C<import> | |
| 20071 | ||
| 11870 | method can be found then the call is skipped. | |
| 20072 | L<C<import>|/import LIST> method can be found, then the call is skipped, | |
| 20073 | even if there is an AUTOLOAD method. | |
| 20074 | 11871 | |
| 20075 | 11872 | =end original |
| 20076 | 11873 | |
| 20077 | C<BEGIN> によって、 | |
| 11874 | C<BEGIN> によって、C<require> や C<import> は、コンパイル時に | |
| 20078 | L<C<import>|/import LIST> は、コンパイル時に | |
| 20079 | 11875 | 実行されることになります。 |
| 20080 | ||
| 11876 | C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。 | |
| 20081 | ||
| 11877 | C<import> は、組込みの関数ではなく、さまざまな機能を現在のパッケージに | |
| 20082 | ||
| 11878 | インポートするように C<Module> パッケージに伝えるために呼ばれる、 | |
| 20083 | ||
| 11879 | 通常の静的メソッドです。 | |
| 20084 | ||
| 11880 | モジュール側では、C<import> メソッドをどのようにでも実装することが | |
| 20085 | モジュール | |
| 11881 | できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、 | |
| 20086 | ||
| 11882 | C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように | |
| 20087 | ||
| 11883 | しています。 | |
| 20088 | C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを | |
| 20089 | 行なうようにしています。 | |
| 20090 | 11884 | L<Exporter>モジュールを参照してください。 |
| 20091 | ||
| 11885 | C<import>メソッドが見つからなかった場合、呼び出しはスキップされます。 | |
| 20092 | あったとしても呼び出しはスキップされます。 | |
| 20093 | 11886 | |
| 20094 | 11887 | =begin original |
| 20095 | 11888 | |
| 20096 | If you do not want to call the package's | |
| 11889 | If you do not want to call the package's C<import> method (for instance, | |
| 20097 | method (for instance, | |
| 20098 | 11890 | to stop your namespace from being altered), explicitly supply the empty list: |
| 20099 | 11891 | |
| 20100 | 11892 | =end original |
| 20101 | 11893 | |
| 20102 | パッケージの | |
| 11894 | パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を | |
| 20103 | ||
| 11895 | 変更したくない場合など)は、明示的に空リストを指定してください: | |
| 20104 | 11896 | |
| 20105 | 11897 | use Module (); |
| 20106 | 11898 | |
| 20107 | 11899 | =begin original |
| 20108 | 11900 | |
| 20109 | 11901 | That is exactly equivalent to |
| 20110 | 11902 | |
| 20111 | 11903 | =end original |
| 20112 | 11904 | |
| 20113 | 11905 | これは以下と完全に等価です: |
| 20114 | 11906 | |
| 20115 | 11907 | BEGIN { require Module } |
| 20116 | 11908 | |
| 20117 | 11909 | =begin original |
| 20118 | 11910 | |
| 20119 | 11911 | If the VERSION argument is present between Module and LIST, then the |
| 20120 | ||
| 11912 | C<use> will call the VERSION method in class Module with the given | |
| 20121 | ||
| 11913 | version as an argument. The default VERSION method, inherited from | |
| 11914 | the UNIVERSAL class, croaks if the given version is larger than the | |
| 11915 | value of the variable C<$Module::VERSION>. | |
| 20122 | 11916 | |
| 20123 | 11917 | =end original |
| 20124 | 11918 | |
| 20125 | Module と LIST の間に VERSION 引数がある場合、 | |
| 11919 | Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの | |
| 20126 | ||
| 11920 | VERSION メソッドを、与えられたバージョンを引数として呼び出します。 | |
| 20127 | ||
| 11921 | デフォルトの VERSION メソッドは、 UNIVERSAL クラスから継承したもので、 | |
| 20128 | ||
| 20129 | use Module 12.34; | |
| 20130 | ||
| 20131 | =begin original | |
| 20132 | ||
| 20133 | is equivalent to: | |
| 20134 | ||
| 20135 | =end original | |
| 20136 | ||
| 20137 | は以下と等価です: | |
| 20138 | ||
| 20139 | BEGIN { require Module; Module->VERSION(12.34) } | |
| 20140 | ||
| 20141 | =begin original | |
| 20142 | ||
| 20143 | The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>, | |
| 20144 | inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given | |
| 20145 | version is larger than the value of the variable C<$Module::VERSION>. | |
| 20146 | ||
| 20147 | =end original | |
| 20148 | ||
| 20149 | デフォルトの | |
| 20150 | L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、 | |
| 20151 | L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、 | |
| 20152 | 11922 | 与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に |
| 20153 | 11923 | 警告を出します。 |
| 20154 | 11924 | |
| 20155 | 11925 | =begin original |
| 20156 | 11926 | |
| 20157 | ||
| 11927 | Again, there is a distinction between omitting LIST (C<import> called | |
| 20158 | ||
| 11928 | with no arguments) and an explicit empty LIST C<()> (C<import> not | |
| 20159 | ||
| 11929 | called). Note that there is no comma after VERSION! | |
| 20160 | look like a version literal will be parsed as the start of the LIST. | |
| 20161 | Nevertheless, many attempts to use an arbitrary expression as a VERSION | |
| 20162 | argument will appear to work, because L<Exporter>'s C<import> method | |
| 20163 | handles numeric arguments specially, performing version checks rather | |
| 20164 | than treating them as things to export. | |
| 20165 | 11930 | |
| 20166 | 11931 | =end original |
| 20167 | 11932 | |
| 20168 | ||
| 11933 | 繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと | |
| 20169 | ||
| 11934 | 明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは | |
| 20170 | ||
| 11935 | 違います。 | |
| 20171 | バージョンリテラルのように見えないものは LIST の開始としてパースされます。 | |
| 20172 | それにも関わらず、VERSION 引数として任意の式を使おうとする | |
| 20173 | 多くの試みは動作しているように見えます; なぜなら | |
| 20174 | L<Exporter> の C<import> メソッドは数値引数を特別に扱い、 | |
| 20175 | それらをエクスポートするべきものと扱わずにバージョンチェックを | |
| 20176 | 実行するからです。 | |
| 20177 | ||
| 20178 | =begin original | |
| 20179 | ||
| 20180 | Again, there is a distinction between omitting LIST (L<C<import>|/import | |
| 20181 | LIST> called with no arguments) and an explicit empty LIST C<()> | |
| 20182 | (L<C<import>|/import LIST> not called). Note that there is no comma | |
| 20183 | after VERSION! | |
| 20184 | ||
| 20185 | =end original | |
| 20186 | ||
| 20187 | 繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで | |
| 20188 | 呼び出される)ことと明示的に空の LIST C<()> を指定する | |
| 20189 | (L<C<import>|/import LIST> は呼び出されない)ことは違います。 | |
| 20190 | 11936 | VERSION の後ろにカンマが不要なことに注意してください! |
| 20191 | 11937 | |
| 20192 | 11938 | =begin original |
| 20193 | 11939 | |
| 20194 | 11940 | Because this is a wide-open interface, pragmas (compiler directives) |
| 20195 | are also implemented this way. | |
| 11941 | are also implemented this way. Currently implemented pragmas are: | |
| 20196 | pragmas are: | |
| 20197 | 11942 | |
| 20198 | 11943 | =end original |
| 20199 | 11944 | |
| 20200 | 11945 | これは、広く公開されているインタフェースですので、 |
| 20201 | 11946 | プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 |
| 20202 | 現在実装されているプラグマには、以下の | |
| 11947 | 現在実装されているプラグマには、以下のものがあります: | |
| 20203 | 11948 | |
| 20204 | 11949 | use constant; |
| 20205 | 11950 | use diagnostics; |
| 20206 | 11951 | use integer; |
| 20207 | 11952 | use sigtrap qw(SEGV BUS); |
| 20208 | 11953 | use strict qw(subs vars refs); |
| 20209 | 11954 | use subs qw(afunc blurfl); |
| 20210 | 11955 | use warnings qw(all); |
| 20211 | use sort qw(stable); | |
| 20212 | 11956 | |
| 20213 | 11957 | =begin original |
| 20214 | 11958 | |
| 20215 | 11959 | Some of these pseudo-modules import semantics into the current |
| 20216 | block scope (like | |
| 11960 | block scope (like C<strict> or C<integer>, unlike ordinary modules, | |
| 20217 | ||
| 11961 | which import symbols into the current package (which are effective | |
| 20218 | ||
| 11962 | through the end of the file). | |
| 20219 | 11963 | |
| 20220 | 11964 | =end original |
| 20221 | 11965 | |
| 20222 | 11966 | 通常のモジュールが、現在のパッケージにシンボルをインポートする |
| 20223 | (これは、ファイルの終わりまで有効です) のに対して、 | |
| 11967 | (これは、ファイルの終わりまで有効です) のに対して、 | |
| 20224 | 一部( | |
| 11968 | これらの擬似モジュールの一部(C<strict> や C<integer> など)は、 | |
| 20225 | ブロックスコープにインポートを行ないます。 | |
| 11969 | 現在のブロックスコープにインポートを行ないます。 | |
| 20226 | 11970 | |
| 20227 | 11971 | =begin original |
| 20228 | 11972 | |
| 20229 | ||
| 11973 | There's a corresponding C<no> command that unimports meanings imported | |
| 20230 | ||
| 11974 | by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>. | |
| 20231 | In particular, putting a L<C<use>|/use Module VERSION LIST> inside the | |
| 20232 | false branch of a conditional doesn't prevent it | |
| 20233 | from being processed. If a module or pragma only needs to be loaded | |
| 20234 | conditionally, this can be done using the L<if> pragma: | |
| 20235 | 11975 | |
| 20236 | 11976 | =end original |
| 20237 | 11977 | |
| 20238 | ||
| 11978 | これに対して、C<no> コマンドという、C<use> によってインポートされたものを、 | |
| 20239 | ||
| 11979 | インポートされていないことにするものがあります。 | |
| 20240 | ||
| 11980 | つまり、C<import> の代わりに C<unimport Module LIST> を呼び出します。 | |
| 20241 | 書いても、処理を妨げられません。 | |
| 20242 | モジュールやプラグマを条件付きでのみ読み込みたい場合、 | |
| 20243 | L<if> プラグマを使って実現できます: | |
| 20244 | 11981 | |
| 20245 | use if $] < 5.008, "utf8"; | |
| 20246 | use if WANT_WARNINGS, warnings => qw(all); | |
| 20247 | ||
| 20248 | =begin original | |
| 20249 | ||
| 20250 | There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration | |
| 20251 | that unimports meanings imported by L<C<use>|/use Module VERSION LIST>, | |
| 20252 | i.e., it calls C<< Module->unimport(LIST) >> instead of | |
| 20253 | L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST> | |
| 20254 | does with VERSION, an omitted or empty LIST, | |
| 20255 | or no unimport method being found. | |
| 20256 | ||
| 20257 | =end original | |
| 20258 | ||
| 20259 | これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、 | |
| 20260 | L<C<use>|/use Module VERSION LIST> によってインポートされたものを、 | |
| 20261 | インポートされていないことにするものがあります; つまり、 | |
| 20262 | L<C<import>|/import LIST> の代わりに | |
| 20263 | C<< Module->unimport(LIST) >> を呼び出します。 | |
| 20264 | これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない | |
| 20265 | 場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。 | |
| 20266 | ||
| 20267 | 11982 | no integer; |
| 20268 | 11983 | no strict 'refs'; |
| 20269 | 11984 | no warnings; |
| 20270 | 11985 | |
| 20271 | 11986 | =begin original |
| 20272 | 11987 | |
| 20273 | C | |
| 11988 | If no C<unimport> method can be found the call fails with a fatal error. | |
| 20274 | MODULE VERSION LIST>. It is | |
| 20275 | I<only> meant to be used to assert that the running Perl is of a earlier | |
| 20276 | version than its argument and I<not> to undo the feature-enabling side effects | |
| 20277 | of C<use VERSION>. | |
| 20278 | 11989 | |
| 20279 | 11990 | =end original |
| 20280 | 11991 | |
| 20281 | ||
| 11992 | C<unimport> メソッドが見つからなかった場合、呼び出しは致命的エラーで | |
| 20282 | ||
| 11993 | 失敗します。 | |
| 20283 | これは引数で指定されたバージョンよりも前の Perl で実行されたときに | |
| 20284 | アサートされることを意味する I<だけ> で、C<use VERSION> によって | |
| 20285 | 有効にされた副作用をなかったことにするもの I<ではありません>。 | |
| 20286 | 11994 | |
| 20287 | 11995 | =begin original |
| 20288 | 11996 | |
| 20289 | 11997 | See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun> |
| 20290 | for the C<-M> and C<-m> command-line options to | |
| 11998 | for the C<-M> and C<-m> command-line options to perl that give C<use> | |
| 20291 | ||
| 11999 | functionality from the command-line. | |
| 20292 | 12000 | |
| 20293 | 12001 | =end original |
| 20294 | 12002 | |
| 20295 | 12003 | 標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。 |
| 20296 | コマンドラインから | |
| 12004 | コマンドラインから C<use> 機能を指定するための C<-M> と C<-m> の | |
| 20297 | ||
| 12005 | コマンドラインオプションについては L<perlrun> を参照して下さい。 | |
| 20298 | コマンドラインオプションについては L<perlrun> を参照してください。 | |
| 20299 | 12006 | |
| 20300 | 12007 | =item utime LIST |
| 20301 | X<utime> | |
| 20302 | 12008 | |
| 20303 | =for Pod::Functions set a file's last access and modify times | |
| 20304 | ||
| 20305 | 12009 | =begin original |
| 20306 | 12010 | |
| 20307 | 12011 | Changes the access and modification times on each file of a list of |
| 20308 | files. The first two elements of the list must be the NUMERIC access | |
| 12012 | files. The first two elements of the list must be the NUMERICAL access | |
| 20309 | 12013 | and modification times, in that order. Returns the number of files |
| 20310 | 12014 | successfully changed. The inode change time of each file is set |
| 20311 | to the current time. | |
| 12015 | to the current time. This code has the same effect as the C<touch> | |
| 20312 | ||
| 12016 | command if the files already exist: | |
| 20313 | the user running the program: | |
| 20314 | 12017 | |
| 20315 | 12018 | =end original |
| 20316 | 12019 | |
| 20317 | 12020 | ファイルのアクセス時刻と修正(modification) 時刻を変更します。 |
| 20318 | LIST の最初の | |
| 12021 | LIST の最初の 2 つの要素に、数値で表わしたアクセス時刻と修正時刻を | |
| 20319 | 12022 | 順に指定します。 |
| 12023 | LIST の残りの要素が、変更の対象となるファイルです。 | |
| 20320 | 12024 | 変更に成功したファイルの数を返します。 |
| 20321 | 12025 | 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 |
| 20322 | ||
| 12026 | C<touch> コマンドの例です: | |
| 20323 | 実行しているプログラムに従っているなら、 | |
| 20324 | Unix の L<touch(1)> コマンドと同じ効果があります。 | |
| 20325 | 12027 | |
| 20326 | 12028 | #!/usr/bin/perl |
| 20327 | | |
| 12029 | $now = time; | |
| 20328 | utime $ | |
| 12030 | utime $now, $now, @ARGV; | |
| 20329 | 12031 | |
| 20330 | =begin original | |
| 20331 | ||
| 20332 | Since Perl 5.8.0, if the first two elements of the list are | |
| 20333 | L<C<undef>|/undef EXPR>, | |
| 20334 | the L<utime(2)> syscall from your C library is called with a null second | |
| 20335 | argument. On most systems, this will set the file's access and | |
| 20336 | modification times to the current time (i.e., equivalent to the example | |
| 20337 | above) and will work even on files you don't own provided you have write | |
| 20338 | permission: | |
| 20339 | ||
| 20340 | =end original | |
| 20341 | ||
| 20342 | Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である | |
| 20343 | 場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として | |
| 20344 | 呼び出します。 | |
| 20345 | ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を | |
| 20346 | 現在の時刻にセットし(つまり、上記の例と等価です)、 | |
| 20347 | 書き込み権限があれば他のユーザーのファイルに対しても動作します。 | |
| 20348 | ||
| 20349 | for my $file (@ARGV) { | |
| 20350 | utime(undef, undef, $file) | |
| 20351 | || warn "Couldn't touch $file: $!"; | |
| 20352 | } | |
| 20353 | ||
| 20354 | =begin original | |
| 20355 | ||
| 20356 | Under NFS this will use the time of the NFS server, not the time of | |
| 20357 | the local machine. If there is a time synchronization problem, the | |
| 20358 | NFS server and local machine will have different times. The Unix | |
| 20359 | L<touch(1)> command will in fact normally use this form instead of the | |
| 20360 | one shown in the first example. | |
| 20361 | ||
| 20362 | =end original | |
| 20363 | ||
| 20364 | NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が | |
| 20365 | 使われます。 | |
| 20366 | 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に | |
| 20367 | なっている場合があります。 | |
| 20368 | 実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、 | |
| 20369 | この形を使います。 | |
| 20370 | ||
| 20371 | =begin original | |
| 20372 | ||
| 20373 | Passing only one of the first two elements as L<C<undef>|/undef EXPR> is | |
| 20374 | equivalent to passing a 0 and will not have the effect described when | |
| 20375 | both are L<C<undef>|/undef EXPR>. This also triggers an | |
| 20376 | uninitialized warning. | |
| 20377 | ||
| 20378 | =end original | |
| 20379 | ||
| 20380 | 最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その | |
| 20381 | 要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を | |
| 20382 | 渡した時と同じ効果ではありません。 | |
| 20383 | この場合は、未初期化の警告が出ます。 | |
| 20384 | ||
| 20385 | =begin original | |
| 20386 | ||
| 20387 | On systems that support L<futimes(2)>, you may pass filehandles among the | |
| 20388 | files. On systems that don't support L<futimes(2)>, passing filehandles raises | |
| 20389 | an exception. Filehandles must be passed as globs or glob references to be | |
| 20390 | recognized; barewords are considered filenames. | |
| 20391 | ||
| 20392 | =end original | |
| 20393 | ||
| 20394 | L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として | |
| 20395 | 渡せます。 | |
| 20396 | L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと | |
| 20397 | 例外が発生します。 | |
| 20398 | ファイルハンドルを認識させるためには、グロブまたはリファレンスとして | |
| 20399 | 渡されなければなりません; 裸の単語はファイル名として扱われます。 | |
| 20400 | ||
| 20401 | =begin original | |
| 20402 | ||
| 20403 | Portability issues: L<perlport/utime>. | |
| 20404 | ||
| 20405 | =end original | |
| 20406 | ||
| 20407 | 移植性の問題: L<perlport/utime>。 | |
| 20408 | ||
| 20409 | 12032 | =item values HASH |
| 20410 | X<values> | |
| 20411 | 12033 | |
| 20412 | =item values ARRAY | |
| 20413 | ||
| 20414 | =for Pod::Functions return a list of the values in a hash | |
| 20415 | ||
| 20416 | 12034 | =begin original |
| 20417 | 12035 | |
| 20418 | ||
| 12036 | Returns a list consisting of all the values of the named hash. (In a | |
| 20419 | ||
| 12037 | scalar context, returns the number of values.) The values are | |
| 20420 | ||
| 12038 | returned in an apparently random order. The actual random order is | |
| 20421 | ||
| 12039 | subject to change in future versions of perl, but it is guaranteed to | |
| 12040 | be the same order as either the C<keys> or C<each> function would | |
| 12041 | produce on the same (unmodified) hash. | |
| 20422 | 12042 | |
| 20423 | 12043 | =end original |
| 20424 | 12044 | |
| 20425 | ||
| 12045 | 指定したハッシュのすべての value からなるリストを返します。 | |
| 20426 | ||
| 12046 | (スカラコンテキストでは、value の数を返します。) | |
| 20427 | ||
| 12047 | 返される value の順序は、見た目にばらばらなものです。 | |
| 20428 | ||
| 12048 | 実際のランダムな順序は将来のバージョンの perl では変わる可能性が | |
| 12049 | ありますが、同じ(変更されていない)ハッシュに対して、 | |
| 12050 | C<keys>関数や C<each>関数が返すものと同じ順序であることは保証されます。 | |
| 20429 | 12051 | |
| 20430 | 12052 | =begin original |
| 20431 | 12053 | |
| 20432 | Hash entries are returned in an apparently random order. The actual random | |
| 20433 | order is specific to a given hash; the exact same series of operations | |
| 20434 | on two hashes may result in a different order for each hash. Any insertion | |
| 20435 | into the hash may change the order, as will any deletion, with the exception | |
| 20436 | that the most recent key returned by L<C<each>|/each HASH> or | |
| 20437 | L<C<keys>|/keys HASH> may be deleted without changing the order. So | |
| 20438 | long as a given hash is unmodified you may rely on | |
| 20439 | L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and | |
| 20440 | L<C<each>|/each HASH> to repeatedly return the same order | |
| 20441 | as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for | |
| 20442 | details on why hash order is randomized. Aside from the guarantees | |
| 20443 | provided here the exact details of Perl's hash algorithm and the hash | |
| 20444 | traversal order are subject to change in any release of Perl. Tied hashes | |
| 20445 | may behave differently to Perl's hashes with respect to changes in order on | |
| 20446 | insertion and deletion of items. | |
| 20447 | ||
| 20448 | =end original | |
| 20449 | ||
| 20450 | ハッシュ要素は見かけ上、ランダムな順序で返されます。 | |
| 20451 | 実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の | |
| 20452 | 操作を行っても、ハッシュによって異なった順序になります。 | |
| 20453 | ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、 | |
| 20454 | L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも | |
| 20455 | 最近のキーは順序を変えることなく削除できます。 | |
| 20456 | ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, | |
| 20457 | L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。 | |
| 20458 | なぜハッシュの順序がランダム化されているかの詳細については | |
| 20459 | L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。 | |
| 20460 | ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の | |
| 20461 | 正確な詳細は Perl のリリースによって変更される可能性があります。 | |
| 20462 | tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと | |
| 20463 | 異なった振る舞いをします。 | |
| 20464 | ||
| 20465 | =begin original | |
| 20466 | ||
| 20467 | As a side effect, calling L<C<values>|/values HASH> resets the HASH or | |
| 20468 | ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the | |
| 20469 | values. In particular, | |
| 20470 | calling L<C<values>|/values HASH> in void context resets the iterator | |
| 20471 | with no other overhead. | |
| 20472 | ||
| 20473 | =end original | |
| 20474 | ||
| 20475 | 副作用として、L<C<values>|/values HASH> を呼び出すと、 | |
| 20476 | 値を取り出す前に HASH や ARRAY の | |
| 20477 | 内部反復子(L<C<each>|/each HASH> 参照)をリセットします。 | |
| 20478 | 特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の | |
| 20479 | オーバーヘッドなしで反復子をリセットします。 | |
| 20480 | ||
| 20481 | =begin original | |
| 20482 | ||
| 20483 | Apart from resetting the iterator, | |
| 20484 | C<values @array> in list context is the same as plain C<@array>. | |
| 20485 | (We recommend that you use void context C<keys @array> for this, but | |
| 20486 | reasoned that taking C<values @array> out would require more | |
| 20487 | documentation than leaving it in.) | |
| 20488 | ||
| 20489 | =end original | |
| 20490 | ||
| 20491 | 反復子をリセットするということを除けば、 | |
| 20492 | リストコンテキストでの C<values @array> は単なる C<@array> と同じです。 | |
| 20493 | この目的のためには無効コンテキストで C<keys @array> を使うことを | |
| 20494 | お勧めしますが、C<values @array> を取り出すにはそのままにするよりも | |
| 20495 | より多くの文書が必要だと判断しました。) | |
| 20496 | ||
| 20497 | =begin original | |
| 20498 | ||
| 20499 | 12054 | Note that the values are not copied, which means modifying them will |
| 20500 | 12055 | modify the contents of the hash: |
| 20501 | 12056 | |
| 20502 | 12057 | =end original |
| 20503 | 12058 | |
| 20504 | 12059 | 値はコピーされないので、返されたリストを変更すると |
| 20505 | 12060 | ハッシュの中身が変更されることに注意してください。 |
| 20506 | 12061 | |
| 20507 | for (values %hash) | |
| 12062 | for (values %hash) { s/foo/bar/g } # modifies %hash values | |
| 20508 | for (@hash{keys %hash}) { s/foo/bar/g } # same | |
| 12063 | for (@hash{keys %hash}) { s/foo/bar/g } # same | |
| 20509 | 12064 | |
| 20510 | 12065 | =begin original |
| 20511 | 12066 | |
| 20512 | ||
| 12067 | As a side effect, calling values() resets the HASH's internal iterator. | |
| 20513 | ||
| 12068 | See also C<keys>, C<each>, and C<sort>. | |
| 20514 | scalar expression. This experiment has been deemed unsuccessful, and was | |
| 20515 | removed as of Perl 5.24. | |
| 20516 | 12069 | |
| 20517 | 12070 | =end original |
| 20518 | 12071 | |
| 20519 | ||
| 12072 | 副作用として、values() を呼び出すと HASH の内部イテレータをリセットします。 | |
| 20520 | ||
| 12073 | C<keys>, C<each>, C<sort> も参照してください。 | |
| 20521 | この実験は失敗と見なされ、Perl 5.24 で削除されました。 | |
| 20522 | 12074 | |
| 20523 | =begin original | |
| 20524 | ||
| 20525 | To avoid confusing would-be users of your code who are running earlier | |
| 20526 | versions of Perl with mysterious syntax errors, put this sort of thing at | |
| 20527 | the top of your file to signal that your code will work I<only> on Perls of | |
| 20528 | a recent vintage: | |
| 20529 | ||
| 20530 | =end original | |
| 20531 | ||
| 20532 | あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な | |
| 20533 | 文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で | |
| 20534 | I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを | |
| 20535 | 書いてください: | |
| 20536 | ||
| 20537 | use 5.012; # so keys/values/each work on arrays | |
| 20538 | ||
| 20539 | =begin original | |
| 20540 | ||
| 20541 | See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and | |
| 20542 | L<C<sort>|/sort SUBNAME LIST>. | |
| 20543 | ||
| 20544 | =end original | |
| 20545 | ||
| 20546 | L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も | |
| 20547 | 参照してください。 | |
| 20548 | ||
| 20549 | 12075 | =item vec EXPR,OFFSET,BITS |
| 20550 | X<vec> X<bit> X<bit vector> | |
| 20551 | 12076 | |
| 20552 | =for Pod::Functions test or set particular bits in a string | |
| 20553 | ||
| 20554 | 12077 | =begin original |
| 20555 | 12078 | |
| 20556 | 12079 | Treats the string in EXPR as a bit vector made up of elements of |
| 20557 | width BITS and returns the value of the element specified by OFFSET | |
| 12080 | width BITS, and returns the value of the element specified by OFFSET | |
| 20558 | 12081 | as an unsigned integer. BITS therefore specifies the number of bits |
| 20559 | 12082 | that are reserved for each element in the bit vector. This must |
| 20560 | 12083 | be a power of two from 1 to 32 (or 64, if your platform supports |
| 20561 | 12084 | that). |
| 20562 | 12085 | |
| 20563 | 12086 | =end original |
| 20564 | 12087 | |
| 20565 | 12088 | 文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、 |
| 12089 | OFFSET で指定される要素の値を返します。 | |
| 20566 | 12090 | OFFSET で指定された要素を符号なし整数として返します。 |
| 20567 | 12091 | 従って、 BITS はビットベクターの中の各要素について予約されるビット数です。 |
| 20568 | 12092 | BIT は、1 から 32 まで(プラットホームが |
| 20569 | 12093 | 対応していれば 64 まで) の 2 のべき乗でなければなりません。 |
| 20570 | 12094 | |
| 20571 | 12095 | =begin original |
| 20572 | 12096 | |
| 20573 | If BITS is 8, "elements" coincide with bytes of the input string. | |
| 12097 | If BITS is 8, "elements" coincide with bytes of the input string. | |
| 20574 | 12098 | |
| 20575 | 12099 | =end original |
| 20576 | 12100 | |
| 20577 | 12101 | BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。 |
| 20578 | 12102 | |
| 20579 | 12103 | =begin original |
| 20580 | 12104 | |
| 20581 | 12105 | If BITS is 16 or more, bytes of the input string are grouped into chunks |
| 20582 | 12106 | of size BITS/8, and each group is converted to a number as with |
| 20583 | ||
| 12107 | pack()/unpack() with big-endian formats C<n>/C<N> (and analogously | |
| 20584 | ||
| 12108 | for BITS==64). See L<"pack"> for details. | |
| 20585 | L<C<pack>|/pack TEMPLATE,LIST> for details. | |
| 20586 | 12109 | |
| 20587 | 12110 | =end original |
| 20588 | 12111 | |
| 20589 | 12112 | BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに |
| 20590 | グループ化され、各グループは | |
| 12113 | グループ化され、各グループは pack()/unpack() のビッグエンディアン | |
| 20591 | L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン | |
| 20592 | 12114 | フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。 |
| 20593 | 詳細は L< | |
| 12115 | 詳細は L<"pack"> を参照してください。 | |
| 20594 | 12116 | |
| 20595 | 12117 | =begin original |
| 20596 | 12118 | |
| 20597 | 12119 | If bits is 4 or less, the string is broken into bytes, then the bits |
| 20598 | 12120 | of each byte are broken into 8/BITS groups. Bits of a byte are |
| 20599 | 12121 | numbered in a little-endian-ish way, as in C<0x01>, C<0x02>, |
| 20600 | 12122 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example, |
| 20601 | 12123 | breaking the single input byte C<chr(0x36)> into two groups gives a list |
| 20602 | 12124 | C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>. |
| 20603 | 12125 | |
| 20604 | 12126 | =end original |
| 20605 | 12127 | |
| 20606 | 12128 | BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは |
| 20607 | 12129 | 8/BITS 個のグループに分割されます。 |
| 20608 | 12130 | ビットはリトルエンディアン風に、C<0x01>, C<0x02>, |
| 20609 | 12131 | C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。 |
| 20610 | 例えば、入力バイト C<chr(0x36)> を | |
| 12132 | 例えば、入力バイト C<chr(0x36)> を 2 つのグループに分割すると、 | |
| 20611 | C<(0x6, 0x3)> になります | |
| 12133 | C<(0x6, 0x3)> になります。 | |
| 20612 | なります。 | |
| 12134 | 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> になります。 | |
| 20613 | 12135 | |
| 20614 | 12136 | =begin original |
| 20615 | 12137 | |
| 20616 | ||
| 12138 | C<vec> may also be assigned to, in which case parentheses are needed | |
| 20617 | parentheses are needed | |
| 20618 | 12139 | to give the expression the correct precedence as in |
| 20619 | 12140 | |
| 20620 | 12141 | =end original |
| 20621 | 12142 | |
| 20622 | ||
| 12143 | 左辺値として、代入の対象にすることもできます。 | |
| 20623 | ||
| 12144 | この場合、式を正しく先行させるために以下のように括弧が必要です。 | |
| 20624 | 先行させるために以下のように括弧が必要です: | |
| 20625 | 12145 | |
| 20626 | 12146 | vec($image, $max_x * $x + $y, 8) = 3; |
| 20627 | 12147 | |
| 20628 | 12148 | =begin original |
| 20629 | 12149 | |
| 20630 | 12150 | If the selected element is outside the string, the value 0 is returned. |
| 20631 | 12151 | If an element off the end of the string is written to, Perl will first |
| 20632 | 12152 | extend the string with sufficiently many zero bytes. It is an error |
| 20633 | to try to write off the beginning of the string (i.e. | |
| 12153 | to try to write off the beginning of the string (i.e. negative OFFSET). | |
| 20634 | 12154 | |
| 20635 | 12155 | =end original |
| 20636 | 12156 | |
| 20637 | 12157 | 選択された要素が文字列の外側だった場合、値 0 が返されます。 |
| 20638 | 12158 | 文字列の最後よりも後ろの要素に書き込もうとした場合、 |
| 20639 | 12159 | Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。 |
| 20640 | 12160 | 文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった) |
| 20641 | 12161 | 場合はエラーとなります。 |
| 20642 | 12162 | |
| 20643 | 12163 | =begin original |
| 20644 | 12164 | |
| 20645 | ||
| 12165 | The string should not contain any character with the value > 255 (which | |
| 20646 | ||
| 12166 | can only happen if you're using UTF8 encoding). If it does, it will be | |
| 20647 | t | |
| 12167 | treated as something which is not UTF8 encoded. When the C<vec> was | |
| 20648 | s | |
| 12168 | assigned to, other parts of your program will also no longer consider the | |
| 20649 | ||
| 12169 | string to be UTF8 encoded. In other words, if you do have such characters | |
| 20650 | ||
| 12170 | in your string, vec() will operate on the actual byte string, and not the | |
| 20651 | ||
| 12171 | conceptual character string. | |
| 20652 | 12172 | |
| 20653 | 12173 | =end original |
| 20654 | 12174 | |
| 20655 | 文字列が | |
| 12175 | 文字列は値が 255 を越える文字を含むべきではありません | |
| 20656 | UTF8 | |
| 12176 | (これは UTF8 エンコーディングを使っているときにだけ起こりえます)。 | |
| 20657 | ||
| 12177 | もし含んでいると、UTF8 エンコードされていないものとして扱われます。 | |
| 20658 | ||
| 12178 | C<vec> が割り当てられたとき、プログラムのその他の部分では | |
| 20659 | ||
| 12179 | もはやこの文字列が UTF8 エンコードされたと扱われなくなります。 | |
| 20660 | ||
| 12180 | 言い換えると、もしこのような文字を文字列に含んでいると、 | |
| 20661 | ||
| 12181 | vec() は実際のバイト文字列として扱い、概念的な文字の文字列としては | |
| 20662 | ||
| 12182 | 扱いません。 | |
| 20663 | Perl 5.32 で、これは致命的エラーになります。 | |
| 20664 | 12183 | |
| 20665 | 12184 | =begin original |
| 20666 | 12185 | |
| 20667 | Strings created with | |
| 12186 | Strings created with C<vec> can also be manipulated with the logical | |
| 20668 | manipulated with the logical | |
| 20669 | 12187 | operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit |
| 20670 | 12188 | vector operation is desired when both operands are strings. |
| 20671 | 12189 | See L<perlop/"Bitwise String Operators">. |
| 20672 | 12190 | |
| 20673 | 12191 | =end original |
| 20674 | 12192 | |
| 20675 | ||
| 12193 | vec() で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で扱うこともできます。 | |
| 20676 | C<^>, C<~> で扱うこともできます。 | |
| 20677 | 12194 | これらの演算子は、両方の被演算子に文字列を使うと、 |
| 20678 | 12195 | ビットベクター演算を行ないます。 |
| 20679 | L<perlop/"Bitwise String Operators"> を参照してください。 | |
| 20680 | 12196 | |
| 20681 | 12197 | =begin original |
| 20682 | 12198 | |
| 20683 | 12199 | The following code will build up an ASCII string saying C<'PerlPerlPerl'>. |
| 20684 | 12200 | The comments show the string after each step. Note that this code works |
| 20685 | 12201 | in the same way on big-endian or little-endian machines. |
| 20686 | 12202 | |
| 20687 | 12203 | =end original |
| 20688 | 12204 | |
| 20689 | 12205 | 次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。 |
| 20690 | 12206 | コメントは各行の実行後の文字列を示します。 |
| 20691 | 12207 | このコードはビッグエンディアンでもリトルエンディアンでも同じように |
| 20692 | 12208 | 動作することに注意してください。 |
| 20693 | 12209 | |
| 20694 | 12210 | my $foo = ''; |
| 20695 | vec($foo, 0, 32) = 0x5065726C; | |
| 12211 | vec($foo, 0, 32) = 0x5065726C; # 'Perl' | |
| 20696 | 12212 | |
| 20697 | 12213 | # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits |
| 20698 | print vec($foo, 0, 8); | |
| 12214 | print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P') | |
| 20699 | 12215 | |
| 20700 | vec($foo, 2, 16) = 0x5065; | |
| 12216 | vec($foo, 2, 16) = 0x5065; # 'PerlPe' | |
| 20701 | vec($foo, 3, 16) = 0x726C; | |
| 12217 | vec($foo, 3, 16) = 0x726C; # 'PerlPerl' | |
| 20702 | vec($foo, 8, 8) = 0x50; | |
| 12218 | vec($foo, 8, 8) = 0x50; # 'PerlPerlP' | |
| 20703 | vec($foo, 9, 8) = 0x65; | |
| 12219 | vec($foo, 9, 8) = 0x65; # 'PerlPerlPe' | |
| 20704 | vec($foo, 20, 4) = 2; | |
| 12220 | vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02" | |
| 20705 | vec($foo, 21, 4) = 7; | |
| 12221 | vec($foo, 21, 4) = 7; # 'PerlPerlPer' | |
| 20706 | # 'r' is "\x72" | |
| 12222 | # 'r' is "\x72" | |
| 20707 | vec($foo, 45, 2) = 3; | |
| 12223 | vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c" | |
| 20708 | vec($foo, 93, 1) = 1; | |
| 12224 | vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c" | |
| 20709 | vec($foo, 94, 1) = 1; | |
| 12225 | vec($foo, 94, 1) = 1; # 'PerlPerlPerl' | |
| 20710 | # 'l' is "\x6c" | |
| 12226 | # 'l' is "\x6c" | |
| 20711 | 12227 | |
| 20712 | 12228 | =begin original |
| 20713 | 12229 | |
| 20714 | 12230 | To transform a bit vector into a string or list of 0's and 1's, use these: |
| 20715 | 12231 | |
| 20716 | 12232 | =end original |
| 20717 | 12233 | |
| 20718 | 12234 | ビットベクターを、0 と 1 の文字列や配列に変換するには、 |
| 20719 | 12235 | 以下のようにします。 |
| 20720 | 12236 | |
| 20721 | | |
| 12237 | $bits = unpack("b*", $vector); | |
| 20722 | | |
| 12238 | @bits = split(//, unpack("b*", $vector)); | |
| 20723 | 12239 | |
| 20724 | 12240 | =begin original |
| 20725 | 12241 | |
| 20726 | 12242 | If you know the exact length in bits, it can be used in place of the C<*>. |
| 20727 | 12243 | |
| 20728 | 12244 | =end original |
| 20729 | 12245 | |
| 20730 | ビット長が分かっていれば、 | |
| 12246 | ビット長が分かっていれば、* の代わりにその長さを使うことができます。 | |
| 20731 | 12247 | |
| 20732 | 12248 | =begin original |
| 20733 | 12249 | |
| 20734 | 12250 | Here is an example to illustrate how the bits actually fall in place: |
| 20735 | 12251 | |
| 20736 | 12252 | =end original |
| 20737 | 12253 | |
| 20738 | 12254 | これはビットが実際にどのような位置に入るかを図示する例です。 |
| 20739 | 12255 | |
| 20740 | #!/usr/bin/perl -wl | |
| 12256 | #!/usr/bin/perl -wl | |
| 20741 | 12257 | |
| 20742 | print <<'EOT'; | |
| 12258 | print <<'EOT'; | |
| 20743 | 0 1 2 3 | |
| 12259 | 0 1 2 3 | |
| 20744 | unpack("V",$_) 01234567890123456789012345678901 | |
| 12260 | unpack("V",$_) 01234567890123456789012345678901 | |
| 20745 | ------------------------------------------------------------------ | |
| 12261 | ------------------------------------------------------------------ | |
| 20746 | EOT | |
| 12262 | EOT | |
| 20747 | 12263 | |
| 20748 | for $w (0..3) { | |
| 12264 | for $w (0..3) { | |
| 20749 | $width = 2**$w; | |
| 12265 | $width = 2**$w; | |
| 20750 | for ($shift=0; $shift < $width; ++$shift) { | |
| 12266 | for ($shift=0; $shift < $width; ++$shift) { | |
| 20751 | for ($off=0; $off < 32/$width; ++$off) { | |
| 12267 | for ($off=0; $off < 32/$width; ++$off) { | |
| 20752 | $str = pack("B*", "0"x32); | |
| 12268 | $str = pack("B*", "0"x32); | |
| 20753 | $bits = (1<<$shift); | |
| 12269 | $bits = (1<<$shift); | |
| 20754 | vec($str, $off, $width) = $bits; | |
| 12270 | vec($str, $off, $width) = $bits; | |
| 20755 | $res = unpack("b*",$str); | |
| 12271 | $res = unpack("b*",$str); | |
| 20756 | $val = unpack("V", $str); | |
| 12272 | $val = unpack("V", $str); | |
| 20757 | write; | |
| 12273 | write; | |
| 20758 | } | |
| 12274 | } | |
| 20759 | } | |
| 12275 | } | |
| 20760 | } | |
| 12276 | } | |
| 20761 | 12277 | |
| 20762 | format STDOUT = | |
| 12278 | format STDOUT = | |
| 20763 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 12279 | vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 20764 | $off, $width, $bits, $val, $res | |
| 12280 | $off, $width, $bits, $val, $res | |
| 20765 | . | |
| 12281 | . | |
| 20766 | __END__ | |
| 12282 | __END__ | |
| 20767 | 12283 | |
| 20768 | 12284 | =begin original |
| 20769 | 12285 | |
| 20770 | Regardless of the machine architecture on which it run | |
| 12286 | Regardless of the machine architecture on which it is run, the above | |
| 20771 | example | |
| 12287 | example should print the following table: | |
| 20772 | 12288 | |
| 20773 | 12289 | =end original |
| 20774 | 12290 | |
| 20775 | 12291 | 実行するマシンのアーキテクチャに関わらず、 |
| 20776 | 12292 | 上記の例は以下の表を出力します。 |
| 20777 | 12293 | |
| 20778 | 0 1 2 3 | |
| 12294 | 0 1 2 3 | |
| 20779 | unpack("V",$_) 01234567890123456789012345678901 | |
| 12295 | unpack("V",$_) 01234567890123456789012345678901 | |
| 20780 | ------------------------------------------------------------------ | |
| 12296 | ------------------------------------------------------------------ | |
| 20781 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 | |
| 12297 | vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000 | |
| 20782 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 | |
| 12298 | vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000 | |
| 20783 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 | |
| 12299 | vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000 | |
| 20784 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 | |
| 12300 | vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000 | |
| 20785 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 | |
| 12301 | vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000 | |
| 20786 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 | |
| 12302 | vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000 | |
| 20787 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 | |
| 12303 | vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000 | |
| 20788 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 | |
| 12304 | vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000 | |
| 20789 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 | |
| 12305 | vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000 | |
| 20790 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 | |
| 12306 | vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000 | |
| 20791 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 | |
| 12307 | vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000 | |
| 20792 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 | |
| 12308 | vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000 | |
| 20793 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 | |
| 12309 | vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000 | |
| 20794 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 | |
| 12310 | vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000 | |
| 20795 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 | |
| 12311 | vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000 | |
| 20796 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 | |
| 12312 | vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000 | |
| 20797 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 | |
| 12313 | vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000 | |
| 20798 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 | |
| 12314 | vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000 | |
| 20799 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 | |
| 12315 | vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000 | |
| 20800 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 | |
| 12316 | vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000 | |
| 20801 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 | |
| 12317 | vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000 | |
| 20802 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 | |
| 12318 | vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000 | |
| 20803 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 | |
| 12319 | vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000 | |
| 20804 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 | |
| 12320 | vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000 | |
| 20805 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 | |
| 12321 | vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000 | |
| 20806 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 | |
| 12322 | vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000 | |
| 20807 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 | |
| 12323 | vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000 | |
| 20808 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 | |
| 12324 | vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000 | |
| 20809 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 | |
| 12325 | vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000 | |
| 20810 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 | |
| 12326 | vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100 | |
| 20811 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 | |
| 12327 | vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010 | |
| 20812 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 | |
| 12328 | vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001 | |
| 20813 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 | |
| 12329 | vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000 | |
| 20814 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 | |
| 12330 | vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000 | |
| 20815 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 | |
| 12331 | vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000 | |
| 20816 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 | |
| 12332 | vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000 | |
| 20817 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 | |
| 12333 | vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000 | |
| 20818 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 | |
| 12334 | vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000 | |
| 20819 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 | |
| 12335 | vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000 | |
| 20820 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 | |
| 12336 | vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000 | |
| 20821 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 | |
| 12337 | vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000 | |
| 20822 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 | |
| 12338 | vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000 | |
| 20823 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 | |
| 12339 | vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000 | |
| 20824 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 | |
| 12340 | vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000 | |
| 20825 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 | |
| 12341 | vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000 | |
| 20826 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 | |
| 12342 | vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000 | |
| 20827 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 | |
| 12343 | vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000 | |
| 20828 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 | |
| 12344 | vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010 | |
| 20829 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 | |
| 12345 | vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000 | |
| 20830 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 | |
| 12346 | vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000 | |
| 20831 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 | |
| 12347 | vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000 | |
| 20832 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 | |
| 12348 | vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000 | |
| 20833 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 | |
| 12349 | vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000 | |
| 20834 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 | |
| 12350 | vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000 | |
| 20835 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 | |
| 12351 | vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000 | |
| 20836 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 | |
| 12352 | vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000 | |
| 20837 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 | |
| 12353 | vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000 | |
| 20838 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 | |
| 12354 | vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000 | |
| 20839 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 | |
| 12355 | vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000 | |
| 20840 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 | |
| 12356 | vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000 | |
| 20841 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 | |
| 12357 | vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000 | |
| 20842 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 | |
| 12358 | vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000 | |
| 20843 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 | |
| 12359 | vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100 | |
| 20844 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 | |
| 12360 | vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001 | |
| 20845 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 | |
| 12361 | vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000 | |
| 20846 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 | |
| 12362 | vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000 | |
| 20847 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 | |
| 12363 | vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000 | |
| 20848 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 | |
| 12364 | vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000 | |
| 20849 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 | |
| 12365 | vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000 | |
| 20850 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 | |
| 12366 | vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000 | |
| 20851 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 | |
| 12367 | vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000 | |
| 20852 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 | |
| 12368 | vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000 | |
| 20853 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 | |
| 12369 | vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000 | |
| 20854 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 | |
| 12370 | vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000 | |
| 20855 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 | |
| 12371 | vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000 | |
| 20856 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 | |
| 12372 | vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000 | |
| 20857 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 | |
| 12373 | vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000 | |
| 20858 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 | |
| 12374 | vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000 | |
| 20859 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 | |
| 12375 | vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000 | |
| 20860 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 | |
| 12376 | vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100 | |
| 20861 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 | |
| 12377 | vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000 | |
| 20862 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 | |
| 12378 | vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000 | |
| 20863 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 | |
| 12379 | vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000 | |
| 20864 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 | |
| 12380 | vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000 | |
| 20865 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 | |
| 12381 | vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000 | |
| 20866 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 | |
| 12382 | vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000 | |
| 20867 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 | |
| 12383 | vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000 | |
| 20868 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 | |
| 12384 | vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010 | |
| 20869 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 | |
| 12385 | vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000 | |
| 20870 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 | |
| 12386 | vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000 | |
| 20871 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 | |
| 12387 | vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000 | |
| 20872 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 | |
| 12388 | vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000 | |
| 20873 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 | |
| 12389 | vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000 | |
| 20874 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 | |
| 12390 | vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000 | |
| 20875 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 | |
| 12391 | vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000 | |
| 20876 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 | |
| 12392 | vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001 | |
| 20877 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 | |
| 12393 | vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000 | |
| 20878 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 | |
| 12394 | vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000 | |
| 20879 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 | |
| 12395 | vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000 | |
| 20880 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 | |
| 12396 | vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000 | |
| 20881 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 | |
| 12397 | vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000 | |
| 20882 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 | |
| 12398 | vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000 | |
| 20883 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 | |
| 12399 | vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000 | |
| 20884 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 | |
| 12400 | vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000 | |
| 20885 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 | |
| 12401 | vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000 | |
| 20886 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 | |
| 12402 | vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000 | |
| 20887 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 | |
| 12403 | vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000 | |
| 20888 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 | |
| 12404 | vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000 | |
| 20889 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 | |
| 12405 | vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000 | |
| 20890 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 | |
| 12406 | vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000 | |
| 20891 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 | |
| 12407 | vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000 | |
| 20892 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 | |
| 12408 | vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000 | |
| 20893 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 | |
| 12409 | vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000 | |
| 20894 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 | |
| 12410 | vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000 | |
| 20895 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 | |
| 12411 | vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000 | |
| 20896 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 | |
| 12412 | vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000 | |
| 20897 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 | |
| 12413 | vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000 | |
| 20898 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 | |
| 12414 | vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000 | |
| 20899 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 | |
| 12415 | vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000 | |
| 20900 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 | |
| 12416 | vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100 | |
| 20901 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 | |
| 12417 | vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000 | |
| 20902 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 | |
| 12418 | vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000 | |
| 20903 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 | |
| 12419 | vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000 | |
| 20904 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 | |
| 12420 | vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010 | |
| 20905 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 | |
| 12421 | vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000 | |
| 20906 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 | |
| 12422 | vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000 | |
| 20907 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 | |
| 12423 | vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000 | |
| 20908 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 | |
| 12424 | vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001 | |
| 20909 | 12425 | |
| 20910 | 12426 | =item wait |
| 20911 | X<wait> | |
| 20912 | 12427 | |
| 20913 | =for Pod::Functions wait for any child process to die | |
| 20914 | ||
| 20915 | 12428 | =begin original |
| 20916 | 12429 | |
| 20917 | Behaves like | |
| 12430 | Behaves like the wait(2) system call on your system: it waits for a child | |
| 20918 | 12431 | process to terminate and returns the pid of the deceased process, or |
| 20919 | C<-1> if there are no child processes. The status is returned in | |
| 12432 | C<-1> if there are no child processes. The status is returned in C<$?>. | |
| 20920 | L<C<$?>|perlvar/$?> and | |
| 20921 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 20922 | 12433 | Note that a return value of C<-1> could mean that child processes are |
| 20923 | 12434 | being automatically reaped, as described in L<perlipc>. |
| 20924 | 12435 | |
| 20925 | 12436 | =end original |
| 20926 | 12437 | |
| 20927 | ||
| 12438 | wait(2) システムコールと同様に振る舞います。 | |
| 20928 | 消滅したプロセスの pid を返します | |
| 12439 | チャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を返します。 | |
| 20929 | C<-1> を返します。 | |
| 12440 | チャイルドプロセスが存在しないときには、C<-1> を返します。 | |
| 20930 | ステータスは | |
| 12441 | ステータスは C<$?> に返されます。 | |
| 20931 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
| 20932 | 12442 | L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが |
| 20933 | 12443 | 自動的に刈り取られたことを意味するかもしれないことに注意してください。 |
| 20934 | 12444 | |
| 20935 | =begin original | |
| 20936 | ||
| 20937 | If you use L<C<wait>|/wait> in your handler for | |
| 20938 | L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child | |
| 20939 | created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>. | |
| 20940 | See L<perlipc> for details. | |
| 20941 | ||
| 20942 | =end original | |
| 20943 | ||
| 20944 | L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って | |
| 20945 | L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって | |
| 20946 | 作られた子を待つことになるかも知れません。 | |
| 20947 | 詳しくは L<perlipc> を参照してください。 | |
| 20948 | ||
| 20949 | =begin original | |
| 20950 | ||
| 20951 | Portability issues: L<perlport/wait>. | |
| 20952 | ||
| 20953 | =end original | |
| 20954 | ||
| 20955 | 移植性の問題: L<perlport/wait>。 | |
| 20956 | ||
| 20957 | 12445 | =item waitpid PID,FLAGS |
| 20958 | X<waitpid> | |
| 20959 | 12446 | |
| 20960 | =for Pod::Functions wait for a particular child process to die | |
| 20961 | ||
| 20962 | 12447 | =begin original |
| 20963 | 12448 | |
| 20964 | 12449 | Waits for a particular child process to terminate and returns the pid of |
| 20965 | the deceased process, or C<-1> if there is no such child process. | |
| 12450 | the deceased process, or C<-1> if there is no such child process. On some | |
| 20966 | ||
| 12451 | systems, a value of 0 indicates that there are processes still running. | |
| 20967 | ||
| 12452 | The status is returned in C<$?>. If you say | |
| 20968 | The status is returned in L<C<$?>|perlvar/$?> and | |
| 20969 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>. | |
| 20970 | 12453 | |
| 20971 | 12454 | =end original |
| 20972 | 12455 | |
| 20973 | 特定の | |
| 12456 | 特定のチャイルドプロセスが終了するのを待ち、消滅した | |
| 20974 | ||
| 12457 | プロセスの pid を返します。 | |
| 20975 | ||
| 12458 | 指定したチャイルドプロセスが存在しないときには、C<-1> を返します。 | |
| 20976 | ||
| 12459 | 値 0 がプロセスがまだ実行中であることを示すシステムもあります。 | |
| 20977 | 返 | |
| 12460 | ステータスは C<$?> に返されます。 | |
| 20978 | ステータスは L<C<$?>|perlvar/$?> と | |
| 20979 | L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。 | |
| 20980 | 12461 | |
| 20981 | =begin original | |
| 20982 | ||
| 20983 | A PID of C<0> indicates to wait for any child process whose process group ID is | |
| 20984 | equal to that of the current process. A PID of less than C<-1> indicates to | |
| 20985 | wait for any child process whose process group ID is equal to -PID. A PID of | |
| 20986 | C<-1> indicates to wait for any child process. | |
| 20987 | ||
| 20988 | =end original | |
| 20989 | ||
| 20990 | PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである | |
| 20991 | 任意の子プロセスを wait します。 | |
| 20992 | PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい | |
| 20993 | 任意の子プロセスを wait します。 | |
| 20994 | PID に C<-1> を指定すると任意の子プロセスを wait します。 | |
| 20995 | ||
| 20996 | =begin original | |
| 20997 | ||
| 20998 | If you say | |
| 20999 | ||
| 21000 | =end original | |
| 21001 | ||
| 21002 | 以下のようにするか | |
| 21003 | ||
| 21004 | 12462 | use POSIX ":sys_wait_h"; |
| 12463 | #... | |
| 12464 | do { | |
| 12465 | $kid = waitpid(-1,WNOHANG); | |
| 12466 | } until $kid == -1; | |
| 21005 | 12467 | |
| 21006 | my $kid; | |
| 21007 | do { | |
| 21008 | $kid = waitpid(-1, WNOHANG); | |
| 21009 | } while $kid > 0; | |
| 21010 | ||
| 21011 | 12468 | =begin original |
| 21012 | 12469 | |
| 21013 | or | |
| 12470 | then you can do a non-blocking wait for all pending zombie processes. | |
| 21014 | ||
| 21015 | =end original | |
| 21016 | ||
| 21017 | または | |
| 21018 | ||
| 21019 | 1 while waitpid(-1, WNOHANG) > 0; | |
| 21020 | ||
| 21021 | =begin original | |
| 21022 | ||
| 21023 | then you can do a non-blocking wait for all pending zombie processes (see | |
| 21024 | L<POSIX/WAIT>). | |
| 21025 | 12471 | Non-blocking wait is available on machines supporting either the |
| 21026 | ||
| 12472 | waitpid(2) or wait4(2) system calls. However, waiting for a particular | |
| 21027 | 12473 | pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the |
| 21028 | 12474 | system call by remembering the status values of processes that have |
| 21029 | 12475 | exited but have not been harvested by the Perl script yet.) |
| 21030 | 12476 | |
| 21031 | 12477 | =end original |
| 21032 | 12478 | |
| 21033 | 12479 | とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを |
| 21034 | wait します | |
| 12480 | wait します。 | |
| 21035 | ブロックなしの wait は、システムコール | |
| 12481 | ブロックなしの wait は、システムコール wait_pid(2) か、 | |
| 21036 | システムコール | |
| 12482 | システムコール wait4(2) をサポートしているマシンで利用可能です。 | |
| 21037 | 12483 | しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも |
| 21038 | 12484 | 実装されています。 |
| 21039 | 12485 | (exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを |
| 21040 | 12486 | エミュレートしますが、Perl スクリプトには取り入れられていません。) |
| 21041 | 12487 | |
| 21042 | 12488 | =begin original |
| 21043 | 12489 | |
| 21044 | 12490 | Note that on some systems, a return value of C<-1> could mean that child |
| 21045 | 12491 | processes are being automatically reaped. See L<perlipc> for details, |
| 21046 | 12492 | and for other examples. |
| 21047 | 12493 | |
| 21048 | 12494 | =end original |
| 21049 | 12495 | |
| 21050 | 12496 | システムによっては、返り値が C<-1> の場合は子プロセスが自動的に |
| 21051 | 12497 | 刈り取られたことを意味するかもしれないことに注意してください。 |
| 21052 | 12498 | 詳細やその他の例については L<perlipc> を参照してください。 |
| 21053 | 12499 | |
| 21054 | =begin original | |
| 21055 | ||
| 21056 | Portability issues: L<perlport/waitpid>. | |
| 21057 | ||
| 21058 | =end original | |
| 21059 | ||
| 21060 | 移植性の問題: L<perlport/waitpid>。 | |
| 21061 | ||
| 21062 | 12500 | =item wantarray |
| 21063 | X<wantarray> X<context> | |
| 21064 | 12501 | |
| 21065 | =for Pod::Functions get void vs scalar vs list context of current subroutine call | |
| 21066 | ||
| 21067 | 12502 | =begin original |
| 21068 | 12503 | |
| 21069 | Returns true if the context of the currently executing subroutine | |
| 12504 | Returns true if the context of the currently executing subroutine is | |
| 21070 | ||
| 12505 | looking for a list value. Returns false if the context is looking | |
| 21071 | context is | |
| 12506 | for a scalar. Returns the undefined value if the context is looking | |
| 21072 | ||
| 12507 | for no value (void context). | |
| 21073 | looking for no value (void context). | |
| 21074 | 12508 | |
| 21075 | 12509 | =end original |
| 21076 | 12510 | |
| 21077 | 現在実行中のサブルーチン | |
| 12511 | 現在実行中のサブルーチンのコンテキストが、リスト値を | |
| 21078 | ||
| 12512 | 要求するものであれば、真を返します。 | |
| 21079 | 12513 | スカラを要求するコンテキストであれば、偽を返します。 |
| 21080 | 12514 | 何も値を要求しない(無効コンテキスト)場合は未定義値を返します。 |
| 21081 | 12515 | |
| 21082 | return unless defined wantarray; | |
| 12516 | return unless defined wantarray; # don't bother doing more | |
| 21083 | 12517 | my @a = complex_calculation(); |
| 21084 | 12518 | return wantarray ? @a : "@a"; |
| 21085 | 12519 | |
| 21086 | 12520 | =begin original |
| 21087 | 12521 | |
| 21088 | ||
| 12522 | This function should have been named wantlist() instead. | |
| 21089 | in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or | |
| 21090 | in a C<DESTROY> method. | |
| 21091 | 12523 | |
| 21092 | 12524 | =end original |
| 21093 | 12525 | |
| 21094 | ||
| 12526 | この関数は wantlist() という名前にするべきでした。 | |
| 21095 | ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は | |
| 21096 | 未定義です。 | |
| 21097 | 12527 | |
| 12528 | =item warn LIST | |
| 12529 | ||
| 21098 | 12530 | =begin original |
| 21099 | 12531 | |
| 21100 | ||
| 12532 | Produces a message on STDERR just like C<die>, but doesn't exit or throw | |
| 12533 | an exception. | |
| 21101 | 12534 | |
| 21102 | 12535 | =end original |
| 21103 | 12536 | |
| 21104 | ||
| 12537 | C<die> と同じように STDERR にメッセージを出力しますが、 | |
| 12538 | exit したり、例外を発生させたりしません。 | |
| 21105 | 12539 | |
| 21106 | = | |
| 12540 | =begin original | |
| 21107 | X<warn> X<warning> X<STDERR> | |
| 21108 | 12541 | |
| 21109 | ||
| 12542 | If LIST is empty and C<$@> already contains a value (typically from a | |
| 12543 | previous eval) that value is used after appending C<"\t...caught"> | |
| 12544 | to C<$@>. This is useful for staying almost, but not entirely similar to | |
| 12545 | C<die>. | |
| 21110 | 12546 | |
| 12547 | =end original | |
| 12548 | ||
| 12549 | LIST が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている | |
| 12550 | 場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。 | |
| 12551 | これはほとんどそのままにするときに便利ですが、 | |
| 12552 | C<die> と全体的に似ているわけではありません。 | |
| 12553 | ||
| 21111 | 12554 | =begin original |
| 21112 | 12555 | |
| 21113 | ||
| 12556 | If C<$@> is empty then the string C<"Warning: Something's wrong"> is used. | |
| 21114 | its operand LIST in the same way as C<die>, but is slightly different | |
| 21115 | in what it defaults to when LIST is empty or makes an empty string. | |
| 21116 | If it is empty and L<C<$@>|perlvar/$@> already contains an exception | |
| 21117 | value then that value is used after appending C<"\t...caught">. If it | |
| 21118 | is empty and C<$@> is also empty then the string C<"Warning: Something's | |
| 21119 | wrong"> is used. | |
| 21120 | 12557 | |
| 21121 | 12558 | =end original |
| 21122 | 12559 | |
| 21123 | ||
| 12560 | C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が | |
| 21124 | ||
| 12561 | 使われます。 | |
| 21125 | LIST が空や空文字列を作る時に何をデフォルトとするかが少し異なります。 | |
| 21126 | それが空かつ、L<C<$@>|perlvar/$@> に既に | |
| 21127 | 例外値が入っている場合、C<"\t...caught"> を追加した値が | |
| 21128 | 用いられます。 | |
| 21129 | もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という | |
| 21130 | 文字列が使われます。 | |
| 21131 | 12562 | |
| 21132 | 12563 | =begin original |
| 21133 | 12564 | |
| 21134 | ||
| 12565 | No message is printed if there is a C<$SIG{__WARN__}> handler | |
| 21135 | ||
| 12566 | installed. It is the handler's responsibility to deal with the message | |
| 21136 | a | |
| 12567 | as it sees fit (like, for instance, converting it into a C<die>). Most | |
| 21137 | handler the | |
| 12568 | handlers must therefore make arrangements to actually display the | |
| 21138 | r | |
| 12569 | warnings that they are not prepared to deal with, by calling C<warn> | |
| 21139 | as it sees fit (like, for instance, converting it into a | |
| 21140 | L<C<die>|/die LIST>). Most | |
| 21141 | handlers must therefore arrange to actually display the | |
| 21142 | warnings that they are not prepared to deal with, by calling | |
| 21143 | L<C<warn>|/warn LIST> | |
| 21144 | 12570 | again in the handler. Note that this is quite safe and will not |
| 21145 | 12571 | produce an endless loop, since C<__WARN__> hooks are not called from |
| 21146 | 12572 | inside one. |
| 21147 | 12573 | |
| 21148 | 12574 | =end original |
| 21149 | 12575 | |
| 21150 | ||
| 12576 | C<$SIG{__WARN__}> ハンドラが設定されている場合は何のメッセージも | |
| 21151 | ||
| 12577 | 表示されません。 | |
| 21152 | ||
| 12578 | メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの | |
| 21153 | 置き換えられます。 | |
| 21154 | このようなハンドラが設定されている場合は何の | |
| 21155 | メッセージも自動的には表示されません; | |
| 21156 | 例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの | |
| 21157 | 12579 | 責任ということです。 |
| 21158 | 12580 | 従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、 |
| 21159 | ハンドラの中で | |
| 12581 | ハンドラの中で C<warn> を再び呼び出します。 | |
| 21160 | 12582 | C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、 |
| 21161 | 12583 | 無限ループを引き起こすことはないということに注意してください。 |
| 21162 | 12584 | |
| 21163 | 12585 | =begin original |
| 21164 | 12586 | |
| 21165 | 12587 | You will find this behavior is slightly different from that of |
| 21166 | ||
| 12588 | C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can | |
| 21167 | ||
| 12589 | instead call C<die> again to change it). | |
| 21168 | it). | |
| 21169 | 12590 | |
| 21170 | 12591 | =end original |
| 21171 | 12592 | |
| 21172 | この振る舞いは | |
| 12593 | この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、 | |
| 21173 | ||
| 12594 | 代わりに C<die> をもう一度呼び出すことで変更できます)とは | |
| 21174 | ||
| 12595 | 少し違うことに気付くことでしょう。 | |
| 21175 | 12596 | |
| 21176 | 12597 | =begin original |
| 21177 | 12598 | |
| 21178 | 12599 | Using a C<__WARN__> handler provides a powerful way to silence all |
| 21179 | 12600 | warnings (even the so-called mandatory ones). An example: |
| 21180 | 12601 | |
| 21181 | 12602 | =end original |
| 21182 | 12603 | |
| 21183 | 12604 | C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての |
| 21184 | 12605 | 警告を黙らせる強力な手段となります。 |
| 21185 | 12606 | 例: |
| 21186 | 12607 | |
| 21187 | 12608 | # wipe out *all* compile-time warnings |
| 21188 | 12609 | BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } } |
| 21189 | 12610 | my $foo = 10; |
| 21190 | 12611 | my $foo = 20; # no warning about duplicate my $foo, |
| 21191 | 12612 | # but hey, you asked for it! |
| 21192 | 12613 | # no compile-time or run-time warnings before here |
| 21193 | 12614 | $DOWARN = 1; |
| 21194 | 12615 | |
| 21195 | 12616 | # run-time warnings enabled after here |
| 21196 | 12617 | warn "\$foo is alive and $foo!"; # does show up |
| 21197 | 12618 | |
| 21198 | 12619 | =begin original |
| 21199 | 12620 | |
| 21200 | See L<perlvar> for details on setting | |
| 12621 | See L<perlvar> for details on setting C<%SIG> entries, and for more | |
| 21201 | a | |
| 12622 | examples. See the Carp module for other kinds of warnings using its | |
| 21202 | ||
| 12623 | carp() and cluck() functions. | |
| 21203 | C<carp> and C<cluck> functions. | |
| 21204 | 12624 | |
| 21205 | 12625 | =end original |
| 21206 | 12626 | |
| 21207 | ||
| 12627 | C<%SIG> エントリのセットに関する詳細とさらなる例に関しては | |
| 21208 | L<perlvar> を参照して | |
| 12628 | L<perlvar> を参照して下さい。 | |
| 21209 | ||
| 12629 | carp() 関数と cluck() 関数を用いた警告の方法に関しては | |
| 21210 | ||
| 12630 | Carp モジュールを参照して下さい。 | |
| 21211 | 12631 | |
| 21212 | 12632 | =item write FILEHANDLE |
| 21213 | X<write> | |
| 21214 | 12633 | |
| 21215 | 12634 | =item write EXPR |
| 21216 | 12635 | |
| 21217 | 12636 | =item write |
| 21218 | 12637 | |
| 21219 | =for Pod::Functions print a picture record | |
| 21220 | ||
| 21221 | 12638 | =begin original |
| 21222 | 12639 | |
| 21223 | 12640 | Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, |
| 21224 | 12641 | using the format associated with that file. By default the format for |
| 21225 | 12642 | a file is the one having the same name as the filehandle, but the |
| 21226 | format for the current output channel (see the | |
| 12643 | format for the current output channel (see the C<select> function) may be set | |
| 21227 | ||
| 12644 | explicitly by assigning the name of the format to the C<$~> variable. | |
| 21228 | assigning the name of the format to the L<C<$~>|perlvar/$~> variable. | |
| 21229 | 12645 | |
| 21230 | 12646 | =end original |
| 21231 | 12647 | |
| 21232 | 12648 | 指定された FILEHANDLE に対して、そのファイルに対応させた |
| 21233 | 12649 | フォーマットを使って、(複数行の場合もある) 整形された |
| 21234 | 12650 | レコードを書き出します。 |
| 21235 | 12651 | デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと |
| 21236 | 同じ名前のものですが、その時点の出力チャネル | |
| 12652 | 同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を | |
| 21237 | ||
| 12653 | 参照してください) のフォーマットは、その名前を明示的に変数 C<$~> に | |
| 21238 | ||
| 12654 | 代入することで、変更が可能です。 | |
| 21239 | L<C<$~>|perlvar/$~> に代入することで、変更が可能です。 | |
| 21240 | 12655 | |
| 21241 | 12656 | =begin original |
| 21242 | 12657 | |
| 21243 | Top of form processing is handled automatically: if there is | |
| 12658 | Top of form processing is handled automatically: if there is | |
| 21244 | room on the current page for the formatted record, the | |
| 12659 | insufficient room on the current page for the formatted record, the | |
| 21245 | writing a form feed a | |
| 12660 | page is advanced by writing a form feed, a special top-of-page format | |
| 21246 | ||
| 12661 | is used to format the new page header, and then the record is written. | |
| 21247 | ||
| 12662 | By default the top-of-page format is the name of the filehandle with | |
| 21248 | ||
| 12663 | "_TOP" appended, but it may be dynamically set to the format of your | |
| 21249 | ||
| 12664 | choice by assigning the name to the C<$^> variable while the filehandle is | |
| 21250 | ||
| 12665 | selected. The number of lines remaining on the current page is in | |
| 21251 | ||
| 12666 | variable C<$->, which can be set to C<0> to force a new page. | |
| 21252 | variable while that filehandle is selected. The number of lines | |
| 21253 | remaining on the current page is in variable L<C<$->|perlvar/$->, which | |
| 21254 | can be set to C<0> to force a new page. | |
| 21255 | 12667 | |
| 21256 | 12668 | =end original |
| 21257 | 12669 | |
| 21258 | ページの先頭の処理は、自動的に行なわれます | |
| 12670 | ページの先頭の処理は、自動的に行なわれます。 | |
| 21259 | レコードを出力するだけのスペースがない場合には、 | |
| 12671 | 現在のページに整形されたレコードを出力するだけのスペースがない場合には、 | |
| 21260 | 進め、新しいページヘッダを整形するため | |
| 12672 | 改ページを行なってページを進め、新しいページヘッダを整形するため、 | |
| 21261 | その後でレコードが書かれます。 | |
| 12673 | ページ先頭フォーマットが使われ、その後でレコードが書かれます。 | |
| 21262 | 12674 | デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に |
| 21263 | ||
| 12675 | "_TOP" をつなげたものですが、ファイルハンドルが選択されている間に、 | |
| 21264 | C< | |
| 12676 | 変数 C<$^> に名前を設定すれば、動的にフォーマットを | |
| 21265 | これは自動有効化されたファイルハンドルで問題になる可能性がありますが、 | |
| 21266 | ファイルハンドルが選択されている間に、 | |
| 21267 | 変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを | |
| 21268 | 12677 | 変更することができます。 |
| 21269 | そのページの残り行数は、変数 | |
| 12678 | そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に | |
| 21270 | ||
| 12679 | 設定することで、強制的に改ページを行なうことができます。 | |
| 21271 | 12680 | |
| 21272 | 12681 | =begin original |
| 21273 | 12682 | |
| 21274 | 12683 | If FILEHANDLE is unspecified, output goes to the current default output |
| 21275 | 12684 | channel, which starts out as STDOUT but may be changed by the |
| 21276 | ||
| 12685 | C<select> operator. If the FILEHANDLE is an EXPR, then the expression | |
| 21277 | then the expression | |
| 21278 | 12686 | is evaluated and the resulting string is used to look up the name of |
| 21279 | 12687 | the FILEHANDLE at run time. For more on formats, see L<perlform>. |
| 21280 | 12688 | |
| 21281 | 12689 | =end original |
| 21282 | 12690 | |
| 21283 | FILEHANDLE を指定しないと、出力はその時点のデフォルト | |
| 12691 | FILEHANDLE を指定しないと、出力はその時点のデフォルト | |
| 21284 | 行なわれます | |
| 12692 | 出力チャネルに対して行なわれます。 | |
| 21285 | ||
| 12693 | これは、スクリプトの開始時点では STDOUT ですが、select() 演算子で | |
| 12694 | 変更することができます。 | |
| 21286 | 12695 | FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が |
| 21287 | 12696 | 実行時に FILEHANDLE の名前として見られます。 |
| 21288 | 12697 | フォーマットについて、さらには、L<perlform> を参照してください。 |
| 21289 | 12698 | |
| 21290 | 12699 | =begin original |
| 21291 | 12700 | |
| 21292 | Note that write is I<not> the opposite of | |
| 12701 | Note that write is I<not> the opposite of C<read>. Unfortunately. | |
| 21293 | L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately. | |
| 21294 | 12702 | |
| 21295 | 12703 | =end original |
| 21296 | 12704 | |
| 21297 | write は | |
| 12705 | 残念ながら、write は C<read> の反対のことをするもの | |
| 21298 | ||
| 12706 | I<ではありません>。 | |
| 21299 | 残念ながら。 | |
| 21300 | 12707 | |
| 21301 | 12708 | =item y/// |
| 21302 | 12709 | |
| 21303 | =for Pod::Functions transliterate a string | |
| 21304 | ||
| 21305 | 12710 | =begin original |
| 21306 | 12711 | |
| 21307 | The transliteration operator. Same as | |
| 12712 | The transliteration operator. Same as C<tr///>. See L<perlop>. | |
| 21308 | L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See | |
| 21309 | L<perlop/"Quote-Like Operators">. | |
| 21310 | 12713 | |
| 21311 | 12714 | =end original |
| 21312 | 12715 | |
| 21313 | 文字変換演算子です。 | |
| 12716 | 文字変換演算子です。C<tr///>と同じです。L<perlop>を参照して | |
| 21314 | ||
| 12717 | ください。 | |
| 21315 | L<perlop/"Quote-Like Operators"> を参照してください。 | |
| 21316 | 12718 | |
| 21317 | 12719 | =back |
| 21318 | 12720 | |
| 21319 | =head2 Non-function Keywords by Cross-reference | |
| 21320 | ||
| 21321 | =head3 perldata | |
| 21322 | ||
| 21323 | =over | |
| 21324 | ||
| 21325 | =item __DATA__ | |
| 21326 | ||
| 21327 | =item __END__ | |
| 21328 | ||
| 21329 | =begin original | |
| 21330 | ||
| 21331 | These keywords are documented in L<perldata/"Special Literals">. | |
| 21332 | ||
| 21333 | =end original | |
| 21334 | ||
| 21335 | これらのキーワードは L<perldata/"Special Literals"> で文書化されています。 | |
| 21336 | ||
| 21337 | =back | |
| 21338 | ||
| 21339 | =head3 perlmod | |
| 21340 | ||
| 21341 | =over | |
| 21342 | ||
| 21343 | =item BEGIN | |
| 21344 | ||
| 21345 | =item CHECK | |
| 21346 | ||
| 21347 | =item END | |
| 21348 | ||
| 21349 | =item INIT | |
| 21350 | ||
| 21351 | =item UNITCHECK | |
| 21352 | ||
| 21353 | =begin original | |
| 21354 | ||
| 21355 | These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">. | |
| 21356 | ||
| 21357 | =end original | |
| 21358 | ||
| 21359 | これらのコンパイルフェーズキーワードは | |
| 21360 | L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。 | |
| 21361 | ||
| 21362 | =back | |
| 21363 | ||
| 21364 | =head3 perlobj | |
| 21365 | ||
| 21366 | =over | |
| 21367 | ||
| 21368 | =item DESTROY | |
| 21369 | ||
| 21370 | =begin original | |
| 21371 | ||
| 21372 | This method keyword is documented in L<perlobj/"Destructors">. | |
| 21373 | ||
| 21374 | =end original | |
| 21375 | ||
| 21376 | このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。 | |
| 21377 | ||
| 21378 | =back | |
| 21379 | ||
| 21380 | =head3 perlop | |
| 21381 | ||
| 21382 | =over | |
| 21383 | ||
| 21384 | =item and | |
| 21385 | ||
| 21386 | =item cmp | |
| 21387 | ||
| 21388 | =item eq | |
| 21389 | ||
| 21390 | =item ge | |
| 21391 | ||
| 21392 | =item gt | |
| 21393 | ||
| 21394 | =item le | |
| 21395 | ||
| 21396 | =item lt | |
| 21397 | ||
| 21398 | =item ne | |
| 21399 | ||
| 21400 | =item not | |
| 21401 | ||
| 21402 | =item or | |
| 21403 | ||
| 21404 | =item x | |
| 21405 | ||
| 21406 | =item xor | |
| 21407 | ||
| 21408 | =begin original | |
| 21409 | ||
| 21410 | These operators are documented in L<perlop>. | |
| 21411 | ||
| 21412 | =end original | |
| 21413 | ||
| 21414 | これらの演算子は L<perlop> で文書化されています。 | |
| 21415 | ||
| 21416 | =back | |
| 21417 | ||
| 21418 | =head3 perlsub | |
| 21419 | ||
| 21420 | =over | |
| 21421 | ||
| 21422 | =item AUTOLOAD | |
| 21423 | ||
| 21424 | =begin original | |
| 21425 | ||
| 21426 | This keyword is documented in L<perlsub/"Autoloading">. | |
| 21427 | ||
| 21428 | =end original | |
| 21429 | ||
| 21430 | このキーワードは L<perlsub/"Autoloading"> で文書化されています。 | |
| 21431 | ||
| 21432 | =back | |
| 21433 | ||
| 21434 | =head3 perlsyn | |
| 21435 | ||
| 21436 | =over | |
| 21437 | ||
| 21438 | =item else | |
| 21439 | ||
| 21440 | =item elsif | |
| 21441 | ||
| 21442 | =item for | |
| 21443 | ||
| 21444 | =item foreach | |
| 21445 | ||
| 21446 | =item if | |
| 21447 | ||
| 21448 | =item unless | |
| 21449 | ||
| 21450 | =item until | |
| 21451 | ||
| 21452 | =item while | |
| 21453 | ||
| 21454 | =begin original | |
| 21455 | ||
| 21456 | These flow-control keywords are documented in L<perlsyn/"Compound Statements">. | |
| 21457 | ||
| 21458 | =end original | |
| 21459 | ||
| 21460 | これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で | |
| 21461 | 文書化されています。 | |
| 21462 | ||
| 21463 | =item elseif | |
| 21464 | ||
| 21465 | =begin original | |
| 21466 | ||
| 21467 | The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif> | |
| 21468 | or C<else if> either. It does parse C<elseif>, but only to warn you | |
| 21469 | about not using it. | |
| 21470 | ||
| 21471 | =end original | |
| 21472 | ||
| 21473 | "else if" キーワードは Perl では C<elsif> と綴ります。 | |
| 21474 | C<elif> や C<else if> はありません。 | |
| 21475 | C<elseif> はパースされますが、使わないように警告するためだけです。 | |
| 21476 | ||
| 21477 | =begin original | |
| 21478 | ||
| 21479 | See the documentation for flow-control keywords in L<perlsyn/"Compound | |
| 21480 | Statements">. | |
| 21481 | ||
| 21482 | =end original | |
| 21483 | ||
| 21484 | L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を | |
| 21485 | 参照してください。 | |
| 21486 | ||
| 21487 | =back | |
| 21488 | ||
| 21489 | =over | |
| 21490 | ||
| 21491 | =item default | |
| 21492 | ||
| 21493 | =item given | |
| 21494 | ||
| 21495 | =item when | |
| 21496 | ||
| 21497 | =begin original | |
| 21498 | ||
| 21499 | These flow-control keywords related to the experimental switch feature are | |
| 21500 | documented in L<perlsyn/"Switch Statements">. | |
| 21501 | ||
| 21502 | =end original | |
| 21503 | ||
| 21504 | これらの実験的な switch 機能に関連するフロー制御キーワードは | |
| 21505 | L<perlsyn/"Switch Statements"> で文書化されています。 | |
| 21506 | ||
| 21507 | =back | |
| 21508 | ||
| 21509 | =cut | |
| 21510 | ||
| 21511 | 12721 | =begin meta |
| 21512 | 12722 | |
| 21513 | 12723 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
| 21514 | Update: | |
| 12724 | Update: Kentaro Shirakata <argrath@ub32.org> | |
| 21515 | ||
| 12725 | License: GPL or Artistic | |
| 21516 | 12726 | |
| 21517 | 12727 | =end meta |