argra****@users*****
argra****@users*****
2010年 7月 25日 (日) 06:03:17 JST
Index: docs/perl/5.10.1/perlfaq4.pod diff -u docs/perl/5.10.1/perlfaq4.pod:1.5 docs/perl/5.10.1/perlfaq4.pod:1.6 --- docs/perl/5.10.1/perlfaq4.pod:1.5 Thu Jul 22 04:15:55 2010 +++ docs/perl/5.10.1/perlfaq4.pod Sun Jul 25 06:03:17 2010 @@ -209,10 +209,9 @@ =end original -You can always check the value you're using by printing it in octal -notation to ensure it matches what you think it should be. +使っている値があなたの考えている形と一致しているかを確認するために、 +いつでも値を 8 進表記で表示することでチェックできます。 8 進数と 10 進数で表示します: -(TBT) printf "0%o %d", $number, $number; @@ -1950,10 +1949,9 @@ もし 5 と答えたなら、あなたは正しいです。 Perl での単語は C<\w+> の集合ですが、これはあなたが キャピタライズしたいものではありません。 -How is Perl supposed to know not to capitalize -that C<s> after the apostrophe? +アポストロフィの後の C<s> はキャピタライズしないように Perl に +知らせるには? 正規表現に挑戦してみましょう: -(TBT) $string =~ s/ ( (^\w) #at the beginning of the line @@ -3876,14 +3874,12 @@ =end original -例えば、 -you don't have to store individual bits in an array -(which would mean that you're wasting a lot of space). +例えば、それぞれのビットを配列に格納する(これをすると多くのメモリが +無駄になります)必要はありません。 ビットの配列を文字列に変換するには、正しいビットをセットするのに C<vec()> 使います。 これは、C<$ints[N]> がセットされている場合のみ C<$vec> の bit N を セットします。 -(TBT) @ints = (...); # array of bits, e.g. ( 1, 0, 0, 1, 1, 0 ... ) $vec = ''; @@ -4201,10 +4197,9 @@ =end original -Before you decide to merge two hashes, you have to decide what to do -if both hashes contain keys that are the same and if you want to leave -the original hashes as they were. -(TBT) +二つのハッシュをマージしようと決める前に、もし両方のハッシュに +同じキーがあったときにどうするかと、元のハッシュをそのままに +しておくかどうかを決める必要があります。 =begin original @@ -4216,12 +4211,11 @@ =end original -If you want to preserve the original hashes, copy one hash (C<%hash1>) -to a new hash (C<%new_hash>), then add the keys from the other hash -(C<%hash2> to the new hash. Checking that the key already exists in -C<%new_hash> gives you a chance to decide what to do with the -duplicates: -(TBT) +もし元のハッシュを保存しておきたいなら、一つのハッシュ (C<%hash1>) を +新しいハッシュ (C<%new_hash>) にコピーして、それからもう一つのハッシュ +(C<%hash2>) からキーを新しいハッシュに追加します。 +キーが既に C<%new_hash> にある場合、重複をどうするかを決定する +機会が与えられます: my %new_hash = %hash1; # make a copy; leave %hash1 alone @@ -4247,9 +4241,8 @@ =end original -If you don't want to create a new hash, you can still use this looping -technique; just change the C<%new_hash> to C<%hash1>. -(TBT) +新しいハッシュを作りたくない場合は、やはりこのループ技術が使えます; +単に C<%new_hash> を C<%hash1> に変更します。 foreach my $key2 ( keys %hash2 ) { @@ -4274,10 +4267,10 @@ =end original -If you don't care that one hash overwrites keys and values from the other, you -could just use a hash slice to add one hash to another. In this case, values -from C<%hash2> replace values from C<%hash1> when they have keys in common: -(TBT) +片方のキーと値がもう片方で上書きされても気にしないなら、片方のハッシュから +もう片方に追加するために単にハッシュスライスを使えます。 +この場合、共通のキーがあった場合は、 +C<%hash1> の値は C<%hash2> の値で置き換えられます: @hash1{ keys %hash2 } = values %hash2; @@ -4311,12 +4304,11 @@ =end original -If you iterate through the hash with each(), you can delete the key -most recently returned without worrying about it. If you delete or add -other keys, the iterator may skip or double up on them since perl -may rearrange the hash table. +ハッシュを each() で反復すると、それについて気にすることなく、 +最後に返されたキーを削除できます。 +他のキーを削除または追加すると、perl はハッシュテーブルを再構成するので、 +反復子はキーを読み飛ばしたり重複して読んだりするかもしれません。 L<perlfunc> の C<each()> のエントリを参照してください。 -(TBT) =head2 How do I look up a hash element by value? @@ -5035,12 +5027,11 @@ =end original -Remember that the entry in the hash will still be there even if -the referenced variable goes out of scope, and that it is entirely -possible for Perl to subsequently allocate a different variable at -the same address. This will mean a new variable might accidentally -be associated with the value for an old. -(TBT) +ハッシュのエントリはリファレンスされた値がスコープ外に出ても +存在していて、その後 Perl が同じアドレスに別の変数を割り当てる可能性が +あることを忘れないでください。 +これは、新しい変数が偶然古い変数の値と関連づけられるかもしれないことを +意味します。 =begin original @@ -5054,14 +5045,13 @@ =end original -If you have Perl 5.10 or later, and you just want to store a value -against the reference for lookup later, you can use the core -Hash::Util::Fieldhash module. This will also handle renaming the -keys if you use multiple threads (which causes all variables to be -reallocated at new addresses, changing their stringification), and -garbage-collecting the entries when the referenced variable goes out -of scope. -(TBT) +Perl 5.10 以降を使っていて、単に後で参照するためにリファレンスで +値を保管したいだけなら、 +コアの Hash::Util::Fieldhash モジュールが使えます。 +これはまた、もしマルチスレッドを使っている(つまり全ての変数は +新しいアドレスに再割り当てされ、文字列化した結果が変わる)場合は +キーの名前の変更を扱い、リファレンスされた変数がスコープ外に +出た場合はガベージコレクションを行います。 =begin original @@ -5071,10 +5061,8 @@ =end original -If you actually need to be able to get a real reference back from -each hash entry, you can use the Tie::RefHash module, which does the -required work for you. -(TBT) +本当にそれぞれのハッシュエントリから実際のリファレンスを得る必要があるのなら、 +それに必要な作業を行う Tie::RefHash モジュールが使えます。 =head1 Data: Misc @@ -5309,13 +5297,12 @@ =end original C<UNIVERSAL> クラス (L<UNIVERSAL>) を参照してください)が使えます。 -However, please -be very careful to consider the consequences of doing this: adding -methods to every object is very likely to have unintended -consequences. If possible, it would be better to have all your object -inherit from some common base class, or to use an object system like -Moose that supports roles. -(TBT) +しかし、これを行うことによる結果の考慮についてはとても注意深く行ってください: +全てのオブジェクトにメソッドを追加すると、想定外の結果になる可能性が +とても高いです。 +可能なら、あなたの作る全てのオブジェクトを共通の基底クラスから +継承するようにするか、ロールに対応している Moose のような +オブジェクトシステムを使う方が良いです。 =head2 How do I verify a credit card checksum? Index: docs/perl/5.10.1/perlfaq5.pod diff -u docs/perl/5.10.1/perlfaq5.pod:1.3 docs/perl/5.10.1/perlfaq5.pod:1.4 --- docs/perl/5.10.1/perlfaq5.pod:1.3 Thu Jul 22 04:15:55 2010 +++ docs/perl/5.10.1/perlfaq5.pod Sun Jul 25 06:03:17 2010 @@ -106,11 +106,11 @@ =end original -The C<$|> is one of the per-filehandle special variables, so each -filehandle has its own copy of its value. If you want to merge -standard output and standard error for instance, you have to unbuffer -each (although STDERR might be unbuffered by default): -(TBT) +C<$|> はファイルハンドル単位の特殊変数の一つで、ファイルハンドル毎に +この値のコピーを保持しています。 +例えば、標準出力と標準エラーをまとめたいなら、それぞれのバッファリングを +解除する必要があります(但し、STDERR はデフォルトでは +バッファリングしていないはずです): { my $previous_default = select(STDOUT); # save previous default @@ -155,9 +155,8 @@ =end original -For more information on output layers, see the entries for C<binmode> -and C<open> in L<perlfunc>, and the C<PerlIO> module documentation. -(TBT) +出力層に関するさらなる情報については、L<perlfunc> の C<binmode> および +C<open> のエントリと、C<PerlIO> モジュールの文書を参照してください。 =begin original @@ -167,10 +166,8 @@ =end original -If you are using C<IO::Handle> or one of its subclasses, you can -call the C<autoflush> method to change the settings of the -filehandle: -(TBT) +C<IO::Handle> かその派生クラスを使っているなら、ファイルハンドルの設定を +変更するために C<autoflush> メソッドを呼び出せます: use IO::Handle; open my( $io_fh ), ">", "output.txt"; @@ -183,9 +180,8 @@ =end original -The C<IO::Handle> objects also have a C<flush> method. You can flush -the buffer any time you want without auto-buffering -(TBT) +C<IO::Handle> オブジェクトには C<flush> メソッドもあります。 +いつでも自動バッファリングなしにバッファをフラッシュできます $io_fh->flush; Index: docs/perl/5.10.1/perlfaq6.pod diff -u docs/perl/5.10.1/perlfaq6.pod:1.3 docs/perl/5.10.1/perlfaq6.pod:1.4 --- docs/perl/5.10.1/perlfaq6.pod:1.3 Thu Jul 22 04:15:55 2010 +++ docs/perl/5.10.1/perlfaq6.pod Sun Jul 25 06:03:17 2010 @@ -323,6 +323,8 @@ X<regex, XML> X<regex, HTML> X<XML> X<HTML> X<pain> X<frustration> X<sucking out, will to live> +(XML, HTML あるいはその他の扱いにくくて不細工なものを正規表現でマッチングさせるには?) + =begin original (contributed by brian d foy) @@ -981,8 +983,9 @@ =end original -Your first try should probably be the C<Text::Balanced> module, which -is in the Perl standard library since Perl 5.8. It has a variety of +おそらく、まずはじめに試すべきなのは、Perl 5.8 から Perl 標準ライブラリに +なっている C<Text::Balanced> モジュールです。 +It has a variety of functions to deal with tricky text. The C<Regexp::Common> module can also help by providing canned patterns you can use. (TBT) @@ -995,8 +998,9 @@ =end original -As of Perl 5.10, you can match balanced text with regular expressions -using recursive patterns. Before Perl 5.10, you had to resort to +Perl 5.10 以降では、再帰パターンを使って正規表現でバランスされた +テキストをマッチングすることが出来ます。 +Before Perl 5.10, you had to resort to various tricks such as using Perl code in C<(??{})> sequences. (TBT) @@ -1010,7 +1014,8 @@ =end original -Here's an example using a recursive regular expression. The goal is to +以下は再帰的正規表現を使った例です。 +The goal is to capture all of the text within angle brackets, including the text in nested angle brackets. This sample text has two "major" groups: a group with one level of nesting and a group with two levels of @@ -1029,10 +1034,10 @@ =end original -The regular expression to match the balanced text uses two new (to -Perl 5.10) regular expression features. These are covered in L<perlre> -and this example is a modified version of one in that documentation. -(TBT) +バランスされたテキストにマッチングする正規表現は二つの新しい +(Perl 5.10 以降の)正規表現の機能を使います。 +これらは L<perlre> で説明されていて、この例はその文書にあるものの +修正版です。 =begin original Index: docs/perl/5.10.1/perlfaq7.pod diff -u docs/perl/5.10.1/perlfaq7.pod:1.3 docs/perl/5.10.1/perlfaq7.pod:1.4 --- docs/perl/5.10.1/perlfaq7.pod:1.3 Thu Jul 22 04:15:55 2010 +++ docs/perl/5.10.1/perlfaq7.pod Sun Jul 25 06:03:17 2010 @@ -1576,11 +1576,10 @@ =end original -Calling a subroutine as C<&foo> with no trailing parentheses ignores -the prototype of C<foo> and passes it the current value of the argumet -list, C<@_>. Here's an example; the C<bar> subroutine calls C<&foo>, -which prints what its arguments list: -(TBT) +C<&foo> の形で、引き続くかっこなしでサブルーチンを呼び出すと、 +C<foo> のプロトタイプを無視して、引数リスト C<@_> の現在の値を渡します。 +以下は例です: C<bar> サブルーチンは、引数リストを表示する C<&foo> を +呼び出します: sub bar { &foo } @@ -1606,10 +1605,9 @@ =end original -Calling the subroutine with trailing parentheses, with or without arguments, -does not use the current C<@_> and respects the subroutine prototype. Changing -the example to put parentheses after the call to C<foo> changes the program: -(TBT) +サブルーチンをかっこ付きで呼び出した場合、引数のありなしに関わらず、 +現在の C<@_> は使わずに、サブルーチンのプロトタイプに従います。 +C<foo> を呼び出すときにかっこをつけるように例を変更します: sub bar { &foo() }