[perldocjp-cvs 376] CVS update: docs/perl/5.8.8

Back to archive index

argra****@users***** argra****@users*****
2009年 1月 5日 (月) 04:18:26 JST


Index: docs/perl/5.8.8/perlpacktut.pod
diff -u docs/perl/5.8.8/perlpacktut.pod:1.8 docs/perl/5.8.8/perlpacktut.pod:1.9
--- docs/perl/5.8.8/perlpacktut.pod:1.8	Thu Jan  1 04:45:25 2009
+++ docs/perl/5.8.8/perlpacktut.pod	Mon Jan  5 04:18:26 2009
@@ -22,14 +22,11 @@
 =end original
 
 C<pack> は C<unpack> は、ユーザーが定義したテンプレートに従って、
-the guarded way Perl stores values と
-some well-defined representation as might be required in the 
-environment of a Perl program 
-の間を変換する二つの関数です。
+Perl が値を保管する保護された方法と、Perl プログラムの環境で必要になる
+かもしれないよく定義された表現の間を変換する二つの関数です。
 残念ながら、これらは Perl が提供する関数の中でもっとも誤解され、
 もっとも見落とされやすい関数でもあります。
 このチュートリアルではこれらを分かりやすく説明します。
-(TBT)
 
 =head1 The Basic Principle
 
@@ -87,18 +84,16 @@
 
 =end original
 
-あなたはどうしてバイナリ表現の中に値が含まれているメモリの塊が必要なのか、と
-問うかもしれません。
-よい理由の一つは、input and output accessing
-some file, a device, or a network connection, whereby this binary
-representation is either forced on you or will give you some benefit
-in processing.
+あなたはどうしてバイナリ表現の中に値が含まれているメモリの塊が
+必要なのか、と問うかもしれません。
+よい理由の一つは、ファイル、デバイス、ネットワーク接続にアクセスする
+入出力で、このバイナリ表現が強制されたものか、処理するためにいくらかの
+利益がある場合です。
 もう一つの原因は、Perl 関数として利用できないシステムコールにデータを
 渡すときです: C<syscall> は C プログラムでのような形で保管された引数を
 提供することを要求します。
 (以下の章で示すように) テキスト処理ですら、これら 2 つの関数を賢明に
 使うことで単純化できます。
-(TBT)
 
 =begin original
 
@@ -116,13 +111,11 @@
 (un)pack がどのように働くのかを見るために、変換がのろのろと行われる単純な
 テンプレートコードから始めましょう: バイトシーケンスと 16 進数の文字列との
 変換です。
-C<unpack> を使いましょう; なぜならこれはダンププログラムを
-思い出させそうであるか、or some desperate last
-message unfortunate programs are wont to throw at you before they expire
-into the wild blue yonder.
+C<unpack> を使いましょう; なぜならこれはダンププログラムや、
+不幸なプログラムが息を引き取る前にあなたに投げかけることが常となっている
+絶望的な最後のメッセージを思い出させそうだからです。
 変数 C<$mem> に、その意味について何の仮定もおかずに調査したいバイト列が
 入っていると仮定すると、以下のように書きます:
-(TBT)
 
    my( $hex ) = unpack( 'H*', $mem );
    print "$hex\n";
@@ -163,15 +156,15 @@
 使っていると仮定します: C<0x40> - C<0x5A> 範囲の 16 進数は大文字を
 示していて、C<0x20> は空白をエンコードしたものです。
 それで、これは、タブロイドのように読むことのできるテキストの断片と
-仮定できます;
-but others will have to get hold of an ASCII table and relive that
-firstgrader feeling. Not caring too much about which way to read this,
+仮定できます; その他は ASCII テーブルを持って 1 年生の感覚を思い出す
+必要があります。
+これをどのようにして読むかについてはあまり気にしないことにして、
 we note that C<unpack> with the template code C<H> converts the contents
 of a sequence of bytes into the customary hexadecimal notation. Since
-"a sequence of" is a pretty vague indication of quantity, C<H> has been
-defined to convert just a single hexadecimal digit unless it is followed
-by a repeat count. An asterisk for the repeat count means to use whatever
-remains.
+"a sequence of" is a pretty vague indication of quantity,
+C<H> は、引き続いて繰り返し回数がない場合は単に 1 つの 16 進数を
+変換するように定義されています。
+繰り返し数でのアスタリスクは、残っているもの全てを使うことを意味します。
 (TBT)
 
 =begin original
@@ -384,13 +377,12 @@
 =end original
 
 ここで少し賢くやりましょう。
-Lines in our ledger which are just income and
-not expenditure might end at column 46. Hence, we don't want to tell our
-C<unpack> pattern that we B<need> to find another 12 characters; we'll
-just say "if there's anything left, take it". As you might guess from
-regular expressions, that's what the C<*> means: "use everything
-remaining".
-(TBT)
+台帳のうち、収入だけがあって支出がない行は 46 行目で終わっています。
+従って、次の 12 文字を見つける B<必要がある> ということを
+C<unpack> パターンに書きたくはありません;
+単に次のようにします「もし何かが残っていれば、それを取ります」。
+正規表現から推測したかもしれませんが、これが C<*> の意味することです:
+「残っているもの全てを使います」。
 
 =over 3
 
