/
perlop.pod
executable file
·4493 lines (3152 loc) · 138 KB
/
perlop.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=encoding euc-jp
=head1 NAME
=begin original
perlop - Perl operators and precedence
=end original
Perl の演算子と優先順位
=head1 SYNOPSIS
=begin original
Perl operators have the following associativity and precedence,
listed from highest precedence to lowest. Operators borrowed from
C keep the same precedence relationship with each other, even where
C's precedence is slightly screwy. (This makes learning Perl easier
for C folks.) With very few exceptions, these all operate on scalar
values only, not array values.
=end original
Perl の演算子には、以下のような結合性と優先順位 (高い優先順位から
低いものへ並べている) があります。
C から持ってきた演算子の優先順位は、C での優先順位が多少おかしくても、
そのままにしてあります。
(これによって、C を使っている方が Perl に移りやすくなっています。)
ごく僅かな例外を別として、全ての演算子はスカラ値のみを持ち、
配列値を持ちません。
=begin original
left terms and list operators (leftward)
left ->
nonassoc ++ --
right **
right ! ~ \ and unary + and -
left =~ !~
left * / % x
left + - .
left << >>
nonassoc named unary operators
nonassoc < > <= >= lt gt le ge
nonassoc == != <=> eq ne cmp
left &
left | ^
left &&
left ||
nonassoc .. ...
right ?:
right = += -= *= etc.
left , =>
nonassoc list operators (rightward)
right not
left and
left or xor
=end original
左結合 項 リスト演算子 (左方向に対して)
左結合 ->
非結合 ++ --
右結合 **
右結合 ! ~ \ 単項の+ 単項の-
左結合 =~ !~
左結合 * / % x
左結合 + - .
左結合 << >>
非結合 名前付き単項演算子
非結合 < > <= >= lt gt le ge
非結合 == != <=> eq ne cmp
左結合 &
左結合 | ^
左結合 &&
左結合 ||
非結合 .. ...
右結合 ?:
右結合 = += -= *= などの代入演算子
左結合 , =>
非結合 リスト演算子 (右方向に対して)
右結合 not
左結合 and
左結合 or xor
=begin original
In the following sections, these operators are covered in precedence order.
=end original
以下の節では、これらの演算子を優先順位に従って紹介します。
=begin original
Many operators can be overloaded for objects. See L<overload>.
=end original
多くの演算子はオブジェクトでオーバーロードできます。
L<overload> を参照して下さい。
=head1 DESCRIPTION
=head2 Terms and List Operators (Leftward)
(項とリスト演算子 (左方向))
=begin original
A TERM has the highest precedence in Perl. They include variables,
quote and quote-like operators, any expression in parentheses,
and any function whose arguments are parenthesized. Actually, there
aren't really functions in this sense, just list operators and unary
operators behaving as functions because you put parentheses around
the arguments. These are all documented in L<perlfunc>.
=end original
「項」は Perl でもっとも優先順位が高いものです。
これには、変数、クォートとクォート的な演算子、括弧で括った任意の式、
引数を括弧で括った任意の関数が含まれます。
実際には、この意味では本当の関数はなく、リスト演算子と関数のように働く
単項演算子が、引数を括弧で括るためそのように見えます。
これらはすべて L<perlfunc> に記述しています。
=begin original
If any list operator (print(), etc.) or any unary operator (chdir(), etc.)
is followed by a left parenthesis as the next token, the operator and
arguments within parentheses are taken to be of highest precedence,
just like a normal function call.
=end original
もし、リスト演算子 (print() など) や単項演算子 (chdir() など)の
名前の後に開き括弧が続く場合には、その演算子と括弧内の引数は、
通常の関数呼び出しのように、もっとも高い優先順位で処理されます。
=begin original
In the absence of parentheses, the precedence of list operators such as
C<print>, C<sort>, or C<chmod> is either very high or very low depending on
whether you are looking at the left side or the right side of the operator.
For example, in
=end original
括弧が無い場合には、C<print>、C<sort>、C<chmod> のようなリスト演算子の
優先順位は、演算子の左側をからすると非常に高く、右側からすると
非常に低く見えます。たとえば、
@ary = (1, 3, sort 4, 2);
print @ary; # prints 1324
=begin original
the commas on the right of the sort are evaluated before the sort,
but the commas on the left are evaluated after. In other words,
list operators tend to gobble up all arguments that follow, and
then act like a simple TERM with regard to the preceding expression.
Be careful with parentheses:
=end original
では、sort の右のコンマは sort よりも前に評価されます (右側から
見ると sort の優先順位が低い) が、左側のコンマは sort のあとに
評価されます (左側から見ると sort の方が優先順位が高く
なっている)。
言い方を変えると、リスト演算子は自分の後にある引数をすべて使って処理を行ない、
その結果を自分の前の式に対する「項」であるかのように見せるということです。
ただし、括弧には気を付けないといけません:
=begin original
# These evaluate exit before doing the print:
print($foo, exit); # Obviously not what you want.
print $foo, exit; # Nor is this.
# These do the print before evaluating exit:
(print $foo), exit; # This is what you want.
print($foo), exit; # Or this.
print ($foo), exit; # Or even this.
=end original
# 以下は print を行なう前に exit を評価します:
print($foo, exit); # 明らかにやりたいことではないでしょう。
print $foo, exit; # これでもない。
# 以下は exit を評価する前に print を行ないます:
(print $foo), exit; # これがしたかった。
print($foo), exit; # これでもいい。
print ($foo), exit; # これも OK。
=begin original
Also note that
print ($foo & 255) + 1, "\n";
probably doesn't do what you expect at first glance. See
L<Named Unary Operators> for more discussion of this.
=end original
また、
print ($foo & 255) + 1, "\n";
の動作を一目見ただけで判断するのは、難しいでしょう。
詳しくは、L<Named Unary Operators> を参照してください。
=begin original
Also parsed as terms are the C<do {}> and C<eval {}> constructs, as
well as subroutine and method calls, and the anonymous
constructors C<[]> and C<{}>.
=end original
この他に「項」として解析されるものには、C<do {}> や C<eval {}> の
構成、サブルーティンやメソッドの呼び出し、無名のコンストラクタ
C<[]> と C<{}> があります。
=begin original
See also L<Quote and Quote-like Operators> toward the end of this section,
as well as L<"I/O Operators">.
=end original
後の方のL<Quote and Quote-like Operators>や
L<"I/O Operators">も参照してください。
=head2 The Arrow Operator
(矢印演算子)
=begin original
"C<< -> >>" is an infix dereference operator, just as it is in C
and C++. If the right side is either a C<[...]>, C<{...}>, or a
C<(...)> subscript, then the left side must be either a hard or
symbolic reference to an array, a hash, or a subroutine respectively.
(Or technically speaking, a location capable of holding a hard
reference, if it's an array or hash reference being used for
assignment.) See L<perlreftut> and L<perlref>.
=end original
C や C++ と同じように "C<< -> >>" は中置の被参照演算子です。
右側が C<[...]>, C<{...}>,
C<(...)> のいずれかの形の添字であれば、左側は配列、ハッシュ、
サブルーチンへのハードリファレンスかシンボリックリファレンス (あるいは
技術的には、配列またはハードリファレンスが代入可能であれば
ハードリファレンスを保持できる場所)
でなければなりません。L<perlreftut> と L<perlref> を参照してください。
=begin original
Otherwise, the right side is a method name or a simple scalar
variable containing either the method name or a subroutine reference,
and the left side must be either an object (a blessed reference)
or a class name (that is, a package name). See L<perlobj>.
=end original
そうでなければ、右側はメソッド名かサブルーチンのリファレンスを持った
単純スカラ変数で、左側はオブジェクト (bless されたリファレンス) か
クラス名でなければなりません。
L<perlobj> を参照してください。
=head2 Auto-increment and Auto-decrement
(インクリメントとデクリメント)
=begin original
"++" and "--" work as in C. That is, if placed before a variable, they
increment or decrement the variable before returning the value, and if
placed after, increment or decrement the variable after returning the value.
=end original
"++" と "--" は、C の場合と同じように動作します。
つまり、変数の前に置かれれば、値を返す前に変数をインクリメントまたは
デクリメントし、後に置かれれば、値を返した後で変数を
インクリメントまたはデクリメントします。
=begin original
The auto-increment operator has a little extra builtin magic to it. If
you increment a variable that is numeric, or that has ever been used in
a numeric context, you get a normal increment. If, however, the
variable has been used in only string contexts since it was set, and
has a value that is not the empty string and matches the pattern
C</^[a-zA-Z]*[0-9]*\z/>, the increment is done as a string, preserving each
character within its range, with carry:
=end original
インクリメント演算子には、ちょっと風変わりな機能が組み込まれています。
数値が入った変数や、数値の文脈で使われてきた変数を
インクリメントする場合には、通常のインクリメントとして動作します。
しかし、その変数が設定されてからずっと文字列の文脈で
しか使われていなくて、空文字列でなく、 C</^[a-zA-Z]*[0-9]*\z/> にマッチする
値を持っているときには、個々の文字の範囲を保ちながら桁あげを行なって、
文字列としてインクリメントが行なわれます (マジカルインクリメントと呼ばれます):
print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'
=begin original
The auto-decrement operator is not magical.
=end original
デクリメント演算子には、マジカルなものはありません。
=head2 Exponentiation
(指数演算子)
=begin original
Binary "**" is the exponentiation operator. It binds even more
tightly than unary minus, so -2**4 is -(2**4), not (-2)**4. (This is
implemented using C's pow(3) function, which actually works on doubles
internally.)
=end original
二項演算子の "**" は指数演算子です。
この演算子は、単項のマイナスよりも結合が強い演算子で、
-2**4 は (-2)**4 ではなく、-(2**4) と解釈されます。
(これは C の pow(3) を使って実装されていますので、
内部的には double で動作します。)
=head2 Symbolic Unary Operators
(単項演算子)
=begin original
Unary "!" performs logical negation, i.e., "not". See also C<not> for a lower
precedence version of this.
=end original
単項演算子の "!" は論理否定を行ないます。
つまり 「not」 ということです。
この演算子の優先順位を低くしたものとして、C<not> が用意されています。
=begin original
Unary "-" performs arithmetic negation if the operand is numeric. If
the operand is an identifier, a string consisting of a minus sign
concatenated with the identifier is returned. Otherwise, if the string
starts with a plus or minus, a string starting with the opposite sign
is returned. One effect of these rules is that C<-bareword> is equivalent
to C<"-bareword">.
=end original
単項演算子の "-" は被演算子が数値であれば、算術否定を行ないます。
被演算子が識別子ならば、マイナス記号にその識別子をつなげた
文字列が返されます。
これ以外で被演算子の最初の文字がプラスかマイナスのときには、
その記号を逆のものに置き換えた文字列を返します。
この規則の結果、C<-bareword> が C<"-bareword"> に等価となります。
=begin original
Unary "~" performs bitwise negation, i.e., 1's complement. For
example, C<0666 & ~027> is 0640. (See also L<Integer Arithmetic> and
L<Bitwise String Operators>.) Note that the width of the result is
platform-dependent: ~0 is 32 bits wide on a 32-bit platform, but 64
bits wide on a 64-bit platform, so if you are expecting a certain bit
width, remember use the & operator to mask off the excess bits.
=end original
単項演算子の "~" はビットごとの否定を行ないます。
つまり、1 の補数を返します。
例えば、C<0666 & ~027> は 0640 です。
(L<Integer Arithmetic> と L<Bitwise String Operators> も参照して下さい。)
結果の幅はプラットホーム依存であることに注意してください。
~0 は 32-bit プラットホームでは 32 ビット幅ですが、
64-bit プラットホームでは 64 ビット幅ですので、
特定のビット幅を仮定する場合は、
余分なビットをマスクするために & 演算子を使うことを忘れないでください。
=begin original
Unary "+" has no effect whatsoever, even on strings. It is useful
syntactically for separating a function name from a parenthesized expression
that would otherwise be interpreted as the complete list of function
arguments. (See examples above under L<Terms and List Operators (Leftward)>.)
=end original
単項演算子の "+" は、たとえ文字列に対して用いられた場合にも、何もしません。
関数名に続けて括弧付きの式を書く場合に、関数の引数リストと
解釈されないようにするために用いることができます。
(下記 L<Terms and List Operators (Leftward)> の例を参照してください。)
=begin original
Unary "\" creates a reference to whatever follows it. See L<perlreftut>
and L<perlref>. Do not confuse this behavior with the behavior of
backslash within a string, although both forms do convey the notion
of protecting the next thing from interpolation.
=end original
単項演算子の "\" はその後に続くものへのリファレンスを生成します。
L<perlreftut> と L<perlref> を参照してください。
この用法も文字列中のバックスラッシュも、後に続くものが展開されるのを
防ぐことになりますが、動作を混同しないでください。
=head2 Binding Operators
(拘束演算子)
=begin original
Binary "=~" binds a scalar expression to a pattern match. Certain operations
search or modify the string $_ by default. This operator makes that kind
of operation work on some other string. The right argument is a search
pattern, substitution, or transliteration. The left argument is what is
supposed to be searched, substituted, or transliterated instead of the default
$_. When used in scalar context, the return value generally indicates the
success of the operation. Behavior in list context depends on the particular
operator. See L</"Regexp Quote-Like Operators"> for details.
=end original
二項演算子の "=~" は、スカラ式をパターンマッチに拘束します。
デフォルトで $_ の文字列を検索したり、変更したりする演算があります。
この演算子は、そのような演算を他の文字列に対して行なわせるようにするものです。
右引数は、検索パターン、置換、文字変換のいずれかです。
左引数は、デフォルトの $_ の代わりに検索、置換、文字変換の対象となるものです。
スカラコンテキストで使うと、返り値は一般的に演算の結果が成功したか否かです。
リストコンテキストでの振る舞いは演算子に依存します。
詳しくは L</"Regexp Quote-Like Operators"> を参照して下さい。
=begin original
If the right argument is an expression rather than a search pattern,
substitution, or transliteration, it is interpreted as a search pattern at run
time. This can be less efficient than an explicit search, because the
pattern must be compiled every time the expression is evaluated.
=end original
右引数が検索パターン、置換、文字変換ではなく、式であれば、
それは実行時に決まる検索パターンと解釈されます。
明示的な検索に比べて効率が落ちるかもしれません。
式が評価されるたびにパターンをコンパイルする必要があるからです。
=begin original
Binary "!~" is just like "=~" except the return value is negated in
the logical sense.
=end original
二項演算子の "!~" は、返される値が論理否定されることを除いて
"=~" と同じです。
=head2 Multiplicative Operators
(乗法演算子)
=begin original
Binary "*" multiplies two numbers.
=end original
二項演算子の "*" は 2 つの数値の積を返します。
=begin original
Binary "/" divides two numbers.
=end original
二項演算子の "/" は 2 つの数値の商を返します。
=begin original
Binary "%" computes the modulus of two numbers. Given integer
operands C<$a> and C<$b>: If C<$b> is positive, then C<$a % $b> is
C<$a> minus the largest multiple of C<$b> that is not greater than
C<$a>. If C<$b> is negative, then C<$a % $b> is C<$a> minus the
smallest multiple of C<$b> that is not less than C<$a> (i.e. the
result will be less than or equal to zero).
Note than when C<use integer> is in scope, "%" gives you direct access
to the modulus operator as implemented by your C compiler. This
operator is not as well defined for negative operands, but it will
execute faster.
=end original
二項演算子の "%" は 2 つの数値の剰余を返します。
C<$a> と C<$b> の二つの整数の被演算子を取ります。
C<$b> が正の場合、C<$a % $b> は、C<$a> から C<$a> を超えない
最大の C<$b> の倍数を引いた値です。
C<$b> が負の場合、C<$a % $b> は、C<$a> から C<$a> を下回らない
最小の C<$b> の倍数を引いた値です。(従って結果はゼロ以下になります。)
C<use integer> がスコープ内にある場合、
"%" は C コンパイラで実装された剰余演算子を使います。
この演算子は被演算子が負の場合の挙動が不確実ですが、
より高速です。
=begin original
Binary "x" is the repetition operator. In scalar context or if the left
operand is not enclosed in parentheses, it returns a string consisting
of the left operand repeated the number of times specified by the right
operand. In list context, if the left operand is enclosed in
parentheses, it repeats the list.
=end original
二項演算子の "x" は繰り返し演算子です。
スカラコンテキストまたは左辺値が括弧で括られていない場合は、
左被演算子を右被演算子に示す数だけ繰り返したもので構成される
文字列を返します。
リストコンテキストでは、左被演算子が括弧で括られていれば、
リストを繰り返します。
print '-' x 80; # print row of dashes
print "\t" x ($tab/8), ' ' x ($tab%8); # tab over
@ones = (1) x 80; # a list of 80 1's
@ones = (5) x @ones; # set all elements to 5
=head2 Additive Operators
(加法演算子)
=begin original
Binary "+" returns the sum of two numbers.
=end original
二項演算子の "+" は 2 つの数値の和を返します。
=begin original
Binary "-" returns the difference of two numbers.
=end original
二項演算子の "-" は 2 つの数値の差を返します。
=begin original
Binary "." concatenates two strings.
=end original
二項演算子の "." は 2 つの文字列を連結します。
=head2 Shift Operators
(シフト演算子)
=begin original
Binary "<<" returns the value of its left argument shifted left by the
number of bits specified by the right argument. Arguments should be
integers. (See also L<Integer Arithmetic>.)
=end original
二項演算子の "<<" は左引数の値を、右引数で示すビット数だけ、
左にシフトした値を返します。
引数は整数でなければなりません。
(L<Integer Arithmetic> も参照して下さい。)
=begin original
Binary ">>" returns the value of its left argument shifted right by
the number of bits specified by the right argument. Arguments should
be integers. (See also L<Integer Arithmetic>.)
=end original
二項演算子の ">>" は左引数の値を、右引数で示すビット数だけ、
右にシフトした値を返します。
引数は整数でなければなりません。
(L<Integer Arithmetic> も参照して下さい。)
=head2 Named Unary Operators
(名前付き単項演算子)
=begin original
The various named unary operators are treated as functions with one
argument, with optional parentheses. These include the filetest
operators, like C<-f>, C<-M>, etc. See L<perlfunc>.
=end original
さまざまな名前付き単項演算子が、引数を 1 つ持ち、括弧が省略可能な、
関数として扱われます。
これには C<-f> や C<-M> のようなファイルテスト演算子も含まれます。
L<perlfunc> を参照してください。
=begin original
If any list operator (print(), etc.) or any unary operator (chdir(), etc.)
is followed by a left parenthesis as the next token, the operator and
arguments within parentheses are taken to be of highest precedence,
just like a normal function call. For example,
because named unary operators are higher precedence than ||:
=end original
リスト演算子 (print() など) や単項演算子 (chdir() など) は、
すべて次のトークンとして開き括弧が続くと、その演算子と括弧内の引数は、
通常の関数呼び出しのようにもっとも高い優先順位として扱われます。
たとえば、名前つき単項演算子は || より優先順位が高いので、
以下のようになります:
chdir $foo || die; # (chdir $foo) || die
chdir($foo) || die; # (chdir $foo) || die
chdir ($foo) || die; # (chdir $foo) || die
chdir +($foo) || die; # (chdir $foo) || die
=begin original
but, because * is higher precedence than named operators:
=end original
しかし * は名前つき演算子より優先順位が高いので、以下のようになります:
chdir $foo * 20; # chdir ($foo * 20)
chdir($foo) * 20; # (chdir $foo) * 20
chdir ($foo) * 20; # (chdir $foo) * 20
chdir +($foo) * 20; # chdir ($foo * 20)
rand 10 * 20; # rand (10 * 20)
rand(10) * 20; # (rand 10) * 20
rand (10) * 20; # (rand 10) * 20
rand +(10) * 20; # rand (10 * 20)
=begin original
See also L<"Terms and List Operators (Leftward)">.
=end original
L<"Terms and List Operators (Leftward)"> も参照して下さい。
=head2 Relational Operators
(比較演算子)
=begin original
Binary "<" returns true if the left argument is numerically less than
the right argument.
=end original
二項演算子の "<" は左引数が数値的に右引数よりも小さければ、
真を返します。
=begin original
Binary ">" returns true if the left argument is numerically greater
than the right argument.
=end original
二項演算子の ">" は左引数が数値的に右引数よりも大きければ、
真を返します。
=begin original
Binary "<=" returns true if the left argument is numerically less than
or equal to the right argument.
=end original
二項演算子の "<=" は左引数が数値的に右引数よりも小さいか等しければ、
真を返します。
=begin original
Binary ">=" returns true if the left argument is numerically greater
than or equal to the right argument.
=end original
二項演算子の ">=" は左引数が数値的に右引数よりも大きいか等しければ、
真を返します。
=begin original
Binary "lt" returns true if the left argument is stringwise less than
the right argument.
=end original
二項演算子の "lt" は左引数が文字列的に右引数よりも小さければ、
真を返します。
=begin original
Binary "gt" returns true if the left argument is stringwise greater
than the right argument.
=end original
二項演算子の "gt" は左引数が文字列的に右引数よりも大きければ、
真を返します。
=begin original
Binary "le" returns true if the left argument is stringwise less than
or equal to the right argument.
=end original
二項演算子の "le" は左引数が文字列的に右引数よりも小さいか等しければ、
真を返します。
=begin original
Binary "ge" returns true if the left argument is stringwise greater
than or equal to the right argument.
=end original
二項演算子の "ge" は左引数が文字列的に右引数よりも大きいか等しければ、
真を返します。
=head2 Equality Operators
(等価演算子)
=begin original
Binary "==" returns true if the left argument is numerically equal to
the right argument.
=end original
二項演算子の "==" は左引数が数値的に右引数と等しければ、
真を返します。
=begin original
Binary "!=" returns true if the left argument is numerically not equal
to the right argument.
=end original
二項演算子の "!=" は左引数が数値的に右引数と等しくなければ、
真を返します。
=begin original
Binary "<=>" returns -1, 0, or 1 depending on whether the left
argument is numerically less than, equal to, or greater than the right
argument. If your platform supports NaNs (not-a-numbers) as numeric
values, using them with "<=>" returns undef. NaN is not "<", "==", ">",
"<=" or ">=" anything (even NaN), so those 5 return false. NaN != NaN
returns true, as does NaN != anything else. If your platform doesn't
support NaNs then NaN is just a string with numeric value 0.
=end original
二項演算子の "<=>" は左引数が数値的に右引数より小さいか、等しいか、
大きいかに従って、-1, 0, 1 を返します。
数値として NaN (非数) に対応しているプラットフォームでは、
NaN に対して "<=>" を使うと undef を返します。
NaN はどの値に対しても(NaN に対してでさえも) "<", "==", ">",
"<=", ">=" のいずれも成立しないので、これらは全て偽となります。
NaN != NaN は真を返しますが、その他のどの値に対しても != は偽を返します。
NaN に対応していないプラットフォームでは、NaN は
単に数としての値 0 を持つ文字列です。
perl -le '$a = NaN; print "No NaN support here" if $a == $a'
perl -le '$a = NaN; print "NaN support here" if $a != $a'
=begin original
Binary "eq" returns true if the left argument is stringwise equal to
the right argument.
=end original
二項演算子の "eq" は左引数が文字列的に右引数と等しければ、
真を返します。
=begin original
Binary "ne" returns true if the left argument is stringwise not equal
to the right argument.
=end original
二項演算子の "ne" は左引数が文字列的に右引数と等しくなければ、
真を返します。
=begin original
Binary "cmp" returns -1, 0, or 1 depending on whether the left
argument is stringwise less than, equal to, or greater than the right
argument.
=end original
二項演算子の "cmp" は左引数が文字列的に右引数より小さいか、
等しいか、大きいかに従って、-1, 0, 1 を返します。
=begin original
"lt", "le", "ge", "gt" and "cmp" use the collation (sort) order specified
by the current locale if C<use locale> is in effect. See L<perllocale>.
=end original
"lt", "le", "ge", "gt", "cmp" は C<use locale> が有効な場合は
現在のロケールで指定された辞書(ソート)順が使われます。
L<perllocale> を参照して下さい。
=head2 Bitwise And
(ビットごとの AND)
=begin original
Binary "&" returns its operators ANDed together bit by bit.
(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
=end original
二項演算子の "&" は、両被演算子のビットごとに論理積をとって、
その結果を返します。
(L<Integer Arithmetic> と L<Bitwise String Operators> も参照して下さい。)
=head2 Bitwise Or and Exclusive Or
(ビットごとの OR と XOR)
=begin original
Binary "|" returns its operators ORed together bit by bit.
(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
=end original
二項演算子の "|" は、両被演算子のビットごとに論理和をとって、
その結果を返します。
(L<Integer Arithmetic> と L<Bitwise String Operators> も参照して下さい。)
=begin original
Binary "^" returns its operators XORed together bit by bit.
(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
=end original
二項演算子の "^" は、両被演算子のビットごとに排他論理和をとって、
その結果を返します。
(L<Integer Arithmetic> と L<Bitwise String Operators> も参照して下さい。)
=head2 C-style Logical And
(C スタイルの論理積)
=begin original
Binary "&&" performs a short-circuit logical AND operation. That is,
if the left operand is false, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.
=end original
二項演算子の "&&" は、短絡の論理積演算を行ないます。
つまり、左被演算子が偽であれば、右被演算子は評価さえ
行なわれないということです。
評価される場合には、スカラーかリストかというコンテキストは、
右被演算子にも及びます。
=head2 C-style Logical Or
(C スタイルの論理和)
=begin original
Binary "||" performs a short-circuit logical OR operation. That is,
if the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.
=end original
二項演算子の "||" は、短絡の論理和演算を行ないます。
つまり、左被演算子が真であれば、右被演算子は評価さえ
行なわれないということです。
評価される場合には、スカラーかリストかというコンテキストは、
右被演算子にも及びます。
=begin original
The C<||> and C<&&> operators differ from C's in that, rather than returning
0 or 1, they return the last value evaluated. Thus, a reasonably portable
way to find out the home directory (assuming it's not "0") might be:
=end original
|| 演算子と && 演算子は、単に 0 や 1 を返すのではなく、最後に評価された値を
返すという点において、C と違っています。
これにより、かなり一般的に使えるホームディレクトリ ("0" でないとして) を
探す方法は:
$home = $ENV{'HOME'} || $ENV{'LOGDIR'} ||
(getpwuid($<))[7] || die "You're homeless!\n";
=begin original
In particular, this means that you shouldn't use this
for selecting between two aggregates for assignment:
=end original
特に、これは代入のために二つの集合を選択するためには
使うべきではないことを意味します。
@a = @b || @c; # this is wrong
@a = scalar(@b) || @c; # really meant this
@a = @b ? @b : @c; # this works fine, though
=begin original
As more readable alternatives to C<&&> and C<||> when used for
control flow, Perl provides C<and> and C<or> operators (see below).
The short-circuit behavior is identical. The precedence of "and" and
"or" is much lower, however, so that you can safely use them after a
list operator without the need for parentheses:
=end original
Perl では、フロー制御に使う場合の多少読みやすい C<&&> と C<||> の同義語として、
C<and> 演算子と C<or> 演算子が用意されています (下記参照)。
短絡の動作は全く同じです。
しかし、"and" と "or" の優先順位はかなり低くしてあるので、
引数に括弧を使っていないリスト演算子のあとに続けて使う場合にも、
安心して使うことができます:
unlink "alpha", "beta", "gamma"
or gripe(), next LINE;
=begin original
With the C-style operators that would have been written like this:
=end original
C スタイルの演算子では以下のように書く必要があります。
unlink("alpha", "beta", "gamma")
|| (gripe(), next LINE);
=begin original
Using "or" for assignment is unlikely to do what you want; see below.
=end original
代入で "or" を使うと、したいことと違うことになります。
以下を参照して下さい。
=head2 Range Operators
(範囲演算子)
=begin original