オープンソース・ソフトウェアの開発とダウンロード

CVS リポジトリの参照

Annotation of /perldocjp/docs/perl/5.18.1/perltrap.pod

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Sat Aug 24 08:14:45 2013 UTC (10 years, 8 months ago) by argrath
Branch: MAIN
CVS Tags: HEAD
update 5.16.1 to 5.18.1 with trivial changes

1 argrath 1.1
2     =encoding euc-jp
3    
4     =head1 NAME
5    
6     =begin original
7    
8     perltrap - Perl traps for the unwary
9    
10     =end original
11    
12     perltrap - 不注意による Perl の罠
13    
14     =head1 DESCRIPTION
15    
16     =begin original
17    
18     The biggest trap of all is forgetting to C<use warnings> or use the B<-w>
19     switch; see L<perllexwarn> and L<perlrun>. The second biggest trap is not
20     making your entire program runnable under C<use strict>. The third biggest
21     trap is not reading the list of changes in this version of Perl; see
22     L<perldelta>.
23    
24     =end original
25    
26     最も大きな罠とは、C<use warnings> あるいは B<-w> スイッチを使うのを
27     忘れてしまうということです; L<perllexwarn> と L<perlrun> を
28     参照してください。
29     二番目に大きな罠とは、あなたのプログラム全体を C<use strict> の元で
30     実行しないということです。
31     三番目の罠は、このバージョンの Perl での変更点を読まないということです;
32     L<perldelta> を参照してください。
33    
34     =head2 Awk Traps
35    
36     (awk の罠)
37    
38     =begin original
39    
40     Accustomed B<awk> users should take special note of the following:
41    
42     =end original
43    
44     B<awk> に慣れた方は、以下のようなことに特に注意してください:
45    
46     =over 4
47    
48     =item *
49    
50     =begin original
51    
52     A Perl program executes only once, not once for each input line. You can
53     do an implicit loop with C<-n> or C<-p>.
54    
55     =end original
56    
57     Perl のプログラムは、1 度だけ実行されます; 入力行毎ではありません。
58     C<-n> や C<-p> を使って暗黙のループを使えます。
59    
60     =item *
61    
62     =begin original
63    
64     The English module, loaded via
65    
66     =end original
67    
68     Englishモジュールを
69    
70     use English;
71    
72     =begin original
73    
74     allows you to refer to special variables (like C<$/>) with names (like
75     $RS), as though they were in B<awk>; see L<perlvar> for details.
76    
77     =end original
78    
79     のようにしてロードすれば、B<awk> でそうであったように
80     (C<$/> のような)特殊変数を($RS のような)名前で参照することができます;
81     詳しくは L<perlvar> を参照してください。
82    
83     =item *
84    
85     =begin original
86    
87     Semicolons are required after all simple statements in Perl (except
88     at the end of a block). Newline is not a statement delimiter.
89    
90     =end original
91    
92     Perlでは、すべての単純文(simple statement)の末尾にセミコロンが必要です
93     (ブロックの最後に置かれたときを除きます)。
94     改行は文の区切りとはなりません。
95    
96     =item *
97    
98     =begin original
99    
100     Curly brackets are required on C<if>s and C<while>s.
101    
102     =end original
103    
104     C<if> や C<while> では中かっこが必要です。
105    
106     =item *
107    
108     =begin original
109    
110     Variables begin with "$", "@" or "%" in Perl.
111    
112     =end original
113    
114     Perlでは、変数は“$”"か“@”か“%”で始まります。
115    
116     =item *
117    
118     =begin original
119    
120     Arrays index from 0. Likewise string positions in substr() and
121     index().
122    
123     =end original
124    
125     配列の添え字は 0 から始まります。
126     substr() や index() での文字列の位置も同様です。
127    
128     =item *
129    
130     =begin original
131    
132     You have to decide whether your array has numeric or string indices.
133    
134     =end original
135    
136     配列の添え字が数値であるか、文字列であるかを決めなければなりません。
137    
138     =item *
139    
140     =begin original
141    
142     Hash values do not spring into existence upon mere reference.
143    
144     =end original
145    
146     ハッシュ(連想配列)の値は、単に参照するだけでは存在することに
147     なりません。
148    
149     =item *
150    
151     =begin original
152    
153     You have to decide whether you want to use string or numeric
154     comparisons.
155    
156     =end original
157    
158     比較を文字列によって行うのか、数値によって行うのかを
159     決めなければなりません。
160    
161     =item *
162    
163     =begin original
164    
165     Reading an input line does not split it for you. You get to split it
166     to an array yourself. And the split() operator has different
167     arguments than B<awk>'s.
168    
169     =end original
170    
171     入力を読み込むだけでは split は行われません。
172     配列への split は自分で行います。
173     また、split() 演算子の引数は B<awk> のものと異なっています。
174    
175     =item *
176    
177     =begin original
178    
179     The current input line is normally in $_, not $0. It generally does
180     not have the newline stripped. ($0 is the name of the program
181     executed.) See L<perlvar>.
182    
183     =end original
184    
185     通常、カレント行は $0 ではなく $_ にあります。
186     一般的に、改行は取り除かれません。
187     ($0 には実行しているプログラムの名前があります)。
188     L<perlvar> を参照してください。
189    
190     =item *
191    
192     =begin original
193    
194     $<I<digit>> does not refer to fields--it refers to substrings matched
195     by the last match pattern.
196    
197     =end original
198    
199     $<I<digit>> はフィールドを参照しません--これは直前に行った
200     パターンマッチングの部分文字列を参照します。
201    
202     =item *
203    
204     =begin original
205    
206     The print() statement does not add field and record separators unless
207     you set C<$,> and C<$\>. You can set $OFS and $ORS if you're using
208     the English module.
209    
210     =end original
211    
212     print() 文は、C<$,> や C<$\> に値を設定しない限りフィールド区切り子や
213     レコード区切り子を付加しません。
214     English モジュールを使っていれば、$OFS や $ORS に対して設定することでも
215     OK です。
216    
217     =item *
218    
219     =begin original
220    
221     You must open your files before you print to them.
222    
223     =end original
224    
225     ファイルに対して出力する前には、そのファイルをあらかじめオープンして
226     おかなければなりません。
227    
228     =item *
229    
230     =begin original
231    
232     The range operator is "..", not comma. The comma operator works as in
233     C.
234    
235     =end original
236    
237     範囲演算子は“..”であって、カンマではありません。
238     カンマ演算子は C と同じような振る舞いをします。
239    
240     =item *
241    
242     =begin original
243    
244     The match operator is "=~", not "~". ("~" is the one's complement
245     operator, as in C.)
246    
247     =end original
248    
249     マッチ演算子は“=~”であって、“~”ではありません。
250     (“~”はCと同様に、1の補数を取る演算子です。)
251    
252     =item *
253    
254     =begin original
255    
256     The exponentiation operator is "**", not "^". "^" is the XOR
257     operator, as in C. (You know, one could get the feeling that B<awk> is
258     basically incompatible with C.)
259    
260     =end original
261    
262     べき乗の演算子は“**”であって、“^”ではありません。
263     “^”は C と同様、XOR 演算子です。
264     (B<awk> が基本的に C と非互換であることにお気付きかもしれませんね。)
265    
266     =item *
267    
268     =begin original
269    
270     The concatenation operator is ".", not the null string. (Using the
271     null string would render C</pat/ /pat/> unparsable, because the third slash
272     would be interpreted as a division operator--the tokenizer is in fact
273     slightly context sensitive for operators like "/", "?", and ">".
274     And in fact, "." itself can be the beginning of a number.)
275    
276     =end original
277    
278     連接演算子は“.”であって、空文字列ではありません。
279     (空文字列を使ってしまうと C</pat/ /pat/> が、その 3 番目のスラッシュが
280     除算演算子と解釈されてしまうので正しく解析できなくなります--
281     Perl の字句解析器は "/", "?", ">" といった演算子に対して
282     多少文脈依存となっています。
283     実際、"." 自身も数値の始まりとなる可能性もあります。)
284    
285     =item *
286    
287     =begin original
288    
289     The C<next>, C<exit>, and C<continue> keywords work differently.
290    
291     =end original
292    
293     キーワード C<next>, C<exit>, C<continue> の振る舞いが異なります。
294    
295     =item *
296    
297     =begin original
298    
299     The following variables work differently:
300    
301     =end original
302    
303     以下の変数の働きが異なります。
304    
305     Awk Perl
306     ARGC scalar @ARGV (compare with $#ARGV)
307     ARGV[0] $0
308     FILENAME $ARGV
309     FNR $. - something
310     FS (whatever you like)
311     NF $#Fld, or some such
312     NR $.
313     OFMT $#
314     OFS $,
315     ORS $\
316     RLENGTH length($&)
317     RS $/
318     RSTART length($`)
319     SUBSEP $;
320    
321     =item *
322    
323     =begin original
324    
325     You cannot set $RS to a pattern, only a string.
326    
327     =end original
328    
329     $RS に正規表現をセットすることはできません; できるのは文字列だけです。
330    
331     =item *
332    
333     =begin original
334    
335     When in doubt, run the B<awk> construct through B<a2p> and see what it
336     gives you.
337    
338     =end original
339    
340     妙だと思ったときには B<awk> の構文を B<a2p> に通して、出力されたものを
341     見てみましょう。
342    
343     =back
344    
345     =head2 C/C++ Traps
346    
347     (C/++ の罠)
348    
349     =begin original
350    
351     Cerebral C and C++ programmers should take note of the following:
352    
353     =end original
354    
355     知的な C と C++ のプログラマは以下のことに注意すべきです:
356    
357     =over 4
358    
359     =item *
360    
361     =begin original
362    
363     Curly brackets are required on C<if>'s and C<while>'s.
364    
365     =end original
366    
367     C<if> や C<while> には中かっこが必要です。
368    
369     =item *
370    
371     =begin original
372    
373     You must use C<elsif> rather than C<else if>.
374    
375     =end original
376    
377     C<else if> ではなく、C<elsif> を使わなければなりません。
378    
379     =item *
380    
381     =begin original
382    
383     The C<break> and C<continue> keywords from C become in Perl C<last>
384     and C<next>, respectively. Unlike in C, these do I<not> work within a
385     C<do { } while> construct. See L<perlsyn/"Loop Control">.
386    
387     =end original
388    
389     C の C<break> と C<continue> は、Perl ではそれぞれ C<last> と
390     C<next> となります。
391     C とは異なり、これらは C<do { } while> 構文では I<使えません>。
392     L<perlsyn/"Loop Control"> を参照してください。
393    
394     =item *
395    
396     =begin original
397    
398     The switch statement is called C<given/when> and only available in
399     perl 5.10 or newer. See L<perlsyn/"Switch Statements">.
400    
401     =end original
402    
403     switch 文は C<given/when> と呼ばれ、perl 5.10 以降でのみ利用可能です。
404     L<perlsyn/"Switch Statements"> を参照してください。
405    
406     =item *
407    
408     =begin original
409    
410     Variables begin with "$", "@" or "%" in Perl.
411    
412     =end original
413    
414     Perlでは、変数は“$”"か“@”か“%”で始まります。
415    
416     =item *
417    
418     =begin original
419    
420     Comments begin with "#", not "/*" or "//". Perl may interpret C/C++
421     comments as division operators, unterminated regular expressions or
422     the defined-or operator.
423    
424     =end original
425    
426     コメントの始まりは、“#”であり、“/*”や "//" ではありません。
427     Perl は C/C++ のコメントを除算演算子、終端していない正規表現、
428     定義性和演算子として解釈するかもしれません。
429    
430     =item *
431    
432     =begin original
433    
434     You can't take the address of anything, although a similar operator
435     in Perl is the backslash, which creates a reference.
436    
437     =end original
438    
439     なにかのアドレスを得ることはできません; Perl には似たような演算子である
440     バックスラッシュがありますが、これはリファレンスを生成します。
441    
442     =item *
443    
444     =begin original
445    
446     C<ARGV> must be capitalized. C<$ARGV[0]> is C's C<argv[1]>, and C<argv[0]>
447     ends up in C<$0>.
448    
449     =end original
450    
451     C<ARGV> は大文字でなければなりません。
452     C<$ARGV[0]> が C での C<argv[1]> に相当し、C<argv[0]> にあたるものは
453     C<$0> です。
454    
455     =item *
456    
457     =begin original
458    
459     System calls such as link(), unlink(), rename(), etc. return nonzero for
460     success, not 0. (system(), however, returns zero for success.)
461    
462     =end original
463    
464     link(), unlink(), rename() などのシステムコールは、成功時に
465     0 ではなく非 0 の値を返します。
466     (但し、system() は成功時に 0 を返します。)
467    
468     =item *
469    
470     =begin original
471    
472     Signal handlers deal with signal names, not numbers. Use C<kill -l>
473     to find their names on your system.
474    
475     =end original
476    
477     シグナルハンドラは、シグナル番号ではなくシグナル名を扱います。
478     使用できるシグナル名は、kill -l として確かめてください。
479    
480     =back
481    
482     =head2 Sed Traps
483    
484     (sed の罠)
485    
486     =begin original
487    
488     Seasoned B<sed> programmers should take note of the following:
489    
490     =end original
491    
492     熟練した B<sed> プログラマは以下のことに注意すべきです:
493    
494     =over 4
495    
496     =item *
497    
498     =begin original
499    
500     A Perl program executes only once, not once for each input line. You can
501     do an implicit loop with C<-n> or C<-p>.
502    
503     =end original
504    
505     Perl のプログラムは、1 度だけ実行されます; 入力行毎ではありません。
506     C<-n> や C<-p> を使って暗黙のループを使えます。
507    
508     =item *
509    
510     =begin original
511    
512     Backreferences in substitutions use "$" rather than "\".
513    
514     =end original
515    
516     置換における後方参照には、“\”ではなく“$”を使います。
517    
518     =item *
519    
520     =begin original
521    
522     The pattern matching metacharacters "(", ")", and "|" do not have backslashes
523     in front.
524    
525     =end original
526    
527     "(", ")", "|" といったパターンマッチのメタキャラクタは、その直前に
528     バックスラッシュを置く必要はありません。
529    
530     =item *
531    
532     =begin original
533    
534     The range operator is C<...>, rather than comma.
535    
536     =end original
537    
538     範囲演算子は C<...> であって、カンマではありません。
539    
540     =back
541    
542     =head2 Shell Traps
543    
544     (shell の罠)
545    
546     =begin original
547    
548     Sharp shell programmers should take note of the following:
549    
550     =end original
551    
552     鋭いシェルプログラマは以下のことに注意すべきです:
553    
554     =over 4
555    
556     =item *
557    
558     =begin original
559    
560     The backtick operator does variable interpolation without regard to
561     the presence of single quotes in the command.
562    
563     =end original
564    
565     バッククォート演算子は、コマンド内にシングルクォートがあっても
566     変数の展開を行ないます。
567    
568     =item *
569    
570     =begin original
571    
572     The backtick operator does no translation of the return value, unlike B<csh>.
573    
574     =end original
575    
576     バッククォート演算子は B<csh> とは違って、返された値を変換しません。
577    
578     =item *
579    
580     =begin original
581    
582     Shells (especially B<csh>) do several levels of substitution on each
583     command line. Perl does substitution in only certain constructs
584     such as double quotes, backticks, angle brackets, and search patterns.
585    
586     =end original
587    
588     シェル (特に B<csh>) は、コマンドラインごとに何段階もの置換を行ないます。
589     Perl はダブルクォート、バッククォート、山かっこ、検索パターンといった
590     特定の構造でだけ置換を行ないます。
591    
592     =item *
593    
594     =begin original
595    
596     Shells interpret scripts a little bit at a time. Perl compiles the
597     entire program before executing it (except for C<BEGIN> blocks, which
598     execute at compile time).
599    
600     =end original
601    
602     シェルは一度に少しずつ解釈を行ないます。
603     Perl は実行前にプログラム全体をコンパイルします
604     (コンパイル時に実行される C<BEGIN> ブロックを除く)。
605    
606     =item *
607    
608     =begin original
609    
610     The arguments are available via @ARGV, not $1, $2, etc.
611    
612     =end original
613    
614     引数は $1, $2 などではなく、@ARGV から得られます。
615    
616     =item *
617    
618     =begin original
619    
620     The environment is not automatically made available as separate scalar
621     variables.
622    
623     =end original
624    
625     環境変数は、自動的には独立したスカラ変数として利用できるように
626     なりません。
627    
628     =item *
629    
630     =begin original
631    
632     The shell's C<test> uses "=", "!=", "<" etc for string comparisons and "-eq",
633     "-ne", "-lt" etc for numeric comparisons. This is the reverse of Perl, which
634     uses C<eq>, C<ne>, C<lt> for string comparisons, and C<==>, C<!=> C<< < >> etc
635     for numeric comparisons.
636    
637     =end original
638    
639     シェルの C<test> は "=", "!=", "<" などを文字列比較に使い、"-eq", "-ne",
640     "-lt" などを数値比較に使います。
641     これは Perl とは逆です; Perl では C<eq>, C<ne>, C<lt> を文字列比較に使い、
642     C<==>, C<!=> C<< < >> などを数値比較に使います。
643    
644     =back
645    
646     =head2 Perl Traps
647    
648     (Perl の罠)
649    
650     =begin original
651    
652     Practicing Perl Programmers should take note of the following:
653    
654     =end original
655    
656     実践的な Perl プログラマは以下のことに注意すべきです:
657    
658     =over 4
659    
660     =item *
661    
662     =begin original
663    
664     Remember that many operations behave differently in a list
665     context than they do in a scalar one. See L<perldata> for details.
666    
667     =end original
668    
669     多くの演算子がリストコンテキストとスカラコンテキストとで
670     振る舞いが変わることを忘れないでください。
671     詳しくは L<perldata> を参照してください。
672    
673     =item *
674    
675     =begin original
676    
677     Avoid barewords if you can, especially all lowercase ones.
678     You can't tell by just looking at it whether a bareword is
679     a function or a string. By using quotes on strings and
680     parentheses on function calls, you won't ever get them confused.
681    
682     =end original
683    
684     裸の単語、特に全てが小文字のものはできる限り使わないでください。
685     見た目だけではその「裸の単語」が関数なのか、
686     文字列なのかが判断できません。文字列にはクォートを、
687     関数呼び出しには括弧をつければ、迷うこともないでしょう。
688    
689     =item *
690    
691     =begin original
692    
693     You cannot discern from mere inspection which builtins
694     are unary operators (like chop() and chdir())
695     and which are list operators (like print() and unlink()).
696     (Unless prototyped, user-defined subroutines can B<only> be list
697     operators, never unary ones.) See L<perlop> and L<perlsub>.
698    
699     =end original
700    
701     組込み関数のどれが(chop() や chdir())のような単項演算子で、
702     どれが(print() や unlink())のような
703     リスト演算子であるかは見ただけではわかりません。
704     (プロトタイプがなければ、ユーザー定義サブルーチンは
705     リスト演算子として B<のみ> 定義でき、単項演算子にはできません。)
706     L<perlop> と L<perlsub> を参照してください。
707    
708     =item *
709    
710     =begin original
711    
712     People have a hard time remembering that some functions
713     default to $_, or @ARGV, or whatever, but that others which
714     you might expect to do not.
715    
716     =end original
717    
718     いくつかの関数が $_ や @ARGV などをデフォルトにしていますが、
719     同じことを期待する他の関数がデフォルトになっていないことを覚えるのに、
720     辛いタイピングが必要でしょう。
721    
722     =item *
723    
724     =begin original
725    
726     The <FH> construct is not the name of the filehandle, it is a readline
727     operation on that handle. The data read is assigned to $_ only if the
728     file read is the sole condition in a while loop:
729    
730     =end original
731    
732     <FH> 構造はファイルハンドルではなく、そのハンドルに対する行読み込みの
733     操作(readline operation)です。
734     while ループの条件式の中にこのファイル読み込みだけがあった場合には
735     読み込まれたデータは $_ に代入されます。
736    
737     while (<FH>) { }
738     while (defined($_ = <FH>)) { }..
739     <FH>; # data discarded!
740    
741     =item *
742    
743     =begin original
744    
745     Remember not to use C<=> when you need C<=~>;
746     these two constructs are quite different:
747    
748     =end original
749    
750     C<=~> が必要なところで c<=> を使わない、ということを忘れないでください;
751     これら二つの構造はかなり違います:
752    
753     $x = /foo/;
754     $x =~ /foo/;
755    
756     =item *
757    
758     =begin original
759    
760     The C<do {}> construct isn't a real loop that you can use
761     loop control on.
762    
763     =end original
764    
765     C<do {}> 構造は、ループ制御を行えるような本当のループではありません。
766    
767     =item *
768    
769     =begin original
770    
771     Use C<my()> for local variables whenever you can get away with
772     it (but see L<perlform> for where you can't).
773     Using C<local()> actually gives a local value to a global
774     variable, which leaves you open to unforeseen side-effects
775     of dynamic scoping.
776    
777     =end original
778    
779     ローカル変数は、my() で済むところではこれで済ませること
780     (使えない場所については、L<perlform> を参照してください)。
781     local() を使えばグローバル変数に対するローカルな値を与えますが、
782     動的スコープの不慮の副作用の可能性は、そのままです。
783    
784     =item *
785    
786     =begin original
787    
788     If you localize an exported variable in a module, its exported value will
789     not change. The local name becomes an alias to a new value but the
790     external name is still an alias for the original.
791    
792     =end original
793    
794     モジュールにある export された変数を局所化すると、その export された
795     値は変更されません。
796     ローカル名は新しい値の別名(alias)となりますが、
797     外部名は元々の値の別名のままです。
798    
799     =back
800    
801     =begin original
802    
803     As always, if any of these are ever officially declared as bugs,
804     they'll be fixed and removed.
805    
806     =end original
807    
808     いつものように、バグとして公式に宣言されたものがあれば、
809     それは修正されて取り除かれるでしょう。
810    
811     =begin meta
812    
813     Translate: KIMURA Koichi (5.005_03)
814     Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
815     Status: completed
816    
817     =end meta
818    

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26