argra****@users*****
argra****@users*****
2017年 9月 18日 (月) 02:33:10 JST
Index: docs/perl/5.20.1/perllocale.pod diff -u docs/perl/5.20.1/perllocale.pod:1.3 docs/perl/5.20.1/perllocale.pod:1.4 --- docs/perl/5.20.1/perllocale.pod:1.3 Sat Jan 10 04:02:42 2015 +++ docs/perl/5.20.1/perllocale.pod Mon Sep 18 02:33:10 2017 @@ -500,12 +500,11 @@ =end original -The variables L<$!|perlvar/$ERRNO> (and its synonyms C<$ERRNO> and -C<$OS_ERROR>) and L<$^E|perlvar/$EXTENDED_OS_ERROR> (and its synonym -C<$EXTENDED_OS_ERROR>) when used as strings always are in terms of the -current locale and as if within the scope of L<"use bytes"|bytes>. This is -likely to change in Perl v5.22. -(TBT) +変数 L<$!|perlvar/$ERRNO> (およびその同義語 C<$ERRNO> と C<$OS_ERROR>) と +L<$^E|perlvar/$EXTENDED_OS_ERROR> (およびその同義語 C<$EXTENDED_OS_ERROR>) は +文字列として使われると常に現在のロケールに従い、 +L<"use bytes"|bytes> のスコープ内にあるかのように振る舞います。 +これは Perl v5.22 で変更予定です。 =item * @@ -1131,6 +1130,8 @@ =head2 Testing for broken locales +(壊れたロケールのテスト) + =begin original If you are building Perl from source, the Perl test suite file @@ -1141,12 +1142,10 @@ =end original -If you are building Perl from source, the Perl test suite file -F<lib/locale.t> can be used to test the locales on your system. -Setting the environment variable C<PERL_DEBUG_FULL_TEST> to 1 -will cause it to output detailed results. For example, on Linux, you -could say -(TBT) +Perl をソースからビルドする場合、Perl テストスイートファイル +F<lib/locale.t> がシステムのロケールのテストに使われます。 +環境変数 C<PERL_DEBUG_FULL_TEST> を 1 に設定すると、詳細な結果を出力します。 +例えば、Linux では、以下のようにします: PERL_DEBUG_FULL_TEST=1 ./perl -T -Ilib lib/locale.t > locale.log 2>&1 @@ -1159,10 +1158,10 @@ =end original -Besides many other tests, it will test every locale it finds on your -system to see if they conform to the POSIX standard. If any have -errors, it will include a summary near the end of the output of which -locales passed all its tests, and which failed, and why. +その他の多くのテストに加えて、システムで発見された全てのロケールについてit will test every locale it finds on your +system to see if they conform to the POSIX standard. +エラーがあった場合、どのロケールが全てのテストに成功したかの出力の末尾辺りに、 +どのテストがなぜ失敗したかの概要が含まれます。 (TBT) =head2 Temporarily fixing locale problems @@ -1708,11 +1707,11 @@ =end original -Perl only supports single-byte locales for C<LC_COLLATE>. This means -that a UTF-8 locale likely will just give you machine-native ordering. -Use L<Unicode::Collate> for the full implementation of the Unicode -Collation Algorithm. -(TBT) +Perl は C<LC_COLLATE> に関して単一バイトロケールのみに対応しています。 +つまり、UTF-8 ロケールが単にマシンネイティブな順序を +提供するだろうということです。 +Unicode 照合アルゴリズムに関する完全な実装については L<Unicode::Collate> を +使ってください。 =begin original @@ -1884,8 +1883,8 @@ =end original -Starting in v5.20, Perl supports UTF-8 locales for C<LC_CTYPE>, but -otherwise Perl only supports single-byte locales, such as the ISO 8859 +v5.20 から、Perl は C<LC_CTYPE> に関して C<LC_CTYPE> に対応していますが、 +それ以外では Perl only supports single-byte locales, such as the ISO 8859 series. This means that wide character locales, for example for Asian languages, are not supported. The UTF-8 locale support is actually a superset of POSIX locales, because it is really full Unicode behavior @@ -2807,6 +2806,8 @@ =head2 String C<eval> and C<LC_NUMERIC> +(文字列 C<eval> と C<LC_NUMERIC>) + =begin original A string L<eval|perlfunc/eval EXPR> parses its expression as standard @@ -2816,11 +2817,10 @@ =end original -A string L<eval|perlfunc/eval EXPR> parses its expression as standard -Perl. It is therefore expecting the decimal point to be a dot. If -C<LC_NUMERIC> is set to have this be a comma instead, the parsing will -be confused, perhaps silently. -(TBT) +文字列 L<eval|perlfunc/eval EXPR> はその式を標準の Perl としてパースします。 +従って小数点がピリオドであることを想定します。 +もしこれがカンマであるように C<LC_NUMERIC> が設定されると、パースは +(おそらく暗黙の内に)混乱します。 use locale; use POSIX qw(locale_h); @@ -2836,9 +2836,9 @@ =end original -prints C<13,5>. This is because in that locale, the comma is the -decimal point character. The C<eval> thus expands to: -(TBT) +これは C<13,5> を表示します。 +これは、このロケールではカンマが小数点文字だからです。 +従って C<eval> はこれを次のように展開します: eval "1,2 + 1.5" @@ -2851,11 +2851,10 @@ =end original -and the result is not what you likely expected. No warnings are -generated. If you do string C<eval>'s within the scope of -S<C<use locale>>, you should instead change the C<eval> line to do -something like: -(TBT) +そして結果はおそらくあなたが想定したものではありません。 +警告は出ません。 +文字列 C<eval> を S<C<use locale>> スコープ内で行うなら、 +C<eval> 行を以下のように変えるべきです: print eval "no locale; $a + 1.5"; @@ -3169,9 +3168,8 @@ =end original -There are two cases, multi-byte and single-byte locales. First -multi-byte: -(TBT) +マルチバイトロケールと単一バイトロケールの二つの場合があります +まずマルチバイトの場合: =begin original @@ -3215,8 +3213,8 @@ 使っている C ライブラリは UTF-8 ロケールに対してこれらの関数が動作せず、 代わりに C<iswalnum()> のような新しいワイド文字ライブラリ関数のみが 動作するかもしれません。 -However, they are treated like single-byte locales, and will have the -restrictions described below. +しかし、これらは単一バイトロケールのように扱われ、後述するような +制限があります。 (TBT) =begin original @@ -3330,10 +3328,10 @@ =end original -Still another problem is that this approach can lead to two code -points meaning the same character. Thus in a Greek locale, both U+03A7 -and U+00D7 are GREEK CAPITAL LETTER CHI. -(TBT) +もう一つの問題は、この手法は同じ文字を意味する二つの符号位置を +持つことになることです。 +従ってギリシャ語ロケールでは、U+03A7 と U+00D7 はどちらも +GREEK CAPITAL LETTER CHI です。 =begin original Index: docs/perl/5.20.1/perldiag.pod diff -u docs/perl/5.20.1/perldiag.pod:1.6 docs/perl/5.20.1/perldiag.pod:1.7 --- docs/perl/5.20.1/perldiag.pod:1.6 Wed Mar 15 22:58:39 2017 +++ docs/perl/5.20.1/perldiag.pod Mon Sep 18 02:33:10 2017 @@ -3695,8 +3695,8 @@ =end original -(D deprecated) defined() は未定義の I<スカラ> 値を調べるので、配列に -使っても普通は正しくありません。 +(D deprecated) C<defined()> は普通はハッシュの右側ではないので、 +5.004 から非推奨でした。 =begin original Index: docs/perl/5.20.1/perlopentut.pod diff -u /dev/null docs/perl/5.20.1/perlopentut.pod:1.1 --- /dev/null Mon Sep 18 02:33:10 2017 +++ docs/perl/5.20.1/perlopentut.pod Mon Sep 18 02:33:10 2017 @@ -0,0 +1,622 @@ + +=encoding euc-jp + +=head1 NAME + +=begin original + +perlopentut - simple recipes for opening files and pipes in Perl + +=end original + +perlopentut - Perl でファイルを開いたりパイプを使ったりするための簡単なレシピ + +=head1 DESCRIPTION + +=begin original + +Whenever you do I/O on a file in Perl, you do so through what in Perl is +called a B<filehandle>. A filehandle is an internal name for an external +file. It is the job of the C<open> function to make the association +between the internal name and the external name, and it is the job +of the C<close> function to break that association. + +=end original + +Perl でファイルにタイして入出力をするとき、Perl では B<ファイルハンドル> と +呼ばれるものを通して行います。 +ファイルハンドルは外部ファイルに対する内部名です。 +C<open> 関数の仕事は内部名と外部名を関連づけることで、C<close> 関数は +関連づけを壊すことです。 + +=begin original + +For your convenience, Perl sets up a few special filehandles that are +already open when you run. These include C<STDIN>, C<STDOUT>, C<STDERR>, +and C<ARGV>. Since those are pre-opened, you can use them right away +without having to go to the trouble of opening them yourself: + +=end original + +便利なように、Perl は実行開始時に既に開いているいくつかの特別な +ファイルハンドルを設定します。 +それは C<STDIN>, C<STDOUT>, C<STDERR>, C<ARGV> です。 +これらは既に開いているので、自分でこれらを開くときの問題を受けることなく +正しく使うことができます。 + + print STDERR "This is a debugging message.\n"; + + print STDOUT "Please enter something: "; + $response = <STDIN> // die "how come no input?"; + print STDOUT "Thank you!\n"; + + while (<ARGV>) { ... } + +=begin original + +As you see from those examples, C<STDOUT> and C<STDERR> are output +handles, and C<STDIN> and C<ARGV> are input handles. They are +in all capital letters because they are reserved to Perl, much +like the C<@ARGV> array and the C<%ENV> hash are. Their external +associations were set up by your shell. + +=end original + +これらの例で見られるように、C<STDOUT> と C<STDERR> は出力ハンドルで、 +C<STDIN> と C<ARGV> は入力ハンドルです。 +これらは C<@ARGV> 配列や C<%ENV> ハッシュと同様に Perl によって +予約されているので、全て大文字になっています。 +これらの外部関連づけはシェルによって行われます。 + +=begin original + +You will need to open every other filehandle on your own. Although there +are many variants, the most common way to call Perl's open() function +is with three arguments and one return value: + +=end original + +その他のファイルハンドルは自分で開く必要があります。 +多くのバリエーションはありますが、Perl の open() 関数を開く最も一般的な方法は +3 引数と一つの返り値のものです: + +=begin original + +C< I<OK> = open(I<HANDLE>, I<MODE>, I<PATHNAME>)> + +=end original + +C< I<OK> = open(I<HANDLE>, I<MODE>, I<PATHNAME>)> + +=begin original + +Where: + +=end original + +ここで: + +=over + +=item I<OK> + +=begin original + +will be some defined value if the open succeeds, but +C<undef> if it fails; + +=end original + +これは、開くのに成功すれば何らかの定義された値、失敗すれば C<undef> です; + +=item I<HANDLE> + +=begin original + +should be an undefined scalar variable to be filled in by the +C<open> function if it succeeds; + +=end original + +これは、成功すれば C<open> 巻数によって埋められる未定義のスカラ変数です; + +=item I<MODE> + +=begin original + +is the access mode and the encoding format to open the file with; + +=end original + +これはファイルを開くときのアクセスモードとエンコーディング型式です; + +=item I<PATHNAME> + +=begin original + +is the external name of the file you want opened. + +=end original + +これは開きたいファイルの外部名です。 + +=back + +=begin original + +Most of the complexity of the C<open> function lies in the many +possible values that the I<MODE> parameter can take on. + +=end original + +C<open> 関数の複雑さの大部分は、I<MODE> 引数が多くの値を +取ることのできることにあります。 + +=begin original + +One last thing before we show you how to open files: opening +files does not (usually) automatically lock them in Perl. See +L<perlfaq5> for how to lock. + +=end original + +ファイルの開き方を説明する前に最後に一言: Perl ではファイルを開いても +(普通は)自動的にロックすることはしません。 +ロックの方法については L<perlfaq5> を参照してください。 + +=head1 Opening Text Files + +(テキストファイルを開く) + +=head2 Opening Text Files for Reading + +(読み込み用にテキストファイルを開く) + +=begin original + +If you want to read from a text file, first open it in +read-only mode like this: + +=end original + +If you want to read from a text file, first open it in +read-only mode like this: +(TBT) + + my $filename = "/some/path/to/a/textfile/goes/here"; + my $encoding = ":encoding(UTF-8)"; + my $handle = undef; # this will be filled in on success + + open($handle, "< $encoding", $filename) + || die "$0: can't open $filename for reading: $!"; + +=begin original + +As with the shell, in Perl the C<< "<" >> is used to open the file in +read-only mode. If it succeeds, Perl allocates a brand new filehandle for +you and fills in your previously undefined C<$handle> argument with a +reference to that handle. + +=end original + +As with the shell, in Perl the C<< "<" >> is used to open the file in +read-only mode. If it succeeds, Perl allocates a brand new filehandle for +you and fills in your previously undefined C<$handle> argument with a +reference to that handle. +(TBT) + +=begin original + +Now you may use functions like C<readline>, C<read>, C<getc>, and +C<sysread> on that handle. Probably the most common input function +is the one that looks like an operator: + +=end original + +Now you may use functions like C<readline>, C<read>, C<getc>, and +C<sysread> on that handle. Probably the most common input function +is the one that looks like an operator: +(TBT) + + $line = readline($handle); + $line = <$handle>; # same thing + +=begin original + +Because the C<readline> function returns C<undef> at end of file or +upon error, you will sometimes see it used this way: + +=end original + +Because the C<readline> function returns C<undef> at end of file or +upon error, you will sometimes see it used this way: +(TBT) + + $line = <$handle>; + if (defined $line) { + # do something with $line + } + else { + # $line is not valid, so skip it + } + +=begin original + +You can also just quickly C<die> on an undefined value this way: + +=end original + +You can also just quickly C<die> on an undefined value this way: +(TBT) + + $line = <$handle> // die "no input found"; + +=begin original + +However, if hitting EOF is an expected and normal event, you do not want to +exit simply because you have run out of input. Instead, you probably just want +to exit an input loop. You can then test to see if an actual error has caused +the loop to terminate, and act accordingly: + +=end original + +However, if hitting EOF is an expected and normal event, you do not want to +exit simply because you have run out of input. Instead, you probably just want +to exit an input loop. You can then test to see if an actual error has caused +the loop to terminate, and act accordingly: +(TBT) + + while (<$handle>) { + # do something with data in $_ + } + if ($!) { + die "unexpected error while reading from $filename: $!"; + } + +=begin original + +B<A Note on Encodings>: Having to specify the text encoding every time +might seem a bit of a bother. To set up a default encoding for C<open> so +that you don't have to supply it each time, you can use the C<open> pragma: + +=end original + +B<A Note on Encodings>: Having to specify the text encoding every time +might seem a bit of a bother. To set up a default encoding for C<open> so +that you don't have to supply it each time, you can use the C<open> pragma: +(TBT) + + use open qw< :encoding(UTF-8) >; + +=begin original + +Once you've done that, you can safely omit the encoding part of the +open mode: + +=end original + +Once you've done that, you can safely omit the encoding part of the +open mode: +(TBT) + + open($handle, "<", $filename) + || die "$0: can't open $filename for reading: $!"; + +=begin original + +But never use the bare C<< "<" >> without having set up a default encoding +first. Otherwise, Perl cannot know which of the many, many, many possible +flavors of text file you have, and Perl will have no idea how to correctly +map the data in your file into actual characters it can work with. Other +common encoding formats including C<"ASCII">, C<"ISO-8859-1">, +C<"ISO-8859-15">, C<"Windows-1252">, C<"MacRoman">, and even C<"UTF-16LE">. +See L<perlunitut> for more about encodings. + +=end original + +But never use the bare C<< "<" >> without having set up a default encoding +first. Otherwise, Perl cannot know which of the many, many, many possible +flavors of text file you have, and Perl will have no idea how to correctly +map the data in your file into actual characters it can work with. Other +common encoding formats including C<"ASCII">, C<"ISO-8859-1">, +C<"ISO-8859-15">, C<"Windows-1252">, C<"MacRoman">, and even C<"UTF-16LE">. +See L<perlunitut> for more about encodings. +(TBT) + +=head2 Opening Text Files for Writing + +(書き込み用にテキストファイルを開く) + +=begin original + +When you want to write to a file, you first have to decide what to do about +any existing contents of that file. You have two basic choices here: to +preserve or to clobber. + +=end original + +When you want to write to a file, you first have to decide what to do about +any existing contents of that file. You have two basic choices here: to +preserve or to clobber. +(TBT) + +=begin original + +If you want to preserve any existing contents, then you want to open the file +in append mode. As in the shell, in Perl you use C<<< ">>" >>> to open an +existing file in append mode. C<<< ">>" >>> creates the file if it does not +already exist. + +=end original + +If you want to preserve any existing contents, then you want to open the file +in append mode. As in the shell, in Perl you use C<<< ">>" >>> to open an +existing file in append mode. C<<< ">>" >>> creates the file if it does not +already exist. +(TBT) + + my $handle = undef; + my $filename = "/some/path/to/a/textfile/goes/here"; + my $encoding = ":encoding(UTF-8)"; + + open($handle, ">> $encoding", $filename) + || die "$0: can't open $filename for appending: $!"; + +=begin original + +Now you can write to that filehandle using any of C<print>, C<printf>, +C<say>, C<write>, or C<syswrite>. + +=end original + +Now you can write to that filehandle using any of C<print>, C<printf>, +C<say>, C<write>, or C<syswrite>. +(TBT) + +=begin original + +As noted above, if the file does not already exist, then the append-mode open +will create it for you. But if the file does already exist, its contents are +safe from harm because you will be adding your new text past the end of the +old text. + +=end original + +As noted above, if the file does not already exist, then the append-mode open +will create it for you. But if the file does already exist, its contents are +safe from harm because you will be adding your new text past the end of the +old text. +(TBT) + +=begin original + +On the other hand, sometimes you want to clobber whatever might already be +there. To empty out a file before you start writing to it, you can open it +in write-only mode: + +=end original + +On the other hand, sometimes you want to clobber whatever might already be +there. To empty out a file before you start writing to it, you can open it +in write-only mode: +(TBT) + + my $handle = undef; + my $filename = "/some/path/to/a/textfile/goes/here"; + my $encoding = ":encoding(UTF-8)"; + + open($handle, "> $encoding", $filename) + || die "$0: can't open $filename in write-open mode: $!"; + +=begin original + +Here again Perl works just like the shell in that the C<< ">" >> clobbers +an existing file. + +=end original + +Here again Perl works just like the shell in that the C<< ">" >> clobbers +an existing file. +(TBT) + +=begin original + +As with the append mode, when you open a file in write-only mode, +you can now write to that filehandle using any of C<print>, C<printf>, +C<say>, C<write>, or C<syswrite>. + +=end original + +As with the append mode, when you open a file in write-only mode, +you can now write to that filehandle using any of C<print>, C<printf>, +C<say>, C<write>, or C<syswrite>. +(TBT) + +=begin original + +What about read-write mode? You should probably pretend it doesn't exist, +because opening text files in read-write mode is unlikely to do what you +would like. See L<perlfaq5> for details. + +=end original + +What about read-write mode? You should probably pretend it doesn't exist, +because opening text files in read-write mode is unlikely to do what you +would like. See L<perlfaq5> for details. +(TBT) + +=head1 Opening Binary Files + +(バイナリファイルを開く) + +=begin original + +If the file to be opened contains binary data instead of text characters, +then the C<MODE> argument to C<open> is a little different. Instead of +specifying the encoding, you tell Perl that your data are in raw bytes. + +=end original + +If the file to be opened contains binary data instead of text characters, +then the C<MODE> argument to C<open> is a little different. Instead of +specifying the encoding, you tell Perl that your data are in raw bytes. +(TBT) + + my $filename = "/some/path/to/a/binary/file/goes/here"; + my $encoding = ":raw :bytes" + my $handle = undef; # this will be filled in on success + +=begin original + +And then open as before, choosing C<<< "<" >>>, C<<< ">>" >>>, or +C<<< ">" >>> as needed: + +=end original + +And then open as before, choosing C<<< "<" >>>, C<<< ">>" >>>, or +C<<< ">" >>> as needed: +(TBT) + + open($handle, "< $encoding", $filename) + || die "$0: can't open $filename for reading: $!"; + + open($handle, ">> $encoding", $filename) + || die "$0: can't open $filename for appending: $!"; + + open($handle, "> $encoding", $filename) + || die "$0: can't open $filename in write-open mode: $!"; + +=begin original + +Alternately, you can change to binary mode on an existing handle this way: + +=end original + +Alternately, you can change to binary mode on an existing handle this way: +(TBT) + + binmode($handle) || die "cannot binmode handle"; + +=begin original + +This is especially handy for the handles that Perl has already opened for you. + +=end original + +This is especially handy for the handles that Perl has already opened for you. +(TBT) + + binmode(STDIN) || die "cannot binmode STDIN"; + binmode(STDOUT) || die "cannot binmode STDOUT"; + +=begin original + +You can also pass C<binmode> an explicit encoding to change it on the fly. +This isn't exactly "binary" mode, but we still use C<binmode> to do it: + +=end original + +You can also pass C<binmode> an explicit encoding to change it on the fly. +This isn't exactly "binary" mode, but we still use C<binmode> to do it: +(TBT) + + binmode(STDIN, ":encoding(MacRoman)") || die "cannot binmode STDIN"; + binmode(STDOUT, ":encoding(UTF-8)") || die "cannot binmode STDOUT"; + +=begin original + +Once you have your binary file properly opened in the right mode, you can +use all the same Perl I/O functions as you used on text files. However, +you may wish to use the fixed-size C<read> instead of the variable-sized +C<readline> for your input. + +=end original + +Once you have your binary file properly opened in the right mode, you can +use all the same Perl I/O functions as you used on text files. However, +you may wish to use the fixed-size C<read> instead of the variable-sized +C<readline> for your input. +(TBT) + +=begin original + +Here's an example of how to copy a binary file: + +=end original + +Here's an example of how to copy a binary file: +(TBT) + + my $BUFSIZ = 64 * (2 ** 10); + my $name_in = "/some/input/file"; + my $name_out = "/some/output/flie"; + + my($in_fh, $out_fh, $buffer); + + open($in_fh, "<", $name_in) + || die "$0: cannot open $name_in for reading: $!"; + open($out_fh, ">", $name_out) + || die "$0: cannot open $name_out for writing: $!"; + + for my $fh ($in_fh, $out_fh) { + binmode($fh) || die "binmode failed"; + } + + while (read($in_fh, $buffer, $BUFSIZ)) { + unless (print $out_fh $buffer) { + die "couldn't write to $name_out: $!"; + } + } + + close($in_fh) || die "couldn't close $name_in: $!"; + close($out_fh) || die "couldn't close $name_out: $!"; + +=head1 Opening Pipes + +(パイプを開く) + +=begin original + +To be announced. + +=end original + +未定。 + +=head1 Low-level File Opens via sysopen + +(sysopen 経由で低レベルにファイルを開く) + +=begin original + +To be announced. Or deleted. + +=end original + +未定。 +または削除する。 + +=head1 SEE ALSO + +=begin original + +To be announced. + +=end original + +未定。 + +=head1 AUTHOR and COPYRIGHT + +Copyright 2013 Tom Christiansen. + +This documentation is free; you can redistribute it and/or modify it under +the same terms as Perl itself. + +=begin meta + +Translate: SHIRAKTA Kentaro <argra****@ub32*****> +Status: in progress + +=end meta +