@@ -777,12 +769,12 @@
 
 これは全ての数値テンプレートコードに対して真です。
 しかし奇跡を期待してはいけません:
-if the packed value exceeds the allotted byte capacity, high order bits
-are silently discarded, and unpack certainly won't be able to pull them
-back out of some magic hat. And, when you pack using a signed template
-code such as C<s>, an excess value may result in the sign bit
-getting set, and unpacking this will smartly return a negative value.
-(TBT)
+もし pack された値が割り当てられたバイト容量を超えると、高位ビットは
+黙って捨てられ、unpack は確実に魔法の帽子からデータを
+取り出すことができません。
+そして、C<s> のような符号付きテンプレートコードを使って pack すると、
+超えた値が符号ビットをセットすることになり、unpack すると負の値が
+返されることになるかもしれません。
 
 =begin original
 
@@ -1235,13 +1227,13 @@
 
 =end original
 
-An even stranger template code is C<%>E<lt>I<number>E<gt>. First, because 
-it's used as a prefix to some other template code. Second, because it
-cannot be used in C<pack> at all, and third, in C<unpack>, doesn't return the
-data as defined by the template code it precedes. Instead it'll give you an
-integer of I<number> bits that is computed from the data value by 
-doing sums. For numeric unpack codes, no big feat is achieved:
-(TBT)
+さらに不思議なテンプレートコードは C<%>E<lt>I<number>E<gt> です。
+第一に、これはその他のテンプレートコードの前置詞として使われるからです。
+第二に、C<pack> では全く使えず、第三に、C<unpack> では、先行する
+テンプレートコードによって定義された値を返さないからです。
+代わりに、これはデータの合計として計算された I<number> ビットの整数を
+与えます。
+数値 unpack コードでは、大きな離れ業は行われません:
 
     my $buf = pack( 'iii', 100, 20, 3 );
     print unpack( '%32i3', $buf ), "\n";  # prints 123
@@ -1253,9 +1245,8 @@
 
 =end original
 
-文字列値に対しては、C<%> returns the sum of the byte values saving
-you the trouble of a sum loop with C<substr> and C<ord>:
-(TBT)
+文字列値に対しては、C<%> はバイト値の合計を返し、C<substr> と C<ord> による
+合計計算ループによる問題からあなたを救います:
 
     print unpack( '%32A*', "\x01\x10" ), "\n";  # prints 17
 
@@ -1464,9 +1455,8 @@
 
 =end original
 
-which returns a string consisting of the first character from each string.
-pack を使うと、以下のように書けて
-(TBT)
+これは、それぞれの文字列の最初の文字からなる文字列を返します。
+pack を使うと、以下のように書けます:
 
    pack( '(A)'. @ str, @str )
 
@@ -1655,11 +1645,10 @@
 
 =end original
 
-The pack code preceding C</> may be anything that's fit to represent a
-number:
+C</> の前に置く pack コードは、数値を表現するのに適したものであれば
+なんでも使えます: 
 全ての数値バイナリ pack コードおよび、C<A4> や C<Z*> のような
 テキストコードにも対応します:
-(TBT)
 
    # pack/unpack a string preceded by its length in ASCII
    my $buf = pack( 'A4/A*', "Humpty-Dumpty" );
@@ -1755,9 +1744,8 @@
 
 =end original
 
-逆操作のために、we'll have to determine the number of items
-in the buffer before we can let C<unpack> rip it apart:
-(TBT)
+逆操作のために、C<unpack> に分解させる前にバッファにあるアイテムの数を
+決定する必要があります:
 
    my $n = $env =~ tr/\0// - 1;
    my %env = map( split( /=/, $_ ), unpack( "(Z*)$n", $env ) );
@@ -2173,10 +2161,10 @@
 
 サイズは様々であるとしています。
 構造のアライメント制約は、それぞれの要素よりも大きいかもしれません。
-[And if you think that this doesn't affect anything
-common, dismember the next cellphone that you see. Many have ARM cores, and
-the ARM structure rules make C<sizeof (foo_t)> == 4]
-(TBT)
+[そしてもしこれが一般的には何も影響を与えないと考えているなら、
+次に見た携帯電話を分解してみてください。
+多くは ARM コアを使っていて、ARM ストラクチャルールでは
+C<sizeof (foo_t)> == 4 となります]
 
 =head2 Pointers for How to Use Them
 
@@ -2226,12 +2214,10 @@
 =end original
 
 ちょっと待った: C<pack> は単にバイトシーケンスを返すのでは?
-How can we pass this
-string of bytes to some C code expecting a pointer which is, after all,
-nothing but a number?
+どうやってこのバイトの文字列を、ポインタ、つまり結局は数値でしかないものを
+想定している C のコードに渡せるのでしょう?
 答えは単純です: C<pack> で返されたバイト列から数値のアドレスを得なければ
 なりません。
-(TBT)
 
     my $ptr = unpack( 'L!', $memptr );
 


perldocjp-cvs メーリングリストの案内
Back to archive index