<?xml version='1.0' encoding='utf-8'?>
<pod xmlns="http://axkit.org/ns/2000/pod2xml">
<head>
	<title>perlop - Perl operators and precedence</title>
</head>
<sect1>
<title>perlop - Perl operators and precedence</title>
<para>
Perl の演算子と優先順位
</para>
</sect1>
<sect1>
<title>SYNOPSIS</title>
<para>
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.
</para>
<para>
Perl の演算子には、以下のような結合性と優先順位 (高い優先順位から
低いものへ並べている) があります。
C から持ってきた演算子の優先順位は、C での優先順位が多少おかしくても、
そのままにしてあります。
(これによって、C を使っている方が Perl に移りやすくなっています。)
ごく僅かな例外を別として、全ての演算子はスカラ値のみを持ち、
配列値を持ちません。
</para>
<verbatim><![CDATA[
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
]]></verbatim>
<verbatim><![CDATA[
左結合      項  リスト演算子 (左方向に対して)
左結合      ->
非結合      ++ --
右結合      **
右結合      ! ~ \ 単項の+ 単項の-
左結合      =~ !~
左結合      * / % x
左結合      + - .
左結合      << >>
非結合      名前付き単項演算子
非結合      < > <= >= lt gt le ge
非結合      == != <=> eq ne cmp
左結合      &
左結合      | ^
左結合      &&
左結合      ||
非結合      .. ...
右結合      ?:
右結合      = += -= *= などの代入演算子
左結合      , =>
非結合      リスト演算子 (右方向に対して)
右結合      not
左結合      and
左結合      or xor
]]></verbatim>
<para>
In the following sections, these operators are covered in precedence order.
</para>
<para>
以下の節では、これらの演算子を優先順位に従って紹介します。
</para>
<para>
Many operators can be overloaded for objects.  See <link xref='overload'>overload</link>.
</para>
<para>
多くの演算子はオブジェクトでオーバーロードできます。
<link xref='overload'>overload</link> を参照して下さい。
</para>
</sect1>
<sect1>
<title>DESCRIPTION</title>
<sect2>
<title>Terms and List Operators (Leftward)</title>
<para>
(項とリスト演算子 (左方向))
</para>
<para>
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 <link xref='perlfunc'>perlfunc</link>.
</para>
<para>
「項」は Perl でもっとも優先順位が高いものです。
これには、変数、クォートとクォート的な演算子、括弧で括った任意の式、
引数を括弧で括った任意の関数が含まれます。
実際には、この意味では本当の関数はなく、リスト演算子と関数のように働く
単項演算子が、引数を括弧で括るためそのように見えます。
これらはすべて <link xref='perlfunc'>perlfunc</link> に記述しています。
</para>
<para>
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.
</para>
<para>
もし、リスト演算子 (print() など) や単項演算子 (chdir() など)の
名前の後に開き括弧が続く場合には、その演算子と括弧内の引数は、
通常の関数呼び出しのように、もっとも高い優先順位で処理されます。
</para>
<para>
In the absence of parentheses, the precedence of list operators such as
<code>print</code>, <code>sort</code>, or <code>chmod</code> 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
</para>
<para>
括弧が無い場合には、<code>print</code>、<code>sort</code>、<code>chmod</code> のようなリスト演算子の
優先順位は、演算子の左側をからすると非常に高く、右側からすると
非常に低く見えます。たとえば、
</para>
<verbatim><![CDATA[
@ary = (1, 3, sort 4, 2);
print @ary;		# prints 1324
]]></verbatim>
<para>
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:
</para>
<para>
では、sort の右のコンマは sort よりも前に評価されます (右側から
見ると sort の優先順位が低い) が、左側のコンマは sort のあとに
評価されます (左側から見ると sort の方が優先順位が高く
なっている)。
言い方を変えると、リスト演算子は自分の後にある引数をすべて使って処理を行ない、
その結果を自分の前の式に対する「項」であるかのように見せるということです。
ただし、括弧には気を付けないといけません:
</para>
<verbatim><![CDATA[
# These evaluate exit before doing the print:
print($foo, exit);	# Obviously not what you want.
print $foo, exit;	# Nor is this.
]]></verbatim>
<verbatim><![CDATA[
# 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.
]]></verbatim>
<verbatim><![CDATA[
# 以下は print を行なう前に exit を評価します:
print($foo, exit);  # 明らかにやりたいことではないでしょう。
print $foo, exit;   # これでもない。
]]></verbatim>
<verbatim><![CDATA[
# 以下は exit を評価する前に print を行ないます:
(print $foo), exit; # これがしたかった。
print($foo), exit;  # これでもいい。
print ($foo), exit; # これも OK。
]]></verbatim>
<para>
Also note that
</para>
<verbatim><![CDATA[
print ($foo & 255) + 1, "\n";
]]></verbatim>
<para>
probably doesn't do what you expect at first glance.  See
<link xref='Named Unary Operators'>Named Unary Operators</link> for more discussion of this.
</para>
<para>
また、
</para>
<verbatim><![CDATA[
print ($foo & 255) + 1, "\n";
]]></verbatim>
<para>
の動作を一目見ただけで判断するのは、難しいでしょう。
詳しくは、<link xref='Named Unary Operators'>Named Unary Operators</link> を参照してください。
</para>
<para>
Also parsed as terms are the <code>do {}</code> and <code>eval {}</code> constructs, as
well as subroutine and method calls, and the anonymous
constructors <code>[]</code> and <code>{}</code>.
</para>
<para>
この他に「項」として解析されるものには、<code>do {}</code> や <code>eval {}</code> の
構成、サブルーティンやメソッドの呼び出し、無名のコンストラクタ
<code>[]</code> と <code>{}</code> があります。
</para>
<para>
See also <link xref='Quote and Quote-like Operators'>Quote and Quote-like Operators</link> toward the end of this section,
as well as <link xref='&quot;I#O Operators&quot;'>&quot;I/O Operators&quot;</link>.
</para>
<para>
後の方の<link xref='Quote and Quote-like Operators'>Quote and Quote-like Operators</link>や
<link xref='&quot;I#O Operators&quot;'>&quot;I/O Operators&quot;</link>も参照してください。
</para>
</sect2>
<sect2>
<title>The Arrow Operator</title>
<para>
(矢印演算子)
</para>
<para>
&quot;<code>-&gt;</code>&quot; is an infix dereference operator, just as it is in C
and C++.  If the right side is either a <code>[...]</code>, <code>{...}</code>, or a
<code>(...)</code> 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 <link xref='perlreftut'>perlreftut</link> and <link xref='perlref'>perlref</link>.
</para>
<para>
C や C++ と同じように &quot;<code>-&gt;</code>&quot; は中置の被参照演算子です。
右側が <code>[...]</code>, <code>{...}</code>,
<code>(...)</code> のいずれかの形の添字であれば、左側は配列、ハッシュ、
サブルーチンへのハードリファレンスかシンボリックリファレンス (あるいは
技術的には、配列またはハードリファレンスが代入可能であれば
ハードリファレンスを保持できる場所)
でなければなりません。<link xref='perlreftut'>perlreftut</link> と <link xref='perlref'>perlref</link> を参照してください。
</para>
<para>
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 <link xref='perlobj'>perlobj</link>.
</para>
<para>
そうでなければ、右側はメソッド名かサブルーチンのリファレンスを持った
単純スカラ変数で、左側はオブジェクト (bless されたリファレンス) か
クラス名でなければなりません。
<link xref='perlobj'>perlobj</link> を参照してください。
</para>
</sect2>
<sect2>
<title>Auto-increment and Auto-decrement</title>
<para>
(インクリメントとデクリメント)
</para>
<para>
&quot;++&quot; and &quot;--&quot; 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.
</para>
<para>
&quot;++&quot; と &quot;--&quot; は、C の場合と同じように動作します。
つまり、変数の前に置かれれば、値を返す前に変数をインクリメントまたは
デクリメントし、後に置かれれば、値を返した後で変数を
インクリメントまたはデクリメントします。
</para>
<para>
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
<code>/^[a-zA-Z]*[0-9]*\z/</code>, the increment is done as a string, preserving each
character within its range, with carry:
</para>
<para>
インクリメント演算子には、ちょっと風変わりな機能が組み込まれています。
数値が入った変数や、数値の文脈で使われてきた変数を
インクリメントする場合には、通常のインクリメントとして動作します。
しかし、その変数が設定されてからずっと文字列の文脈で
しか使われていなくて、空文字列でなく、 <code>/^[a-zA-Z]*[0-9]*\z/</code> にマッチする
値を持っているときには、個々の文字の範囲を保ちながら桁あげを行なって、
文字列としてインクリメントが行なわれます (マジカルインクリメントと呼ばれます):
</para>
<verbatim><![CDATA[
print ++($foo = '99');	# prints '100'
print ++($foo = 'a0');	# prints 'a1'
print ++($foo = 'Az');	# prints 'Ba'
print ++($foo = 'zz');	# prints 'aaa'
]]></verbatim>
<para>
The auto-decrement operator is not magical.
</para>
<para>
デクリメント演算子には、マジカルなものはありません。
</para>
</sect2>
<sect2>
<title>Exponentiation</title>
<para>
(指数演算子)
</para>
<para>
Binary &quot;**&quot; 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.)
</para>
<para>
二項演算子の &quot;**&quot; は指数演算子です。
この演算子は、単項のマイナスよりも結合が強い演算子で、
-2**4 は (-2)**4 ではなく、-(2**4) と解釈されます。
(これは C の pow(3) を使って実装されていますので、
内部的には double で動作します。)
</para>
</sect2>
<sect2>
<title>Symbolic Unary Operators</title>
<para>
(単項演算子)
</para>
<para>
Unary &quot;!&quot; performs logical negation, i.e., &quot;not&quot;.  See also <code>not</code> for a lower
precedence version of this.
</para>
<para>
単項演算子の &quot;!&quot; は論理否定を行ないます。
つまり 「not」 ということです。
この演算子の優先順位を低くしたものとして、<code>not</code> が用意されています。
</para>
<para>
Unary &quot;-&quot; 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 <code>-bareword</code> is equivalent
to <code>&quot;-bareword&quot;</code>.
</para>
<para>
単項演算子の &quot;-&quot; は被演算子が数値であれば、算術否定を行ないます。
被演算子が識別子ならば、マイナス記号にその識別子をつなげた
文字列が返されます。
これ以外で被演算子の最初の文字がプラスかマイナスのときには、
その記号を逆のものに置き換えた文字列を返します。
この規則の結果、<code>-bareword</code> が <code>&quot;-bareword&quot;</code> に等価となります。
</para>
<para>
Unary &quot;~&quot; performs bitwise negation, i.e., 1's complement.  For
example, <code>0666 &amp; ~027</code> is 0640.  (See also <link xref='Integer Arithmetic'>Integer Arithmetic</link> and
<link xref='Bitwise String Operators'>Bitwise String Operators</link>.)  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 &amp; operator to mask off the excess bits.
</para>
<para>
単項演算子の &quot;~&quot; はビットごとの否定を行ないます。
つまり、1 の補数を返します。
例えば、<code>0666 &amp; ~027</code> は 0640 です。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> と <link xref='Bitwise String Operators'>Bitwise String Operators</link> も参照して下さい。)
結果の幅はプラットホーム依存であることに注意してください。
~0 は 32-bit プラットホームでは 32 ビット幅ですが、
64-bit プラットホームでは 64 ビット幅ですので、
特定のビット幅を仮定する場合は、
余分なビットをマスクするために &amp; 演算子を使うことを忘れないでください。
</para>
<para>
Unary &quot;+&quot; 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 <link xref='Terms and List Operators (Leftward)'>Terms and List Operators (Leftward)</link>.)
</para>
<para>
単項演算子の &quot;+&quot; は、たとえ文字列に対して用いられた場合にも、何もしません。
関数名に続けて括弧付きの式を書く場合に、関数の引数リストと
解釈されないようにするために用いることができます。
(下記 <link xref='Terms and List Operators (Leftward)'>Terms and List Operators (Leftward)</link> の例を参照してください。)
</para>
<para>
Unary &quot;\&quot; creates a reference to whatever follows it.  See <link xref='perlreftut'>perlreftut</link>
and <link xref='perlref'>perlref</link>.  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.
</para>
<para>
単項演算子の &quot;\&quot; はその後に続くものへのリファレンスを生成します。
<link xref='perlreftut'>perlreftut</link> と <link xref='perlref'>perlref</link> を参照してください。
この用法も文字列中のバックスラッシュも、後に続くものが展開されるのを
防ぐことになりますが、動作を混同しないでください。
</para>
</sect2>
<sect2>
<title>Binding Operators</title>
<para>
(拘束演算子)
</para>
<para>
Binary &quot;=~&quot; 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 <link xref='#Regexp_Quote-Like_Operators'>/&quot;Regexp Quote-Like Operators&quot;</link> for details.
</para>
<para>
二項演算子の &quot;=~&quot; は、スカラ式をパターンマッチに拘束します。
デフォルトで $_ の文字列を検索したり、変更したりする演算があります。
この演算子は、そのような演算を他の文字列に対して行なわせるようにするものです。
右引数は、検索パターン、置換、文字変換のいずれかです。
左引数は、デフォルトの $_ の代わりに検索、置換、文字変換の対象となるものです。
スカラコンテキストで使うと、返り値は一般的に演算の結果が成功したか否かです。
リストコンテキストでの振る舞いは演算子に依存します。
詳しくは <link xref='#Regexp_Quote-Like_Operators'>/&quot;Regexp Quote-Like Operators&quot;</link> を参照して下さい。
</para>
<para>
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.
</para>
<para>
右引数が検索パターン、置換、文字変換ではなく、式であれば、
それは実行時に決まる検索パターンと解釈されます。
明示的な検索に比べて効率が落ちるかもしれません。
式が評価されるたびにパターンをコンパイルする必要があるからです。
</para>
<para>
Binary &quot;!~&quot; is just like &quot;=~&quot; except the return value is negated in
the logical sense.
</para>
<para>
二項演算子の &quot;!~&quot; は、返される値が論理否定されることを除いて
&quot;=~&quot; と同じです。
</para>
</sect2>
<sect2>
<title>Multiplicative Operators</title>
<para>
(乗法演算子)
</para>
<para>
Binary &quot;*&quot; multiplies two numbers.
</para>
<para>
二項演算子の &quot;*&quot; は 2 つの数値の積を返します。
</para>
<para>
Binary &quot;/&quot; divides two numbers.
</para>
<para>
二項演算子の &quot;/&quot; は 2 つの数値の商を返します。
</para>
<para>
Binary &quot;%&quot; computes the modulus of two numbers.  Given integer
operands <code>$a</code> and <code>$b</code>: If <code>$b</code> is positive, then <code>$a % $b</code> is
<code>$a</code> minus the largest multiple of <code>$b</code> that is not greater than
<code>$a</code>.  If <code>$b</code> is negative, then <code>$a % $b</code> is <code>$a</code> minus the
smallest multiple of <code>$b</code> that is not less than <code>$a</code> (i.e. the
result will be less than or equal to zero). 
Note than when <code>use integer</code> is in scope, &quot;%&quot; 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.
</para>
<para>
二項演算子の &quot;%&quot; は 2 つの数値の剰余を返します。
<code>$a</code> と <code>$b</code> の二つの整数の被演算子を取ります。
<code>$b</code> が正の場合、<code>$a % $b</code> は、<code>$a</code> から <code>$a</code> を超えない
最大の <code>$b</code> の倍数を引いた値です。
<code>$b</code> が負の場合、<code>$a % $b</code> は、<code>$a</code> から <code>$a</code> を下回らない
最小の <code>$b</code> の倍数を引いた値です。(従って結果はゼロ以下になります。)
<code>use integer</code> がスコープ内にある場合、
&quot;%&quot; は C コンパイラで実装された剰余演算子を使います。
この演算子は被演算子が負の場合の挙動が不確実ですが、
より高速です。
</para>
<para>
Binary &quot;x&quot; 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.
</para>
<para>
二項演算子の &quot;x&quot; は繰り返し演算子です。
スカラコンテキストまたは左辺値が括弧で括られていない場合は、
左被演算子を右被演算子に示す数だけ繰り返したもので構成される
文字列を返します。
リストコンテキストでは、左被演算子が括弧で括られていれば、
リストを繰り返します。
</para>
<verbatim><![CDATA[
print '-' x 80;		# print row of dashes
]]></verbatim>
<verbatim><![CDATA[
print "\t" x ($tab/8), ' ' x ($tab%8);	# tab over
]]></verbatim>
<verbatim><![CDATA[
@ones = (1) x 80;		# a list of 80 1's
@ones = (5) x @ones;	# set all elements to 5
]]></verbatim>
</sect2>
<sect2>
<title>Additive Operators</title>
<para>
(加法演算子)
</para>
<para>
Binary &quot;+&quot; returns the sum of two numbers.
</para>
<para>
二項演算子の &quot;+&quot; は 2 つの数値の和を返します。
</para>
<para>
Binary &quot;-&quot; returns the difference of two numbers.
</para>
<para>
二項演算子の &quot;-&quot; は 2 つの数値の差を返します。
</para>
<para>
Binary &quot;.&quot; concatenates two strings.
</para>
<para>
二項演算子の &quot;.&quot; は 2 つの文字列を連結します。
</para>
</sect2>
<sect2>
<title>Shift Operators</title>
<para>
(シフト演算子)
</para>
<para>
Binary &quot;&lt;&lt;&quot; 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 <link xref='Integer Arithmetic'>Integer Arithmetic</link>.)
</para>
<para>
二項演算子の &quot;&lt;&lt;&quot; は左引数の値を、右引数で示すビット数だけ、
左にシフトした値を返します。
引数は整数でなければなりません。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> も参照して下さい。)
</para>
<para>
Binary &quot;&gt;&gt;&quot; 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 <link xref='Integer Arithmetic'>Integer Arithmetic</link>.)
</para>
<para>
二項演算子の &quot;&gt;&gt;&quot; は左引数の値を、右引数で示すビット数だけ、
右にシフトした値を返します。
引数は整数でなければなりません。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> も参照して下さい。)
</para>
</sect2>
<sect2>
<title>Named Unary Operators</title>
<para>
(名前付き単項演算子)
</para>
<para>
The various named unary operators are treated as functions with one
argument, with optional parentheses.  These include the filetest
operators, like <code>-f</code>, <code>-M</code>, etc.  See <link xref='perlfunc'>perlfunc</link>.
</para>
<para>
さまざまな名前付き単項演算子が、引数を 1 つ持ち、括弧が省略可能な、
関数として扱われます。
これには <code>-f</code> や <code>-M</code> のようなファイルテスト演算子も含まれます。
<link xref='perlfunc'>perlfunc</link> を参照してください。
</para>
<para>
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 ||:
</para>
<para>
リスト演算子 (print() など) や単項演算子 (chdir() など) は、
すべて次のトークンとして開き括弧が続くと、その演算子と括弧内の引数は、
通常の関数呼び出しのようにもっとも高い優先順位として扱われます。
たとえば、名前つき単項演算子は || より優先順位が高いので、
以下のようになります:
</para>
<verbatim><![CDATA[
chdir $foo    || die;	# (chdir $foo) || die
chdir($foo)   || die;	# (chdir $foo) || die
chdir ($foo)  || die;	# (chdir $foo) || die
chdir +($foo) || die;	# (chdir $foo) || die
]]></verbatim>
<para>
but, because * is higher precedence than named operators:
</para>
<para>
しかし * は名前つき演算子より優先順位が高いので、以下のようになります:
</para>
<verbatim><![CDATA[
chdir $foo * 20;	# chdir ($foo * 20)
chdir($foo) * 20;	# (chdir $foo) * 20
chdir ($foo) * 20;	# (chdir $foo) * 20
chdir +($foo) * 20;	# chdir ($foo * 20)
]]></verbatim>
<verbatim><![CDATA[
rand 10 * 20;	# rand (10 * 20)
rand(10) * 20;	# (rand 10) * 20
rand (10) * 20;	# (rand 10) * 20
rand +(10) * 20;	# rand (10 * 20)
]]></verbatim>
<para>
See also <link xref='#Terms_and_List_Operators_(Left'>&quot;Terms and List Operators (Leftward)&quot;</link>.
</para>
<para>
<link xref='#Terms_and_List_Operators_(Left'>&quot;Terms and List Operators (Leftward)&quot;</link> も参照して下さい。
</para>
</sect2>
<sect2>
<title>Relational Operators</title>
<para>
(比較演算子)
</para>
<para>
Binary &quot;&lt;&quot; returns true if the left argument is numerically less than
the right argument.
</para>
<para>
二項演算子の &quot;&lt;&quot; は左引数が数値的に右引数よりも小さければ、
真を返します。
</para>
<para>
Binary &quot;&gt;&quot; returns true if the left argument is numerically greater
than the right argument.
</para>
<para>
二項演算子の &quot;&gt;&quot; は左引数が数値的に右引数よりも大きければ、
真を返します。
</para>
<para>
Binary &quot;&lt;=&quot; returns true if the left argument is numerically less than
or equal to the right argument.
</para>
<para>
二項演算子の &quot;&lt;=&quot; は左引数が数値的に右引数よりも小さいか等しければ、
真を返します。
</para>
<para>
Binary &quot;&gt;=&quot; returns true if the left argument is numerically greater
than or equal to the right argument.
</para>
<para>
二項演算子の &quot;&gt;=&quot; は左引数が数値的に右引数よりも大きいか等しければ、
真を返します。
</para>
<para>
Binary &quot;lt&quot; returns true if the left argument is stringwise less than
the right argument.
</para>
<para>
二項演算子の &quot;lt&quot; は左引数が文字列的に右引数よりも小さければ、
真を返します。
</para>
<para>
Binary &quot;gt&quot; returns true if the left argument is stringwise greater
than the right argument.
</para>
<para>
二項演算子の &quot;gt&quot; は左引数が文字列的に右引数よりも大きければ、
真を返します。
</para>
<para>
Binary &quot;le&quot; returns true if the left argument is stringwise less than
or equal to the right argument.
</para>
<para>
二項演算子の &quot;le&quot; は左引数が文字列的に右引数よりも小さいか等しければ、
真を返します。
</para>
<para>
Binary &quot;ge&quot; returns true if the left argument is stringwise greater
than or equal to the right argument.
</para>
<para>
二項演算子の &quot;ge&quot; は左引数が文字列的に右引数よりも大きいか等しければ、
真を返します。
</para>
</sect2>
<sect2>
<title>Equality Operators</title>
<para>
(等価演算子)
</para>
<para>
Binary &quot;==&quot; returns true if the left argument is numerically equal to
the right argument.
</para>
<para>
二項演算子の &quot;==&quot; は左引数が数値的に右引数と等しければ、
真を返します。
</para>
<para>
Binary &quot;!=&quot; returns true if the left argument is numerically not equal
to the right argument.
</para>
<para>
二項演算子の &quot;!=&quot; は左引数が数値的に右引数と等しくなければ、
真を返します。
</para>
<para>
Binary &quot;&lt;=&gt;&quot; 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 &quot;&lt;=&gt;&quot; returns undef.  NaN is not &quot;&lt;&quot;, &quot;==&quot;, &quot;&gt;&quot;,
&quot;&lt;=&quot; or &quot;&gt;=&quot; 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.
</para>
<para>
二項演算子の &quot;&lt;=&gt;&quot; は左引数が数値的に右引数より小さいか、等しいか、
大きいかに従って、-1, 0, 1 を返します。
数値として NaN (非数) に対応しているプラットフォームでは、
NaN に対して &quot;&lt;=&gt;&quot; を使うと undef を返します。
NaN はどの値に対しても(NaN に対してでさえも) &quot;&lt;&quot;, &quot;==&quot;, &quot;&gt;&quot;,
&quot;&lt;=&quot;, &quot;&gt;=&quot; のいずれも成立しないので、これらは全て偽となります。
NaN != NaN は真を返しますが、その他のどの値に対しても != は偽を返します。
NaN に対応していないプラットフォームでは、NaN は
単に数としての値 0 を持つ文字列です。
</para>
<verbatim><![CDATA[
perl -le '$a = NaN; print "No NaN support here" if $a == $a'
perl -le '$a = NaN; print "NaN support here" if $a != $a'
]]></verbatim>
<para>
Binary &quot;eq&quot; returns true if the left argument is stringwise equal to
the right argument.
</para>
<para>
二項演算子の &quot;eq&quot; は左引数が文字列的に右引数と等しければ、
真を返します。
</para>
<para>
Binary &quot;ne&quot; returns true if the left argument is stringwise not equal
to the right argument.
</para>
<para>
二項演算子の &quot;ne&quot; は左引数が文字列的に右引数と等しくなければ、
真を返します。
</para>
<para>
Binary &quot;cmp&quot; returns -1, 0, or 1 depending on whether the left
argument is stringwise less than, equal to, or greater than the right
argument.
</para>
<para>
二項演算子の &quot;cmp&quot; は左引数が文字列的に右引数より小さいか、
等しいか、大きいかに従って、-1, 0, 1 を返します。
</para>
<para>
&quot;lt&quot;, &quot;le&quot;, &quot;ge&quot;, &quot;gt&quot; and &quot;cmp&quot; use the collation (sort) order specified
by the current locale if <code>use locale</code> is in effect.  See <link xref='perllocale'>perllocale</link>.
</para>
<para>
&quot;lt&quot;, &quot;le&quot;, &quot;ge&quot;, &quot;gt&quot;, &quot;cmp&quot; は <code>use locale</code> が有効な場合は
現在のロケールで指定された辞書(ソート)順が使われます。
<link xref='perllocale'>perllocale</link> を参照して下さい。
</para>
</sect2>
<sect2>
<title>Bitwise And</title>
<para>
(ビットごとの AND)
</para>
<para>
Binary &quot;&amp;&quot; returns its operators ANDed together bit by bit.
(See also <link xref='Integer Arithmetic'>Integer Arithmetic</link> and <link xref='Bitwise String Operators'>Bitwise String Operators</link>.)
</para>
<para>
二項演算子の &quot;&amp;&quot; は、両被演算子のビットごとに論理積をとって、
その結果を返します。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> と <link xref='Bitwise String Operators'>Bitwise String Operators</link> も参照して下さい。)
</para>
</sect2>
<sect2>
<title>Bitwise Or and Exclusive Or</title>
<para>
(ビットごとの OR と XOR)
</para>
<para>
Binary &quot;|&quot; returns its operators ORed together bit by bit.
(See also <link xref='Integer Arithmetic'>Integer Arithmetic</link> and <link xref='Bitwise String Operators'>Bitwise String Operators</link>.)
</para>
<para>
二項演算子の &quot;|&quot; は、両被演算子のビットごとに論理和をとって、
その結果を返します。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> と <link xref='Bitwise String Operators'>Bitwise String Operators</link> も参照して下さい。)
</para>
<para>
Binary &quot;^&quot; returns its operators XORed together bit by bit.
(See also <link xref='Integer Arithmetic'>Integer Arithmetic</link> and <link xref='Bitwise String Operators'>Bitwise String Operators</link>.)
</para>
<para>
二項演算子の &quot;^&quot; は、両被演算子のビットごとに排他論理和をとって、
その結果を返します。
(<link xref='Integer Arithmetic'>Integer Arithmetic</link> と <link xref='Bitwise String Operators'>Bitwise String Operators</link> も参照して下さい。)
</para>
</sect2>
<sect2>
<title>C-style Logical And</title>
<para>
(C スタイルの論理積)
</para>
<para>
Binary &quot;&amp;&amp;&quot; 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.
</para>
<para>
二項演算子の &quot;&amp;&amp;&quot; は、短絡の論理積演算を行ないます。
つまり、左被演算子が偽であれば、右被演算子は評価さえ
行なわれないということです。
評価される場合には、スカラーかリストかというコンテキストは、
右被演算子にも及びます。
</para>
</sect2>
<sect2>
<title>C-style Logical Or</title>
<para>
(C スタイルの論理和)
</para>
<para>
Binary &quot;||&quot; 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.
</para>
<para>
二項演算子の &quot;||&quot; は、短絡の論理和演算を行ないます。
つまり、左被演算子が真であれば、右被演算子は評価さえ
行なわれないということです。
評価される場合には、スカラーかリストかというコンテキストは、
右被演算子にも及びます。
</para>
<para>
The <code>||</code> and <code>&amp;&amp;</code> 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 &quot;0&quot;) might be:
</para>
<para>
|| 演算子と &amp;&amp; 演算子は、単に 0 や 1 を返すのではなく、最後に評価された値を
返すという点において、C と違っています。
これにより、かなり一般的に使えるホームディレクトリ (&quot;0&quot; でないとして) を
探す方法は:
</para>
<verbatim><![CDATA[
$home = $ENV{'HOME'} || $ENV{'LOGDIR'} ||
	(getpwuid($<))[7] || die "You're homeless!\n";
]]></verbatim>
<para>
In particular, this means that you shouldn't use this
for selecting between two aggregates for assignment:
</para>
<para>
特に、これは代入のために二つの集合を選択するためには
使うべきではないことを意味します。
</para>
<verbatim><![CDATA[
@a = @b || @c;		# this is wrong
@a = scalar(@b) || @c;	# really meant this
@a = @b ? @b : @c;		# this works fine, though
]]></verbatim>
<para>
As more readable alternatives to <code>&amp;&amp;</code> and <code>||</code> when used for
control flow, Perl provides <code>and</code> and <code>or</code> operators (see below).
The short-circuit behavior is identical.  The precedence of &quot;and&quot; and
&quot;or&quot; is much lower, however, so that you can safely use them after a
list operator without the need for parentheses:
</para>
<para>
Perl では、フロー制御に使う場合の多少読みやすい <code>&amp;&amp;</code> と <code>||</code> の同義語として、
<code>and</code> 演算子と <code>or</code> 演算子が用意されています (下記参照)。
短絡の動作は全く同じです。
しかし、&quot;and&quot; と &quot;or&quot; の優先順位はかなり低くしてあるので、
引数に括弧を使っていないリスト演算子のあとに続けて使う場合にも、
安心して使うことができます:
</para>
<verbatim><![CDATA[
unlink "alpha", "beta", "gamma"
	    or gripe(), next LINE;
]]></verbatim>
<para>
With the C-style operators that would have been written like this:
</para>
<para>
C スタイルの演算子では以下のように書く必要があります。
</para>
<verbatim><![CDATA[
unlink("alpha", "beta", "gamma")
	    || (gripe(), next LINE);
]]></verbatim>
<para>
Using &quot;or&quot; for assignment is unlikely to do what you want; see below.
</para>
<para>
代入で &quot;or&quot; を使うと、したいことと違うことになります。
以下を参照して下さい。
</para>
</sect2>
<sect2>
<title>Range Operators</title>
<para>
(範囲演算子)
</para>
<para>
Binary &quot;..&quot; is the range operator, which is really two different
operators depending on the context.  In list context, it returns an
array of values counting (up by ones) from the left value to the right
value.  If the left value is greater than the right value then it
returns the empty array.  The range operator is useful for writing
<code>foreach (1..10)</code> loops and for doing slice operations on arrays.  In
the current implementation, no temporary array is created when the
range operator is used as the expression in <code>foreach</code> loops, but older
versions of Perl might burn a lot of memory when you write something
like this:
</para>
<para>
二項演算子の &quot;..&quot; は範囲演算子で、使われるコンテキストによって
異なる動作をする 2 つの演算子を合わせたものです。
リストコンテキストでは、左の値から右の値まで (1 づつ昇順で) 数えあげた値から
なる配列を返します。
左側の値が右側の値より大きい場合は、空配列を返します。
範囲演算子は、<code>foreach (1..10)</code> のようなループを書くときや、
配列のスライス演算を行なうときに便利です。
現状の実装では、<code>foreach</code> ループの式の中で範囲演算子を使っても
一時配列は作りませんが、古い Perl は以下のようなことを書くと、
大量のメモリを消費することになります:
</para>
<verbatim><![CDATA[
for (1 .. 1_000_000) {
	# code
}
]]></verbatim>
<para>
In scalar context, &quot;..&quot; returns a boolean value.  The operator is
bistable, like a flip-flop, and emulates the line-range (comma) operator
of <strong>sed</strong>, <strong>awk</strong>, and various editors.  Each &quot;..&quot; operator maintains its
own boolean state.  It is false as long as its left operand is false.
Once the left operand is true, the range operator stays true until the
right operand is true, <emphasis>AFTER</emphasis> which the range operator becomes false
again.  It doesn't become false till the next time the range operator is
evaluated.  It can test the right operand and become false on the same
evaluation it became true (as in <strong>awk</strong>), but it still returns true once.
If you don't want it to test the right operand till the next
evaluation, as in <strong>sed</strong>, just use three dots (&quot;...&quot;) instead of
two.  In all other regards, &quot;...&quot; behaves just like &quot;..&quot; does.
</para>
<para>
スカラコンテキストで使われたときには、&quot;..&quot; は真偽値を返します。
この演算子は、フリップフロップのように 2 値安定で、
<strong>sed</strong> や <strong>awk</strong> や多くのエディタでの行範囲 (コンマ) 演算子を
エミュレートするものとなります。
各々の &quot;..&quot; 演算子がそれぞれに独立して自分の真偽状態を管理します。
はじめは、左被演算子が偽である間、演算全体も偽となっています。
範囲演算子は、いったん左被演算子が真になると、右被演算子が真である間、
真を返すようになります。
右被演算子が偽になると、演算子も偽を返すようになります。
(次に範囲演算子が評価されるまでは、偽とはなりません。
(<strong>awk</strong> でのように) 真となった、その評価の中で右被演算子をテストし、
偽とすることができますが、1 度は真を返すことになります。
<strong>sed</strong> でのように、次に評価されるまで右被演算子をテストしたくなければ、
2 個のドットの代わりに 3 つのドット (&quot;...&quot;) を使ってください。
その他の点では、&quot;...&quot; は &quot;..&quot; と同様に振舞います．
</para>
<para>
The right operand is not evaluated while the operator is in the
&quot;false&quot; state, and the left operand is not evaluated while the
operator is in the &quot;true&quot; state.  The precedence is a little lower
than || and &amp;&amp;.  The value returned is either the empty string for
false, or a sequence number (beginning with 1) for true.  The
sequence number is reset for each range encountered.  The final
sequence number in a range has the string &quot;E0&quot; appended to it, which
doesn't affect its numeric value, but gives you something to search
for if you want to exclude the endpoint.  You can exclude the
beginning point by waiting for the sequence number to be greater
than 1.  If either operand of scalar &quot;..&quot; is a constant expression,
that operand is implicitly compared to the <code>$.</code> variable, the
current line number.  Examples:
</para>
<para>
右被演算子は、演算子の状態が「偽」である間は評価されることがなく、
左被演算子は、演算子の状態が「真」である間は評価されることがありません。
優先順位は、|| と &amp;&amp; の少し下です。
偽としては空文字列が返され、
真としては (1 から始まる) 順に並んだ数値が返されます。
この通し番号は、新たに範囲が始まるごとにリセットされます。
範囲の最後の数字には、文字列 &quot;E0&quot; がお尻につけられます。
これは、数値としては何の影響もありませんが、範囲の終わりで何か特別なことを
したい場合に、目印として使うことができます。
範囲の始まりで何かしたい場合には、通し番号が 1 よりも大きくなるのを
待っていればよいでしょう。
スカラの &quot;..&quot; の被演算子が定数表現であるときは、その被演算子は暗黙に、
変数 <code>$.</code> と比較されることになります。例:
</para>
<para>
As a scalar operator:
</para>
<para>
スカラー演算子として:
</para>
<verbatim><![CDATA[
if (101 .. 200) { print; }	# print 2nd hundred lines
next line if (1 .. /^$/);	# skip header lines
s/^/> / if (/^$/ .. eof());	# quote body
]]></verbatim>
<verbatim><![CDATA[
# parse mail messages
while (<>) {
    $in_header =   1  .. /^$/;
    $in_body   = /^$/ .. eof();
	# do something based on those
} continue {
	close ARGV if eof; 		# reset $. each file
}
]]></verbatim>
<para>
As a list operator:
</para>
<para>
リスト演算子として:
</para>
<verbatim><![CDATA[
for (101 .. 200) { print; }	# print $_ 100 times
@foo = @foo[0 .. $#foo];	# an expensive no-op
@foo = @foo[$#foo-4 .. $#foo];	# slice last 5 items
]]></verbatim>
<para>
The range operator (in list context) makes use of the magical
auto-increment algorithm if the operands are strings.  You
can say
</para>
<para>
(リストコンテキストでの) 範囲演算子は、被演算子が文字列であるときには、
マジカルインクリメントの機能を使います。
大文字すべての配列を得るのに
</para>
<verbatim><![CDATA[
@alphabet = ('A' .. 'Z');
]]></verbatim>
<para>
to get all normal letters of the alphabet, or
</para>
<para>
と書けますし、
</para>
<verbatim><![CDATA[
$hexdigit = (0 .. 9, 'a' .. 'f')[$num & 15];
]]></verbatim>
<para>
to get a hexadecimal digit, or
</para>
<para>
と書けば、16 進の数字が得られますし、
</para>
<verbatim><![CDATA[
@z2 = ('01' .. '31');  print $z2[$mday];
]]></verbatim>
<para>
to get dates with leading zeros.  If the final value specified is not
in the sequence that the magical increment would produce, the sequence
goes until the next value would be longer than the final value
specified.
</para>
<para>
とすれば、0 付きの日付が得られます。
マジカルインクリメントによって得られる値の中に指定した最終値に
ちょうど一致するものが見つからないような場合には、
マジカルインクリメントによって得られる次の値の文字列長が、
最終値として指定した値のものより長くなるまでインクリメントが続けられます。
</para>
</sect2>
<sect2>
<title>Conditional Operator</title>
<para>
(条件演算子)
</para>
<para>
Ternary &quot;?:&quot; is the conditional operator, just as in C.  It works much
like an if-then-else.  If the argument before the ? is true, the
argument before the : is returned, otherwise the argument after the :
is returned.  For example:
</para>
<para>
三項演算子の &quot;?:&quot; は、C の場合と同じ条件演算子です。
これは、if-then-else のように働きます。
&quot;?&quot; の前の引数が真であれば &quot;:&quot; の前の引数が返されますが、
真でなければ、&quot;:&quot; の後の引数が返されます。例:
</para>
<verbatim><![CDATA[
printf "I have %d dog%s.\n", $n,
	    ($n == 1) ? '' : "s";
]]></verbatim>
<para>
Scalar or list context propagates downward into the 2nd
or 3rd argument, whichever is selected.
</para>
<para>
スカラコンテキストかリストコンテキストかという状況は、
選択された 2 番目もしくは 3 番目の引数にまで伝わります。
</para>
<verbatim><![CDATA[
$a = $ok ? $b : $c;  # get a scalar
@a = $ok ? @b : @c;  # get an array
$a = $ok ? @b : @c;  # oops, that's just a count!
]]></verbatim>
<para>
The operator may be assigned to if both the 2nd and 3rd arguments are
legal lvalues (meaning that you can assign to them):
</para>
<para>
2 番目と 3 番目の引数双方が左辺値 (代入可能ということ)であれば、
この演算子に代入を行なうこともできます:
</para>
<verbatim><![CDATA[
($a_or_b ? $a : $b) = $c;
]]></verbatim>
<para>
Because this operator produces an assignable result, using assignments
without parentheses will get you in trouble.  For example, this:
</para>
<para>
この演算子は代入可能な結果を生み出すので、
括弧なしで代入を行うとおかしくなるかもしれません。例えば:
</para>
<verbatim><![CDATA[
$a % 2 ? $a += 10 : $a += 2
]]></verbatim>
<para>
Really means this:
</para>
<para>
は以下を意味し:
</para>
<verbatim><![CDATA[
(($a % 2) ? ($a += 10) : $a) += 2
]]></verbatim>
<para>
Rather than this:
</para>
<para>
以下のようにはなりません:
</para>
<verbatim><![CDATA[
($a % 2) ? ($a += 10) : ($a += 2)
]]></verbatim>
<para>
That should probably be written more simply as:
</para>
<para>
恐らく以下のようにもっと単純に書くべきでしょう:
</para>
<verbatim><![CDATA[
$a += ($a % 2) ? 10 : 2;
]]></verbatim>
</sect2>
<sect2>
<title>Assignment Operators</title>
<para>
(代入演算子)
</para>
<para>
&quot;=&quot; is the ordinary assignment operator.
</para>
<para>
&quot;=&quot; は通常の代入演算子です。
</para>
<para>
Assignment operators work as in C.  That is,
</para>
<para>
代入演算子は C の場合と同様の働きをします。つまり、
</para>
<verbatim><![CDATA[
$a += 2;
]]></verbatim>
<para>
is equivalent to
</para>
<para>
は以下と等価です。
</para>
<verbatim><![CDATA[
$a = $a + 2;
]]></verbatim>
<para>
although without duplicating any side effects that dereferencing the lvalue
might trigger, such as from tie().  Other assignment operators work similarly.
The following are recognized:
</para>
<para>
しかし、tie() のようなもので起こる左辺値の被参照による
副作用が 2 回起こることはありません。
他の代入演算も同様に働きます。以下のものが認識されます:
</para>
<verbatim><![CDATA[
**=    +=    *=    &=    <<=    &&=
       -=    /=    |=    >>=    ||=
       .=    %=    ^=
	         x=
]]></verbatim>
<para>
Although these are grouped by family, they all have the precedence
of assignment.
</para>
<para>
グループ分けしてありますが、これらはいずれも代入演算子として
同じ優先順位となっています。
</para>
<para>
Unlike in C, the scalar assignment operator produces a valid lvalue.
Modifying an assignment is equivalent to doing the assignment and
then modifying the variable that was assigned to.  This is useful
for modifying a copy of something, like this:
</para>
<para>
C と違って、スカラ代入演算子は有効な左辺値を作り出します。
代入を修正することは、代入を行なってから、その代入された変数を修正するのと
同じことになります。
これは、以下のように何かのコピーを変更したいときに便利です:
</para>
<verbatim><![CDATA[
($tmp = $global) =~ tr [A-Z] [a-z];
]]></verbatim>
<para>
Likewise,
</para>
<para>
同様に、
</para>
<verbatim><![CDATA[
($a += 2) *= 3;
]]></verbatim>
<para>
is equivalent to
</para>
<para>
は以下と同等です。
</para>
<verbatim><![CDATA[
$a += 2;
$a *= 3;
]]></verbatim>
<para>
Similarly, a list assignment in list context produces the list of
lvalues assigned to, and a list assignment in scalar context returns
the number of elements produced by the expression on the right hand
side of the assignment.
</para>
<para>
同様に、リストコンテキストでのリストへの代入は代入可能な左辺値のリストとなり、
スカラコンテキストでのリストへの代入は代入の右側の式で作成された
要素の数を返します。
</para>
</sect2>
<sect2>
<title>Comma Operator</title>
<para>
(コンマ演算子)
</para>
<para>
Binary &quot;,&quot; is the comma operator.  In scalar context it evaluates
its left argument, throws that value away, then evaluates its right
argument and returns that value.  This is just like C's comma operator.
</para>
<para>
二項演算子の &quot;,&quot; はコンマ演算子です。
スカラコンテキストではその左引数を評価し、その値を捨てて、
それから右引数を評価し、その値を返します。
これはちょうど、C のコンマ演算子と同じです。
</para>
<para>
In list context, it's just the list argument separator, and inserts
both its arguments into the list.
</para>
<para>
リストコンテキストでは、これは単にリスト引数の区切り文字で、
双方の引数をそのリストに挿入する働きがあります。
</para>
<para>
The =&gt; digraph is mostly just a synonym for the comma operator.  It's useful for
documenting arguments that come in pairs.  As of release 5.001, it also forces
any word to the left of it to be interpreted as a string.
</para>
<para>
記号 =&gt; は単にコンマ演算子の同義語です。
これはペアで扱われる引数を記述するのに便利です。
5.001 以降では、左辺値の単語を必ず文字列として扱うという効果もあります。
</para>
</sect2>
<sect2>
<title>List Operators (Rightward)</title>
<para>
(リスト演算子 (右方向))
</para>
<para>
On the right side of a list operator, it has very low precedence,
such that it controls all comma-separated expressions found there.
The only operators with lower precedence are the logical operators
&quot;and&quot;, &quot;or&quot;, and &quot;not&quot;, which may be used to evaluate calls to list
operators without the need for extra parentheses:
</para>
<para>
リスト演算子の右側のものにとって、リスト演算子はとても低い優先順位になります。
これによってコンマで区切った式をリスト演算子の引数として
置くことができます。
これよりも優先順位が低いものは、論理演算子の &quot;and&quot;, &quot;or&quot;, &quot;not&quot; のみで、
余分な括弧を付けないリスト演算子の呼び出しを評価するために使うことができます:
</para>
<verbatim><![CDATA[
open HANDLE, "filename"
	or die "Can't open: $!\n";
]]></verbatim>
<para>
See also discussion of list operators in <link xref='Terms and List Operators (Leftward)'>Terms and List Operators (Leftward)</link>.
</para>
<para>
<link xref='Terms and List Operators (Leftward)'>Terms and List Operators (Leftward)</link> のリスト演算子の議論も参照して下さい。
</para>
</sect2>
<sect2>
<title>Logical Not</title>
<para>
(論理否定)
</para>
<para>
Unary &quot;not&quot; returns the logical negation of the expression to its right.
It's the equivalent of &quot;!&quot; except for the very low precedence.
</para>
<para>
単項演算子の &quot;not&quot; は右側に来る式の否定を返します。
これは、優先順位がずっと低いことを除いては &quot;!&quot; と等価です。
</para>
</sect2>
<sect2>
<title>Logical And</title>
<para>
(論理積)
</para>
<para>
Binary &quot;and&quot; returns the logical conjunction of the two surrounding
expressions.  It's equivalent to &amp;&amp; except for the very low
precedence.  This means that it short-circuits: i.e., the right
expression is evaluated only if the left expression is true.
</para>
<para>
二項演算子の &quot;and&quot; は両側の式の論理積を返します。
これは、優先順位がずっと低いことを除けば &amp;&amp; と等価です。
つまり、これも短絡演算を行ない、右側の式は左側の式が
「真」であった場合にのみ評価されます。
</para>
</sect2>
<sect2>
<title>Logical or and Exclusive Or</title>
<para>
(論理和と排他論理和)
</para>
<para>
Binary &quot;or&quot; returns the logical disjunction of the two surrounding
expressions.  It's equivalent to || except for the very low precedence.
This makes it useful for control flow
</para>
<para>
二項演算子の &quot;or&quot; は両側の式の論理和を返します。
これは、優先順位がずっと低いことを除いて || と等価です。
これはフローを制御するのに有用です:
</para>
<verbatim><![CDATA[
print FH $data		or die "Can't write to FH: $!";
]]></verbatim>
<para>
This means that it short-circuits: i.e., the right expression is evaluated
only if the left expression is false.  Due to its precedence, you should
probably avoid using this for assignment, only for control flow.
</para>
<para>
つまり、これも短絡演算を行ない、右側の式は左側の式が
「偽」であった場合にのみ評価されます。
優先度の関係で、これは代入には使わず、フローの制御のみに使うべきです。
</para>
<verbatim><![CDATA[
$a = $b or $c;		# bug: this is wrong
($a = $b) or $c;		# really means this
$a = $b || $c;		# better written this way
]]></verbatim>
<para>
However, when it's a list-context assignment and you're trying to use
&quot;||&quot; for control flow, you probably need &quot;or&quot; so that the assignment
takes higher precedence.
</para>
<para>
しかし、代入がリストコンテキストの時に &quot;||&quot; をフロー制御に使おうとする場合、
代入により大きな優先順位を持たせるために &quot;or&quot; が必要かもしれません。
</para>
<verbatim><![CDATA[
@info = stat($file) || die;     # oops, scalar sense of stat!
@info = stat($file) or die;     # better, now @info gets its due
]]></verbatim>
<para>
Then again, you could always use parentheses.
</para>
<para>
もちろん、常に括弧をつけてもよいです。
</para>
<para>
Binary &quot;xor&quot; returns the exclusive-OR of the two surrounding expressions.
It cannot short circuit, of course.
</para>
<para>
二項演算子の &quot;xor&quot; は両側の式の排他論理和を返します。
これはもちろん、短絡ではありません。
</para>
</sect2>
<sect2>
<title>C Operators Missing From Perl</title>
<para>
(Perl にない C の演算子)
</para>
<para>
Here is what C has that Perl doesn't:
</para>
<para>
C にあって Perl に無いものは以下の通りです:
</para>
<list>
<item><itemtext>unary &amp;</itemtext>
<para>
Address-of operator.  (But see the &quot;\&quot; operator for taking a reference.)
</para>
</item>
<item><itemtext>単項 &amp;</itemtext>
<para>
アドレス演算子。
(&quot;\&quot; 演算子がリファレンスのために用いられます。)
</para>
</item>
<item><itemtext>unary *</itemtext>
<para>
Dereference-address operator. (Perl's prefix dereferencing
operators are typed: $, @, %, and &amp;.)
</para>
</item>
<item><itemtext>単項 *</itemtext>
<para>
被アドレス参照演算子。
(Perl の被参照プリフィクス演算子が型づけを行ないます: $, @, %, &amp;。)
</para>
</item>
<item><itemtext>(TYPE)</itemtext>
<para>
Type-casting operator.
</para>
</item>
<item><itemtext>(型)</itemtext>
<para>
型のキャスト演算子。
</para>
</item>
</list>
</sect2>
<sect2>
<title>Quote and Quote-like Operators</title>
<para>
(クォートとクォート風の演算子)
</para>
<para>
While we usually think of quotes as literal values, in Perl they
function as operators, providing various kinds of interpolating and
pattern matching capabilities.  Perl provides customary quote characters
for these behaviors, but also provides a way for you to choose your
quote character for any of them.  In the following table, a <code>{}</code> represents
any pair of delimiters you choose.
</para>
<para>
クォートはリテラル値であると考えるのが普通ですが、Perl において、
クォートは演算子として働き、さまざまな展開やパターンマッチの機能を
持っています。
そのような動作をさせるのに、Perl は慣習的にクォート文字を使っていますが、
どの種類のクォートも、自分でクォート文字を選べるようになっています。
以下の表では、{} がその選んだ区切文字のペアを示しています。
</para>
<verbatim><![CDATA[
Customary  Generic        Meaning	     Interpolates
	''	 q{}	      Literal		  no
	""	qq{}	      Literal		  yes
	``	qx{}	      Command		  yes (unless '' is delimiter)
		qw{}	     Word list		  no
	//	 m{}	   Pattern match	  yes (unless '' is delimiter)
		qr{}	      Pattern		  yes (unless '' is delimiter)
		 s{}{}	    Substitution	  yes (unless '' is delimiter)
		tr{}{}	  Transliteration	  no (but see below)
]]></verbatim>
<verbatim><![CDATA[
通常記法  汎用記法        意味             展開
    =================================================
	''	 q{}	     リテラル		不可
	""	qq{}	     リテラル		可
	``	qx{}	     コマンド		可 (''がデリミタでなければ)
		qw{}	     単語リスト		不可
	//	 m{}	  パターンマッチ	可 (''がデリミタでなければ)
		qr{}	     パターン		可 (''がデリミタでなければ)
		 s{}{}	       置換		可 (''がデリミタでなければ)
		tr{}{}	       変換		不可 (但し以下を参照のこと)
]]></verbatim>
<para>
Non-bracketing delimiters use the same character fore and aft, but the four
sorts of brackets (round, angle, square, curly) will all nest, which means
that
</para>
<para>
選んだ区切文字が括弧の類でない場合には、前後の文字として同一のものを
使いますが、4 つの括弧 ((), &lt;&gt;, [], {}) の場合にはネストできます。
つまり、以下のものは、
</para>
<verbatim><![CDATA[
q{foo{bar}baz}
]]></verbatim>
<para>
is the same as
</para>
<para>
以下と同じです。
</para>
<verbatim><![CDATA[
'foo{bar}baz'
]]></verbatim>
<para>
Note, however, that this does not always work for quoting Perl code:
</para>
<para>
しかし、以下のコードはクォートされた Perl コードでは
いつも正しく動くわけではないことに注意してください:
</para>
<verbatim><![CDATA[
$s = q{ if($a eq "}") ... }; # WRONG
]]></verbatim>
<para>
is a syntax error. The <code>Text::Balanced</code> module on CPAN is able to do this
properly.
</para>
<para>
これは文法エラーとなります。
CPAN の <code>Text::Balanced</code> モジュールはこれを適切に行います。
</para>
<para>
There can be whitespace between the operator and the quoting
characters, except when <code>#</code> is being used as the quoting character.
<code>q#foo#</code> is parsed as the string <code>foo</code>, while <code>q #foo#</code> is the
operator <code>q</code> followed by a comment.  Its argument will be taken
from the next line.  This allows you to write:
</para>
<para>
演算子とクォート文字の間に空白を置くことも出来ます。
ただし、<code>#</code> をクォート文字として使う場合は例外です。
<code>q#foo#</code> は文字列 <code>foo</code> としてパースされますが、
<code>q #foo#</code> は <code>q</code> 演算子の後にコメントがあるとみなされます。
この引数は次の行から取られます。つまり、以下のように書けます:
</para>
<verbatim><![CDATA[
s {foo}  # Replace foo
  {bar}  # with bar.
]]></verbatim>
<para>
For constructs that do interpolate, variables beginning with &quot;<code>$</code>&quot;
or &quot;<code>@</code>&quot; are interpolated, as are the following escape sequences.  Within
a transliteration, the first eleven of these sequences may be used.
</para>
<para>
展開が行なわれる構文では、&quot;<code>$</code>&quot; や &quot;<code>@</code>&quot; で始まる変数が、
以下のエスケープシーケンスと同時に展開されます。
文字変換の中では、シーケンスの 11 要素が使われます:
</para>
<verbatim><![CDATA[
\t		tab             (HT, TAB)
\n		newline         (NL)
\r		return          (CR)
\f		form feed       (FF)
\b		backspace       (BS)
\a		alarm (bell)    (BEL)
\e		escape          (ESC)
\033	octal char	(ESC)
\x1b	hex char	(ESC)
\x{263a}	wide hex char	(SMILEY)
\c[		control char    (ESC)
\N{name}	named char
]]></verbatim>
<verbatim><![CDATA[
\t          タブ
\n          改行
\r          復帰
\f          改ページ
\b          バックスペース
\a          アラーム (ベル)
\e          エスケープ
\033        8 進数で表した文字
\x1b        16 進数で表した文字
\x{263a}	16 進数で表したワイド文字	(SMILEY)
\c[         コントロール文字
\N{name}	名前つき文字
]]></verbatim>
<verbatim><![CDATA[
\l		lowercase next char
\u		uppercase next char
\L		lowercase till \E
\U		uppercase till \E
\E		end case modification
\Q		quote non-word characters till \E
]]></verbatim>
<verbatim><![CDATA[
\l          次の文字を小文字にする
\u          次の文字を大文字にする
\L          \E まで小文字にする
\U          \E まで大文字にする
\E          変更の終わり
\Q          \E まで非単語文字をクォートする
]]></verbatim>
<para>
If <code>use locale</code> is in effect, the case map used by <code>\l</code>, <code>\L</code>, <code>\u</code>
and <code>\U</code> is taken from the current locale.  See <link xref='perllocale'>perllocale</link>.  For
documentation of <code>\N{name}</code>, see <link xref='charnames'>charnames</link>.
</para>
<para>
<code>use locale</code> が有効の場合、
<code>\l</code>, <code>\L</code>, <code>\u</code>, <code>\U</code> で使われる大文字小文字テーブルは
現在のロケールのものが使われます。
<link xref='perllocale'>perllocale</link> を参照して下さい。
<code>\N{name}</code> のドキュメントに関しては、<link xref='charnames'>charnames</link> を参照して下さい。
</para>
<para>
All systems use the virtual <code>&quot;\n&quot;</code> to represent a line terminator,
called a &quot;newline&quot;.  There is no such thing as an unvarying, physical
newline character.  It is only an illusion that the operating system,
device drivers, C libraries, and Perl all conspire to preserve.  Not all
systems read <code>&quot;\r&quot;</code> as ASCII CR and <code>&quot;\n&quot;</code> as ASCII LF.  For example,
on a Mac, these are reversed, and on systems without line terminator,
printing <code>&quot;\n&quot;</code> may emit no actual data.  In general, use <code>&quot;\n&quot;</code> when
you mean a &quot;newline&quot; for your system, but use the literal ASCII when you
need an exact character.  For example, most networking protocols expect
and prefer a CR+LF (<code>&quot;\015\012&quot;</code> or <code>&quot;\cM\cJ&quot;</code>) for line terminators,
and although they often accept just <code>&quot;\012&quot;</code>, they seldom tolerate just
<code>&quot;\015&quot;</code>.  If you get in the habit of using <code>&quot;\n&quot;</code> for networking,
you may be burned some day.
</para>
<para>
全てのシステムでは &quot;newline&quot; と呼ばれる行端末子を表現するために
仮想的な <code>&quot;\n&quot;</code> が用いられます。
普遍の、物理的な &quot;newline&quot; 文字と言うものはありません。
オペレーティングシステム、デバイスドライバ、C ライブラリ、
Perl が全て協力して保存しようとすると言うのは単なる幻想です。
全てのシステムで <code>&quot;\r&quot;</code> を ASCII CR として、また <code>&quot;\n&quot;</code> を
ASCII LF として読み込むわけではありません。
例えば Mac ではこれらは保存され、行端末子のないシステムでは、
<code>&quot;\n&quot;</code> を print しても実際のデータは何も出力しません。
一般に、システムで &quot;newline&quot; を意味したいときには <code>&quot;\n&quot;</code> を使いますが、
正確な文字が必要な場合はリテラルな ASCII を使います。
例えば、ほとんどのネットワークプロトコルでは行端末子として
CR+LF (<code>&quot;\015\012&quot;</code> または <code>&quot;\cM\cJ&quot;</code>) を予想し、また好みますが、
しばしば <code>&quot;\012&quot;</code> だけでも許容し、さらに時々は <code>&quot;\015&quot;</code> だけでも認めます。
もしネットワーク関係で <code>&quot;\n&quot;</code> を使う習慣がついていると、
いつか痛い目を見ることになるでしょう。
</para>
<para>
You cannot include a literal <code>$</code> or <code>@</code> within a <code>\Q</code> sequence. 
An unescaped <code>$</code> or <code>@</code> interpolates the corresponding variable, 
while escaping will cause the literal string <code>\$</code> to be inserted.
You'll need to write something like <code>m/\Quser\E\@\Qhost/</code>.
</para>
<para>
<code>\Q</code> シーケンスの中にリテラルな <code>$</code> や <code>@</code> を入れることはできません。
エスケープされない <code>$</code> や <code>@</code> は対応する変数に変換されます。
一方、エスケープすると、リテラルな文字列 <code>\$</code> が挿入されます。
<code>m/\Quser\E\@\Qhost/</code> などという風に書く必要があります。
</para>
<para>
Patterns are subject to an additional level of interpretation as a
regular expression.  This is done as a second pass, after variables are
interpolated, so that regular expressions may be incorporated into the
pattern from the variables.  If this is not what you want, use <code>\Q</code> to
interpolate a variable literally.
</para>
<para>
パターンはさらに、正規表現として展開が行なわれます。
これは、変数が展開された後の 2 回目のパスで行なわれるので、
変数に正規表現を含めておき、パターンの中へ展開することができます。
もし、そうしたくないのであれば、<code>\Q</code> を使うと変数の内容を文字通りに
展開することができます。
</para>
<para>
Apart from the behavior described above, Perl does not expand
multiple levels of interpolation.  In particular, contrary to the
expectations of shell programmers, back-quotes do <emphasis>NOT</emphasis> interpolate
within double quotes, nor do single quotes impede evaluation of
variables when used within double quotes.
</para>
<para>
上記の振る舞いを除けば、Perl は 複数の段階を踏んで展開を行ないません。
特に、シェルのプログラマの期待とは裏腹に、
バッククォートはダブルクォートの中では展開されませんし、シングルクォートが
ダブルクォートの中で使われても、変数の展開を妨げることは <emphasis>ありません</emphasis>。
</para>
</sect2>
<sect2>
<title>Regexp Quote-Like Operators</title>
<para>
(正規表現のクォート風の演算子)
</para>
<para>
Here are the quote-like operators that apply to pattern
matching and related activities.
</para>
<para>
以下はパターンマッチングと関連する行動に関するクォート風の演算子です。
</para>
<list>
<item><itemtext>?PATTERN?</itemtext>
<para>
This is just like the <code>/pattern/</code> search, except that it matches only
once between calls to the reset() operator.  This is a useful
optimization when you want to see only the first occurrence of
something in each file of a set of files, for instance.  Only <code>??</code>
patterns local to the current package are reset.
</para>
<para>
これは、reset() 演算子を呼び出すごとに 1 度だけしか
マッチしないことを除いては <code>/pattern/</code> による検索と全く同じです。
たとえば、ファイルの集まりの中で個々のファイルについて、
あるものを探すとき、最初の 1 つだけの存在がわかれば良いのであれば、
この機能を使って最適化をはかることができます。
現在のパッケージにローカルとなっている <code>??</code> のパターンだけが
リセットされます。
</para>
<verbatim><![CDATA[
while (<>) {
	if (?^$?) {
			    # blank line between header and body
	}
} continue {
	reset if eof;	    # clear ?? status for next file
}
]]></verbatim>
<para>
This usage is vaguely deprecated, which means it just might possibly
be removed in some distant future version of Perl, perhaps somewhere
around the year 2168.
</para>
<para>
この方法は、あまりお勧めしません。
Perl の遠い将来のバージョン(おそらく 2168 年頃)では削除されるかもしれません。
</para>
</item>
<item><itemtext>m/PATTERN/cgimosx</itemtext>
</item>
<item><itemtext>/PATTERN/cgimosx</itemtext>
<para>
Searches a string for a pattern match, and in scalar context returns
true if it succeeds, false if it fails.  If no string is specified
via the <code>=~</code> or <code>!~</code> operator, the $_ string is searched.  (The
string specified with <code>=~</code> need not be an lvalue--it may be the
result of an expression evaluation, but remember the <code>=~</code> binds
rather tightly.)  See also <link xref='perlre'>perlre</link>.  See <link xref='perllocale'>perllocale</link> for
discussion of additional considerations that apply when <code>use locale</code>
is in effect.
</para>
<para>
Options are:
</para>
<para>
パターンマッチで文字列検索を行ない、スカラコンテキストでは成功したときは真、
失敗したときは偽を返します。
<code>=~</code> 演算子か <code>!~</code> 演算子で検索対象の文字列を示さなかったときには、
<code>$_</code> の文字列が検索対象となります。
(<code>=~</code> で指定される文字列は、左辺値である必要はありません。
式を評価した結果でもかまいませんが、<code>=~</code> の優先順位がいくぶん高いことに
注意してください。)
<link xref='perlre'>perlre</link> も参照してください。
<code>use locale</code> が有効の場合の議論については <link xref='perllocale'>perllocale</link> を参照して下さい。
</para>
<para>
オプションには以下のものがあります。
</para>
<verbatim><![CDATA[
c	Do not reset search position on a failed match when /g is in effect.
g	Match globally, i.e., find all occurrences.
i	Do case-insensitive pattern matching.
m	Treat string as multiple lines.
o	Compile pattern only once.
s	Treat string as single line.
x	Use extended regular expressions.
]]></verbatim>
<verbatim><![CDATA[
c	/g が有効なとき、マッチングに失敗しても検索位置をリセットしない
g   グローバルにマッチ、つまり、すべてを探し出す
i   大文字、小文字を区別しない
m   文字列を複数行として扱う
o   パターンのコンパイルを 1 度だけにする
s   文字列を単一行として扱う
x   拡張正規表現を使用する
]]></verbatim>
<para>
If &quot;/&quot; is the delimiter then the initial <code>m</code> is optional.  With the <code>m</code>
you can use any pair of non-alphanumeric, non-whitespace characters 
as delimiters.  This is particularly useful for matching path names
that contain &quot;/&quot;, to avoid LTS (leaning toothpick syndrome).  If &quot;?&quot; is
the delimiter, then the match-only-once rule of <code>?PATTERN?</code> applies.
If &quot;'&quot; is the delimiter, no interpolation is performed on the PATTERN.
</para>
<para>
区切文字が &quot;/&quot; のときには、最初の <code>m</code> は付けても付けなくてもかまいません。
<code>m</code> を付けるときには、英数字でも空白でもない、任意の文字のペアを
区切文字として使うことができます。
これは &quot;/&quot; を含むパス名にパターンパッチを行なうときに便利でしょう。
LTS (楊枝偏執症候群) を避けるためにも。
&quot;'&quot; がデリミタの場合、PATTERN に対する展開は行われません。
</para>
<para>
PATTERN may contain variables, which will be interpolated (and the
pattern recompiled) every time the pattern search is evaluated, except
for when the delimiter is a single quote.  (Note that <code>$(</code>, <code>$)</code>, and
<code>$|</code> are not interpolated because they look like end-of-string tests.)
If you want such a pattern to be compiled only once, add a <code>/o</code> after
the trailing delimiter.  This avoids expensive run-time recompilations,
and is useful when the value you are interpolating won't change over
the life of the script.  However, mentioning <code>/o</code> constitutes a promise
that you won't change the variables in the pattern.  If you change them,
Perl won't even notice.  See also <link xref='&quot;qr#STRING/imosx&quot;'>&quot;qr/STRING/imosx&quot;</link>.
</para>
<para>
PATTERN には、変数が含まれていてもよく、パターンが評価されるごとに、
(デリミタがシングルクォートでない限り)
変数は展開され (パターンが再コンパイルされ) ます。
(変数 <code>$(</code>, <code>$)</code>, <code>$|</code> は文字列の終わりを調べるパターンであると
解釈されるので、展開されません。)
パターンがコンパイルされるのを 1 度だけにしたい場合には、
終わりの区切文字の後に <code>/o</code> 修飾子を付けます。
これにより、実行時に再コンパイルが頻繁に起こることが避けられ、
展開する値がスクリプトの実行中に変化しない場合に有効なものとなります。
しかし、<code>/o</code> を付けることは、パターンの中の変数を変更しないことを
約束するものです。
変更したとしても、Perl がそれに気付くことはありません。
<link xref='&quot;qr#STRING/imosx&quot;'>&quot;qr/STRING/imosx&quot;</link> も参照して下さい。
</para>
<para>
If the PATTERN evaluates to the empty string, the last
<emphasis>successfully</emphasis> matched regular expression is used instead.
</para>
<para>
PATTERN を評価した結果が空文字列となった場合には、
最後にマッチに <emphasis>成功した</emphasis> 正規表現が、代わりに使われます。
</para>
<para>
If the <code>/g</code> option is not used, <code>m//</code> in list context returns a
list consisting of the subexpressions matched by the parentheses in the
pattern, i.e., (<code>$1</code>, <code>$2</code>, <code>$3</code>...).  (Note that here <code>$1</code> etc. are
also set, and that this differs from Perl 4's behavior.)  When there are
no parentheses in the pattern, the return value is the list <code>(1)</code> for
success.  With or without parentheses, an empty list is returned upon
failure.
</para>
<para>
Examples:
</para>
<para>
<code>/g</code>オプションが使われなかった場合、リストコンテキストでの<code>m//</code>は
パターンの中の括弧で括られた部分列にマッチしたもので構成されるリストを
返します。
これは、(<code>$1</code>, <code>$2</code>, <code>$3</code>, ...) ということです。
(この場合、<code>$1</code> なども設定されます。
この点で Perl 4 の動作と違っています。)
パターンに括弧がない場合は、返り値は成功時はリスト <code>(1)</code> です。
括弧のあるなしに関わらず、失敗時は空リストを返します。
</para>
<para>
例を示します:
</para>
<verbatim><![CDATA[
open(TTY, '/dev/tty');
<TTY> =~ /^y/i && foo();	# do foo if desired
]]></verbatim>
<verbatim><![CDATA[
if (/Version: *([0-9.]*)/) { $version = $1; }
]]></verbatim>
<verbatim><![CDATA[
next if m#^/usr/spool/uucp#;
]]></verbatim>
<verbatim><![CDATA[
# poor man's grep
$arg = shift;
while (<>) {
	print if /$arg/o;	# compile only once
}
]]></verbatim>
<verbatim><![CDATA[
if (($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))
]]></verbatim>
<para>
This last example splits $foo into the first two words and the
remainder of the line, and assigns those three fields to $F1, $F2, and
$Etc.  The conditional is true if any variables were assigned, i.e., if
the pattern matched.
</para>
<para>
最後の例は、$foo を最初の 2 つの単語と行の残りに分解し、
$F1 と $F2 と $Etc に代入しています。
変数に代入されれば、すなわちパターンがマッチすれば、
if の条件が真となります。
</para>
<para>
The <code>/g</code> modifier specifies global pattern matching--that is,
matching as many times as possible within the string.  How it behaves
depends on the context.  In list context, it returns a list of the
substrings matched by any capturing parentheses in the regular
expression.  If there are no parentheses, it returns a list of all
the matched strings, as if there were parentheses around the whole
pattern.
</para>
<para>
<code>/g</code> 修飾子は、グローバルなパターンマッチを指定するもので、
文字列の中で可能な限りたくさんマッチを行ないます。
この動作は、コンテキストに依存します。
リストコンテキストでは、正規表現内の括弧付けされたものにマッチした
部分文字列のリストが返されます。
括弧がなければ、パターン全体を括弧で括っていたかのように、
すべてのマッチした文字列のリストが返されます。
</para>
<para>
In scalar context, each execution of <code>m//g</code> finds the next match,
returning true if it matches, and false if there is no further match.
The position after the last match can be read or set using the pos()
function; see <link xref='perlfunc#pos'>perlfunc/pos</link>.   A failed match normally resets the
search position to the beginning of the string, but you can avoid that
by adding the <code>/c</code> modifier (e.g. <code>m//gc</code>).  Modifying the target
string also resets the search position.
</para>
<para>
スカラコンテキストでは、<code>m//g</code> を実行する毎に次のマッチを探します。
マッチした場合は真を返し、もうマッチしなくなったら偽を返します。
最後のマッチの位置は pos() 関数で読み出しや設定ができます。
<link xref='perlfunc#pos'>perlfunc/pos</link> を参照して下さい。
マッチに失敗すると通常は検索位置を文字列の先頭にリセットしますが、
<code>/c</code> 修飾子をつける(つまり <code>m//gc</code>)ことでこれを防ぐことができます。
ターゲットとなる文字列が変更された場合も検索位置はリセットされます。
</para>
<para>
You can intermix <code>m//g</code> matches with <code>m/\G.../g</code>, where <code>\G</code> is a
zero-width assertion that matches the exact position where the previous
<code>m//g</code>, if any, left off.  Without the <code>/g</code> modifier, the <code>\G</code> assertion
still anchors at pos(), but the match is of course only attempted once.
Using <code>\G</code> without <code>/g</code> on a target string that has not previously had a
<code>/g</code> match applied to it is the same as using the <code>\A</code> assertion to match
the beginning of the string.
</para>
<para>
Examples:
</para>
<para>
<code>m//g</code> マッチを <code>m/\G.../g</code> と混ぜることもできます。
<code>\G</code> は前回の <code>m//g</code> があればその同じ位置でマッチする
ゼロ文字幅のアサートです。
<code>/g</code> 修飾子なしの場合、<code>\G</code> アサートは pos() に固定しますが、
マッチはもちろん一度だけ試されます。
以前に <code>/g</code> マッチを適用していないターゲット文字列に対して
<code>/g</code> なしで <code>\G</code> を使うと、文字列の先頭にマッチする <code>\A</code> アサートを
使うのと同じことになります。
</para>
<para>
例:
</para>
<verbatim><![CDATA[
# list context
($one,$five,$fifteen) = (`uptime` =~ /(\d+\.\d+)/g);
]]></verbatim>
<verbatim><![CDATA[
# scalar context
$/ = "";
while (defined($paragraph = <>)) {
	while ($paragraph =~ /[a-z]['")]*[.!?]+['")]*\s/g) {
	    $sentences++;
	}
}
print "$sentences\n";
]]></verbatim>
<verbatim><![CDATA[
# using m//gc with \G
$_ = "ppooqppqq";
while ($i++ < 2) {
    print "1: '";
    print $1 while /(o)/gc; print "', pos=", pos, "\n";
    print "2: '";
    print $1 if /\G(q)/gc;  print "', pos=", pos, "\n";
    print "3: '";
    print $1 while /(p)/gc; print "', pos=", pos, "\n";
}
print "Final: '$1', pos=",pos,"\n" if /\G(.)/;
]]></verbatim>
<para>
The last example should print:
</para>
<para>
最後のものは以下のものを表示するはずです:
</para>
<verbatim><![CDATA[
1: 'oo', pos=4
2: 'q', pos=5
3: 'pp', pos=7
1: '', pos=7
2: 'q', pos=8
3: '', pos=8
Final: 'q', pos=8
]]></verbatim>
<para>
Notice that the final match matched <code>q</code> instead of <code>p</code>, which a match
without the <code>\G</code> anchor would have done. Also note that the final match
did not update <code>pos</code> -- <code>pos</code> is only updated on a <code>/g</code> match. If the
final match did indeed match <code>p</code>, it's a good bet that you're running an
older (pre-5.6.0) Perl.
</para>
<para>
<code>\G</code> なしでのマッチが行われたため、最後のマッチでは <code>p</code> ではなく
<code>q</code> がマッチすることに注意してください。
また、最後のマッチは <code>pos</code> を更新しないことに注意してください。
<code>pos</code> は <code>/g</code> マッチでのみ更新されます。
もし最後のマッチで <code>p</code> にマッチした場合、かなりの確率で
古い (5.6.0 以前の) Perl で実行しているはずです。
</para>
<para>
A useful idiom for <code>lex</code>-like scanners is <code>/\G.../gc</code>.  You can
combine several regexps like this to process a string part-by-part,
doing different actions depending on which regexp matched.  Each
regexp tries to match where the previous one leaves off.
</para>
<para>
<code>lex</code> 風にスキャンするために便利な指定は <code>/\G.../gc</code> です。
文字列を部分ごとに処理するためにいくつかの正規表現をつなげて、
どの正規表現にマッチしたかによって異なる処理をすることができます。
それぞれの正規表現は前の正規表現が飛ばした部分に対して
マッチを試みます。
</para>
<verbatim><![CDATA[
$_ = <<'EOL';
     $url = new URI::URL "http://www/";   die if $url eq "xXx";
EOL
LOOP:
   {
     print(" digits"),		redo LOOP if /\G\d+\b[,.;]?\s*/gc;
     print(" lowercase"),	redo LOOP if /\G[a-z]+\b[,.;]?\s*/gc;
     print(" UPPERCASE"),	redo LOOP if /\G[A-Z]+\b[,.;]?\s*/gc;
     print(" Capitalized"),	redo LOOP if /\G[A-Z][a-z]+\b[,.;]?\s*/gc;
     print(" MiXeD"),		redo LOOP if /\G[A-Za-z]+\b[,.;]?\s*/gc;
     print(" alphanumeric"),	redo LOOP if /\G[A-Za-z0-9]+\b[,.;]?\s*/gc;
     print(" line-noise"),	redo LOOP if /\G[^A-Za-z0-9]+/gc;
     print ". That's all!\n";
   }
]]></verbatim>
<para>
Here is the output (split into several lines):
</para>
<para>
出力は以下のようになります(何行かに分割しています):
</para>
<verbatim><![CDATA[
line-noise lowercase line-noise lowercase UPPERCASE line-noise
UPPERCASE line-noise lowercase line-noise lowercase line-noise
lowercase lowercase line-noise lowercase lowercase line-noise
MiXeD line-noise. That's all!
]]></verbatim>
</item>
<item><itemtext>q/STRING/</itemtext>
</item>
<item><itemtext><code>'STRING'</code></itemtext>
<para>
A single-quoted, literal string.  A backslash represents a backslash
unless followed by the delimiter or another backslash, in which case
the delimiter or backslash is interpolated.
</para>
<para>
シングルクォートされた、リテラル文字列です。
バックスラッシュは、後ろに続くものが区切文字か、別のバックスラッシュで
ある場合を除いて単なるバックスラッシュです。
区切文字やバックスラッシュが続く場合には、その区切文字自身もしくは
バックスラッシュそのものが展開されます。
</para>
<verbatim><![CDATA[
$foo = q!I said, "You said, 'She said it.'"!;
$bar = q('This is it.');
$baz = '\n';		# a two-character string
]]></verbatim>
</item>
<item><itemtext>qq/STRING/</itemtext>
</item>
<item><itemtext>&quot;STRING&quot;</itemtext>
<para>
A double-quoted, interpolated string.
</para>
<para>
ダブルクォートされた、リテラル文字列です。
</para>
<verbatim><![CDATA[
$_ .= qq
 (*** The previous line contains the naughty word "$1".\n)
		if /\b(tcl|java|python)\b/i;      # :-)
$baz = "\n";		# a one-character string
]]></verbatim>
</item>
<item><itemtext>qr/STRING/imosx</itemtext>
<para>
This operator quotes (and possibly compiles) its <emphasis>STRING</emphasis> as a regular
expression.  <emphasis>STRING</emphasis> is interpolated the same way as <emphasis>PATTERN</emphasis>
in <code>m/PATTERN/</code>.  If &quot;'&quot; is used as the delimiter, no interpolation
is done.  Returns a Perl value which may be used instead of the
corresponding <code>/STRING/imosx</code> expression.
</para>
<para>
For example,
</para>
<para>
この演算子は <emphasis>STRING</emphasis> を正規表現としてクォートします
(そして可能ならコンパイルします)。
<emphasis>STRING</emphasis> は <code>m/PATTERN/</code> 内の <emphasis>PATTERN</emphasis> と同様に文字変換されます。
&quot;'&quot; がデリミタとして使用された場合、文字変換は行われません。
対応する <code>/STRING/imosx</code> 表現の代わりに使われた Perl の値を返します。
</para>
<para>
例えば:
</para>
<verbatim><![CDATA[
$rex = qr/my.STRING/is;
s/$rex/foo/;
]]></verbatim>
<para>
is equivalent to
</para>
<para>
は以下と等価です:
</para>
<verbatim><![CDATA[
s/my.STRING/foo/is;
]]></verbatim>
<para>
The result may be used as a subpattern in a match:
</para>
<para>
結果はマッチのサブパターンとして使えます:
</para>
<verbatim><![CDATA[
$re = qr/$pattern/;
$string =~ /foo${re}bar/;	# can be interpolated in other patterns
$string =~ $re;		# or used standalone
$string =~ /$re/;		# or this way
]]></verbatim>
<para>
Since Perl may compile the pattern at the moment of execution of qr()
operator, using qr() may have speed advantages in some situations,
notably if the result of qr() is used standalone:
</para>
<para>
Perl は qr() 演算子を実行する瞬間にパターンをコンパイルするので、
qr() を使うことでいくつかの場面で速度的に有利になります。
特に qr() の結果が独立して使われる場合に有利になります。
</para>
<verbatim><![CDATA[
sub match {
	my $patterns = shift;
	my @compiled = map qr/$_/i, @$patterns;
	grep {
	    my $success = 0;
	    foreach my $pat (@compiled) {
		$success = 1, last if /$pat/;
	    }
	    $success;
	} @_;
}
]]></verbatim>
<para>
Precompilation of the pattern into an internal representation at
the moment of qr() avoids a need to recompile the pattern every
time a match <code>/$pat/</code> is attempted.  (Perl has many other internal
optimizations, but none would be triggered in the above example if
we did not use qr() operator.)
</para>
<para>
Options are:
</para>
<para>
qr() の時点でパターンを内部表現にプリコンパイルすることにより、
<code>/$pat/</code> を試みる毎に毎回パターンを再コンパイルするのを避けることができます
(Perl はその他にも多くの内部最適化を行いますが、
上の例で qr() 演算子を使わなかった場合はどの最適化も行われません)。
</para>
<para>
オプションは以下の通りです:
</para>
<verbatim><![CDATA[
i	Do case-insensitive pattern matching.
m	Treat string as multiple lines.
o	Compile pattern only once.
s	Treat string as single line.
x	Use extended regular expressions.
]]></verbatim>
<verbatim><![CDATA[
i	パターンマッチにおいて大文字小文字を区別しない
m	文字列を複数行として扱う
o	一度だけコンパイルする
s	文字列を一行として扱う
x	拡張正規表現を使う
]]></verbatim>
<para>
See <link xref='perlre'>perlre</link> for additional information on valid syntax for STRING, and
for a detailed look at the semantics of regular expressions.
</para>
<para>
STRING の有効な文法に関する追加の情報と、正規表現の意味論に関する
詳細については <link xref='perlre'>perlre</link> を参照して下さい。
</para>
</item>
<item><itemtext>qx/STRING/</itemtext>
</item>
<item><itemtext>`STRING`</itemtext>
<para>
A string which is (possibly) interpolated and then executed as a
system command with <code>/bin/sh</code> or its equivalent.  Shell wildcards,
pipes, and redirections will be honored.  The collected standard
output of the command is returned; standard error is unaffected.  In
scalar context, it comes back as a single (potentially multi-line)
string, or undef if the command failed.  In list context, returns a
list of lines (however you've defined lines with $/ or
$INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
</para>
<para>
展開され、<code>/bin/sh</code> またはそれと等価なものでシステムのコマンドとして
実行される(であろう)文字列です。
シェルのワイルドカード、パイプ、リダイレクトが有効です。
そのコマンドの、標準出力を集めたものが返されます。
標準エラーは影響を与えません。
スカラコンテキストでは、(複数行を含むかもしれない)
1 つの文字列が戻ってきます。
コマンドが失敗したときは未定義値を返します。
リストコンテキストでは、($/ もしくは $INPUT_RECORD_SEPARATOR を
どのように設定していても) 行のリストを返します。
コマンドが失敗したときは空リストを返します。
</para>
<para>
Because backticks do not affect standard error, use shell file descriptor
syntax (assuming the shell supports this) if you care to address this.
To capture a command's STDERR and STDOUT together:
</para>
<para>
バッククォートは標準エラーには影響を与えないので、
標準エラーを使いたい場合は(シェルが対応しているものとして)
シェルのファイル記述子の文法を使ってください。
コマンドの STDERR と STDOUT を共に取得したい場合は:
</para>
<verbatim><![CDATA[
$output = `cmd 2>&1`;
]]></verbatim>
<para>
To capture a command's STDOUT but discard its STDERR:
</para>
<para>
コマンドの STDOUT は取得するが STDERR は捨てる場合は:
</para>
<verbatim><![CDATA[
$output = `cmd 2>/dev/null`;
]]></verbatim>
<para>
To capture a command's STDERR but discard its STDOUT (ordering is
important here):
</para>
<para>
コマンドの STDERR は取得するが STDOUT は捨てる場合は
(ここでは順序が重要です):
</para>
<verbatim><![CDATA[
$output = `cmd 2>&1 1>/dev/null`;
]]></verbatim>
<para>
To exchange a command's STDOUT and STDERR in order to capture the STDERR
but leave its STDOUT to come out the old STDERR:
</para>
<para>
STDERR を取得するが、STDOUT は古い STDERR のために残しておくために
STDOUT と STDERR を交換するには:
</para>
<verbatim><![CDATA[
$output = `cmd 3>&1 1>&2 2>&3 3>&-`;
]]></verbatim>
<para>
To read both a command's STDOUT and its STDERR separately, it's easiest
and safest to redirect them separately to files, and then read from those
files when the program is done:
</para>
<para>
コマンドの STDOUT と STDERR の両方を別々に読み込みたい場合、
一番簡単で安全な方法は別々のファイルにリダイレクトし、
プログラムが終了してからそのファイルを読むことです:
</para>
<verbatim><![CDATA[
system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
]]></verbatim>
<para>
Using single-quote as a delimiter protects the command from Perl's
double-quote interpolation, passing it on to the shell instead:
</para>
<para>
シングルクォートをデリミタとして使うと Perl のダブルクォート展開から
保護され、そのままシェルに渡されます:
</para>
<verbatim><![CDATA[
$perl_info  = qx(ps $$);            # that's Perl's $$
$shell_info = qx'ps $$';            # that's the new shell's $$
]]></verbatim>
<para>
How that string gets evaluated is entirely subject to the command
interpreter on your system.  On most platforms, you will have to protect
shell metacharacters if you want them treated literally.  This is in
practice difficult to do, as it's unclear how to escape which characters.
See <link xref='perlsec'>perlsec</link> for a clean and safe example of a manual fork() and exec()
to emulate backticks safely.
</para>
<para>
この文字列がどのように評価されるかは完全にシステムの
コマンドインタプリタに依存します。
ほとんどのプラットフォームでは、シェルのメタキャラクタを
リテラルに扱ってほしい場合はそれを守る必要があります。
文字をエスケープする方法が明確ではないので、これは理論的には難しいことです。
逆クォートを安全にエミュレートするために手動で fork() と exec() を
行うためのきれいで安全な例については <link xref='perlsec'>perlsec</link> を参照してください。
</para>
<para>
On some platforms (notably DOS-like ones), the shell may not be
capable of dealing with multiline commands, so putting newlines in
the string may not get you what you want.  You may be able to evaluate
multiple commands in a single line by separating them with the command
separator character, if your shell supports that (e.g. <code>;</code> on many Unix
shells; <code>&amp;</code> on the Windows NT <code>cmd</code> shell).
</para>
<para>
(特に DOS 風の)プラットフォームには、シェルが複数行のコマンドを
扱うことができないものがあるので、文字列に改行を入れると
あなたの望まない結果になる場合があります。
シェルが対応していれば、コマンド分割文字で分割することで
1 行に複数のコマンドを入れて解釈させることができます
(この文字は、多くの Unix シェルでは <code>;</code>、Windows NT <code>cmd</code> シェルでは
<code>&amp;</code> です)。
</para>
<para>
Beginning with v5.6.0, Perl will attempt to flush all files opened for
output before starting the child process, but this may not be supported
on some platforms (see <link xref='perlport'>perlport</link>).  To be safe, you may need to set
<code>$|</code> ($AUTOFLUSH in English) or call the <code>autoflush()</code> method of
<code>IO::Handle</code> on any open handles.
</para>
<para>
v5.6.0 以降、Perl は子プロセスの実行前に書き込み用に開いている全ての
ファイルをフラッシュしようとしますが、これに対応していない
プラットフォームもあります(<link xref='perlport'>perlport</link> を参照してください)。
安全のためには、<code>$|</code> (English モジュールでは $AUTOFLUSH)をセットするか、
開いている全てのハンドルに対して <code>IO::Handle</code> の <code>autoflush()</code> メソッドを
呼び出す必要があります。
</para>
<para>
Beware that some command shells may place restrictions on the length
of the command line.  You must ensure your strings don't exceed this
limit after any necessary interpolations.  See the platform-specific
release notes for more details about your particular environment.
</para>
<para>
コマンド行の長さに制限があるコマンドシェルがあることに注意してください。
全ての必要な変換が行われた後、コマンド文字列がこの制限を越えないことを
保障する必要があります。
特定の環境に関するさらなる詳細についてはプラットフォーム固有の
リリースノートを参照してください。
</para>
<para>
Using this operator can lead to programs that are difficult to port,
because the shell commands called vary between systems, and may in
fact not be present at all.  As one example, the <code>type</code> command under
the POSIX shell is very different from the <code>type</code> command under DOS.
That doesn't mean you should go out of your way to avoid backticks
when they're the right way to get something done.  Perl was made to be
a glue language, and one of the things it glues together is commands.
Just understand what you're getting yourself into.
</para>
<para>
この演算子を使うと、プログラムの移殖が困難になります。
呼び出されるシェルコマンドはシステムによって異なり、
実際全く存在しないこともあるからです。
一つの例としては、POSIX シェルの <code>type</code> コマンドは
DOS の <code>type</code> コマンドと大きく異なっています。
これは、何かを為すために正しい方法として逆クォートを使うことを
避けるべきであることを意味しません。
Perl は接着剤のような言語として作られ、接着されるべきものの一つは
コマンドです。
単にあなたが何をしようとしているかを理解しておいてください。
</para>
<para>
See <link xref='&quot;I#O Operators&quot;'>&quot;I/O Operators&quot;</link> for more discussion.
</para>
<para>
さらなる議論については <link xref='&quot;I#O Operators&quot;'>&quot;I/O Operators&quot;</link> を参照して下さい。
</para>
</item>
<item><itemtext>qw/STRING/</itemtext>
<para>
Evaluates to a list of the words extracted out of STRING, using embedded
whitespace as the word delimiters.  It can be understood as being roughly
equivalent to:
</para>
<para>
埋め込まれた空白を区切文字として、STRING から抜き出した
単語のリストを評価します。
これは、以下の式と大体同じと考えられます:
</para>
<verbatim><![CDATA[
split(' ', q/STRING/);
]]></verbatim>
<para>
the difference being that it generates a real list at compile time.  So
this expression:
</para>
<para>
違いは、実際のリストをコンパイル時に生成することです。
従って、以下の表現は:
</para>
<verbatim><![CDATA[
qw(foo bar baz)
]]></verbatim>
<para>
is semantically equivalent to the list:
</para>
<para>
以下のリストと文法的に等価です。
</para>
<verbatim><![CDATA[
'foo', 'bar', 'baz'
]]></verbatim>
<para>
Some frequently seen examples:
</para>
<para>
よく行なわれる例としては以下のものです:
</para>
<verbatim><![CDATA[
use POSIX qw( setlocale localeconv )
@EXPORT = qw( foo bar baz );
]]></verbatim>
<para>
A common mistake is to try to separate the words with comma or to
put comments into a multi-line <code>qw</code>-string.  For this reason, the
<code>use warnings</code> pragma and the <strong>-w</strong> switch (that is, the <code>$^W</code> variable) 
produces warnings if the STRING contains the &quot;,&quot; or the &quot;#&quot; character.
</para>
<para>
よくある間違いは、単語をカンマで区切ったり、複数行の <code>qw</code> 文字列の中に
コメントを書いたりすることです。
このために、<code>usr warnings</code> プラグマと <strong>-w</strong> スイッチ
(つまり、<code>$^W</code> 変数) は STRING に &quot;,&quot; や &quot;#&quot; の文字が入っていると
警告を出します。
</para>
</item>
<item><itemtext>s/PATTERN/REPLACEMENT/egimosx</itemtext>
<para>
Searches a string for a pattern, and if found, replaces that pattern
with the replacement text and returns the number of substitutions
made.  Otherwise it returns false (specifically, the empty string).
</para>
<para>
文字列中でパターンを検索し、もし見つかれば、置換テキストで置き換え、
置換した数を返します。
見つからなければ、偽 (具体的には、空文字列) を返します。
</para>
<para>
If no string is specified via the <code>=~</code> or <code>!~</code> operator, the <code>$_</code>
variable is searched and modified.  (The string specified with <code>=~</code> must
be scalar variable, an array element, a hash element, or an assignment
to one of those, i.e., an lvalue.)
</para>
<para>
<code>=~</code> 演算子や <code>!~</code> 演算子によって文字列が指定されていなければ、
変数 <code>$_</code> が検索され、修正されます。
(<code>=~</code> で指定される文字列は、スカラ変数、配列要素、ハッシュ要素、
あるいは、これらへの代入式といった左辺値でなければなりません。)
</para>
<para>
If the delimiter chosen is a single quote, no interpolation is
done on either the PATTERN or the REPLACEMENT.  Otherwise, if the
PATTERN contains a $ that looks like a variable rather than an
end-of-string test, the variable will be interpolated into the pattern
at run-time.  If you want the pattern compiled only once the first time
the variable is interpolated, use the <code>/o</code> option.  If the pattern
evaluates to the empty string, the last successfully executed regular
expression is used instead.  See <link xref='perlre'>perlre</link> for further explanation on these.
See <link xref='perllocale'>perllocale</link> for discussion of additional considerations that apply
when <code>use locale</code> is in effect.
</para>
<para>
あとで述べますが、区切り文字はスラッシュとは限りません。
シングルクォートを区切り文字として使った場合には、
PATTERN にも REPLACEMENT にも変数の展開を行ないません。
それ以外の場合、文字列の最後を表わすものには見えない $ が
PATTERN に含まれると、実行時に変数がパターン内に展開されます。
最初に変数が展開されるときにだけパターンのコンパイルを行ないたいときには、
<code>/o</code> オプションを使ってください。
パターンの評価結果が空文字列になった場合には、最後に成功した正規表現が
代わりに使われます。
これについてさらに詳しくは、<link xref='perlre'>perlre</link> を参照してください。
<code>use locale</code> が有効の場合の議論については <link xref='perllocale'>perllocale</link> を参照して下さい。
</para>
<para>
Options are:
</para>
<verbatim><![CDATA[
e	Evaluate the right side as an expression.
g	Replace globally, i.e., all occurrences.
i	Do case-insensitive pattern matching.
m	Treat string as multiple lines.
o	Compile pattern only once.
s	Treat string as single line.
x	Use extended regular expressions.
]]></verbatim>
<para>
オプションには以下のものがあります:
</para>
<verbatim><![CDATA[
e   式の右側の評価を行なう
g   グローバルな置換、つまり見つかったものすべて
i   大文字、小文字を区別しないで検索
m   文字列を複数行として扱う
o   パターンのコンパイルを 1 度だけにする
s   文字列を単一行として扱う
x   拡張正規表現を使用する
]]></verbatim>
<para>
Any non-alphanumeric, non-whitespace delimiter may replace the
slashes.  If single quotes are used, no interpretation is done on the
replacement string (the <code>/e</code> modifier overrides this, however).  Unlike
Perl 4, Perl 5 treats backticks as normal delimiters; the replacement
text is not evaluated as a command.  If the
PATTERN is delimited by bracketing quotes, the REPLACEMENT has its own
pair of quotes, which may or may not be bracketing quotes, e.g.,
<code>s(foo)(bar)</code> or <code>s&lt;foo&gt;/bar/</code>.  A <code>/e</code> will cause the
replacement portion to be treated as a full-fledged Perl expression
and evaluated right then and there.  It is, however, syntax checked at
compile-time. A second <code>e</code> modifier will cause the replacement portion
to be <code>eval</code>ed before being run as a Perl expression.
</para>
<para>
Examples:
</para>
<para>
英数字、空白ではない任意の区切り文字で、スラッシュを
置き換えることができます。
先に述べたように、シングルクォートを使うと
置換文字列での展開はされません (<code>/e</code>修飾子を使えば可能です)。
Perl 4 と違って、 Perl 5 はバッククォートを通常のデリミタとして扱います。
置換テキストはコマンドとして評価されません。
PATTERN を括弧類で括った場合には、
REPLACEMENT 用にもう一組の区切り文字を用意します。
これは、括弧類であっても、なくてもかまいません。
例: <code>s(foo)(bar)</code> や <code>s&lt;foo&gt;/bar/</code>。
<code>/e</code> は置換文字列を完全な Perl の式として扱い、その場所で直ちに解釈します。
しかし、これはコンパイル時に構文チェックされます。
二番目の <code>e</code> 修飾子を指定すると、置換部分がまず Perl の式として
<code>eval</code> されます。
</para>
<para>
例:
</para>
<verbatim><![CDATA[
s/\bgreen\b/mauve/g;		# don't change wintergreen
]]></verbatim>
<verbatim><![CDATA[
$path =~ s|/usr/bin|/usr/local/bin|;
]]></verbatim>
<verbatim><![CDATA[
s/Login: $foo/Login: $bar/; # run-time pattern
]]></verbatim>
<verbatim><![CDATA[
($foo = $bar) =~ s/this/that/;	# copy first, then change
]]></verbatim>
<verbatim><![CDATA[
$count = ($paragraph =~ s/Mister\b/Mr./g);  # get change-count
]]></verbatim>
<verbatim><![CDATA[
$_ = 'abc123xyz';
s/\d+/$&*2/e;		# yields 'abc246xyz'
s/\d+/sprintf("%5d",$&)/e;	# yields 'abc  246xyz'
s/\w/$& x 2/eg;		# yields 'aabbcc  224466xxyyzz'
]]></verbatim>
<verbatim><![CDATA[
s/%(.)/$percent{$1}/g;	# change percent escapes; no /e
s/%(.)/$percent{$1} || $&/ge;	# expr now, so /e
s/^=(\w+)/&pod($1)/ge;	# use function call
]]></verbatim>
<verbatim><![CDATA[
# expand variables in $_, but dynamics only, using
# symbolic dereferencing
s/\$(\w+)/${$1}/g;
]]></verbatim>
<verbatim><![CDATA[
# Add one to the value of any numbers in the string
s/(\d+)/1 + $1/eg;
]]></verbatim>
<verbatim><![CDATA[
# This will expand any embedded scalar variable
# (including lexicals) in $_ : First $1 is interpolated
# to the variable name, and then evaluated
s/(\$\w+)/$1/eeg;
]]></verbatim>
<verbatim><![CDATA[
# Delete (most) C comments.
$program =~ s {
	/\*	# Match the opening delimiter.
	.*?	# Match a minimal number of characters.
	\*/	# Match the closing delimiter.
} []gsx;
]]></verbatim>
<verbatim><![CDATA[
s/^\s*(.*?)\s*$/$1/;	# trim white space in $_, expensively
]]></verbatim>
<verbatim><![CDATA[
for ($variable) {		# trim white space in $variable, cheap
	s/^\s+//;
	s/\s+$//;
}
]]></verbatim>
<verbatim><![CDATA[
s/([^ ]*) *([^ ]*)/$2 $1/;	# reverse 1st two fields
]]></verbatim>
<para>
Note the use of $ instead of \ in the last example.  Unlike
<strong>sed</strong>, we use the \&lt;<emphasis>digit</emphasis>&gt; form in only the left hand side.
Anywhere else it's $&lt;<emphasis>digit</emphasis>&gt;.
</para>
<para>
最後の例で \ の代わりに $ を使っているのに注意してください。
<strong>sed</strong> と違って、\&lt;<emphasis>数字</emphasis>&gt; の形式はパターンの方でのみ使用できます。
その他の場所では、$&lt;<emphasis>数字</emphasis>&gt; を使います。
</para>
<para>
Occasionally, you can't use just a <code>/g</code> to get all the changes
to occur that you might want.  Here are two common cases:
</para>
<para>
ときには、<code>/g</code> を付けるだけでは、あなたが望んでいるような形で
すべてを変更することができないことがあります。
2 つ例を示します:
</para>
<verbatim><![CDATA[
# put commas in the right places in an integer
1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
]]></verbatim>
<verbatim><![CDATA[
# expand tabs to 8-column spacing
1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
]]></verbatim>
</item>
<item><itemtext>tr/SEARCHLIST/REPLACEMENTLIST/cds</itemtext>
</item>
<item><itemtext>y/SEARCHLIST/REPLACEMENTLIST/cds</itemtext>
<para>
Transliterates all occurrences of the characters found in the search list
with the corresponding character in the replacement list.  It returns
the number of characters replaced or deleted.  If no string is
specified via the =~ or !~ operator, the $_ string is transliterated.  (The
string specified with =~ must be a scalar variable, an array element, a
hash element, or an assignment to one of those, i.e., an lvalue.)
</para>
<para>
検索リスト (SEARCHLIST) に含まれる文字を、対応する置換リスト
(REPLACEMENTLIST) の文字に変換します。
置換または削除が行なわれた、文字数を返します。
=~ 演算子や =! 演算子で文字列が指定されていなければ、$_ の文字列が変換されます。
(=~ で指定される文字列は、スカラ変数、配列要素、ハッシュ要素、
あるいはこれらへの代入式といった左辺値でなければなりません。)
</para>
<para>
A character range may be specified with a hyphen, so <code>tr/A-J/0-9/</code> 
does the same replacement as <code>tr/ACEGIBDFHJ/0246813579/</code>.
For <strong>sed</strong> devotees, <code>y</code> is provided as a synonym for <code>tr</code>.  If the
SEARCHLIST is delimited by bracketing quotes, the REPLACEMENTLIST has
its own pair of quotes, which may or may not be bracketing quotes,
e.g., <code>tr[A-Z][a-z]</code> or <code>tr(+\-*/)/ABCD/</code>.
</para>
<para>
文字の範囲はハイフンを使って指定できます。
<code>tr/A-J/0-9/</code> は <code>tr/ACEGIBDFHJ/0246813579/</code> と同じ置換を行います。
<strong>sed</strong> の信仰者のために <code>y</code> が <code>tr</code> の同義語として提供されています。
SEARCHLIST を括弧類で括った場合には、
REPLACEMENTLIST 用に、もう一組の区切り文字を用意します。
これは、括弧類であっても、なくてもかまいません。
例: <code>tr[A-Z][a-z]</code> や <code>tr(+\-*/)/ABCD/</code>。
</para>
<para>
Note that <code>tr</code> does <strong>not</strong> do regular expression character classes
such as <code>\d</code> or <code>[:lower:]</code>.  The &lt;tr&gt; operator is not equivalent to
the tr(1) utility.  If you want to map strings between lower/upper
cases, see <link xref='perlfunc#lc'>perlfunc/lc</link> and <link xref='perlfunc#uc'>perlfunc/uc</link>, and in general consider
using the <code>s</code> operator if you need regular expressions.
</para>
<para>
<code>tr</code> は <code>\d</code> や <code>[:lower:]</code> といった正規表現文字クラスを
<strong>使わない</strong> ことに注意してください。
<code>tr</code> 演算子は tr(1) ユーティリティと等価ではありません。
文字列の大文字小文字をマップしたい場合は、
<link xref='perlfunc#lc'>perlfunc/lc</link> と <link xref='perlfunc#uc'>perlfunc/uc</link> を参照して下さい。
また正規表現が必要な場合には一般的に <code>s</code> 演算子を使うことを
考慮してみてください。
</para>
<para>
Note also that the whole range idea is rather unportable between
character sets--and even within character sets they may cause results
you probably didn't expect.  A sound principle is to use only ranges
that begin from and end at either alphabets of equal case (a-e, A-E),
or digits (0-4).  Anything else is unsafe.  If in doubt, spell out the
character sets in full.
</para>
<para>
範囲指定という考え方は文字セットが異なる場合はやや移植性に欠けることにも
注意してください -- そして同じ文字セットでも恐らく期待しているのとは違う
結果を引き起こすこともあります。
健全な原則としては、範囲の最初と最後をどちらもアルファベット
(大文字小文字も同じ)(a-e, A-E)にするか、どちらも数字にする(0-4)ことです。
それ以外は全て安全ではありません。
疑わしいときは、文字セットを完全に書き出してください。
</para>
<para>
Options:
</para>
<verbatim><![CDATA[
c	Complement the SEARCHLIST.
d	Delete found but unreplaced characters.
s	Squash duplicate replaced characters.
]]></verbatim>
<para>
オプションは以下の通りです:
</para>
<verbatim><![CDATA[
c   SEARCHLIST を補集合にする
d   見つかったが置換されなかった文字を削除する
s   置換された文字が重なったときに圧縮する
]]></verbatim>
<para>
If the <code>/c</code> modifier is specified, the SEARCHLIST character set
is complemented.  If the <code>/d</code> modifier is specified, any characters
specified by SEARCHLIST not found in REPLACEMENTLIST are deleted.
(Note that this is slightly more flexible than the behavior of some
<strong>tr</strong> programs, which delete anything they find in the SEARCHLIST,
period.) If the <code>/s</code> modifier is specified, sequences of characters
that were transliterated to the same character are squashed down
to a single instance of the character.
</para>
<para>
<code>/c</code> 修飾子が指定されると、SEARCHLIST には補集合が指定されたものと
解釈されます。
<code>/d</code> 修飾子が指定されると、SEARCHLIST に指定されて、
REPLACEMENTLIST に対応するものがない文字が削除されます。
(これは、SEARCHLIST で見つかったものを削除する、ただそれだけの、ある種の
<strong>tr</strong> プログラムの動作よりと比べれば、いく分柔軟なものになっています。)
<code>/s</code> 修飾子が指定されると、同じ文字に文字変換された文字の並びを、
その文字 1 文字だけに圧縮します。　
</para>
<para>
If the <code>/d</code> modifier is used, the REPLACEMENTLIST is always interpreted
exactly as specified.  Otherwise, if the REPLACEMENTLIST is shorter
than the SEARCHLIST, the final character is replicated till it is long
enough.  If the REPLACEMENTLIST is empty, the SEARCHLIST is replicated.
This latter is useful for counting characters in a class or for
squashing character sequences in a class.
</para>
<para>
Examples:
</para>
<para>
<code>/d</code> 修飾子が使われると、REPLACEMENTLIST は、常に指定された通りに
解釈されます。
<code>/d</code> が指定されない場合で、REPLACEMENTLIST が SEARCHLIST よりも短いと、
同じ長さになるまで、REPLACEMENTLIST の最後の文字が
繰り返されているものとして扱われます。
REPLACEMENTLIST が空文字列でのときには、SEARCHLIST と同じになります。
後者は、ある文字クラスに含まれる文字数を数えるときや、
ある文字クラスの文字の並びを圧縮するようなときに便利です。
</para>
<para>
例:
</para>
<verbatim><![CDATA[
$ARGV[1] =~ tr/A-Z/a-z/;	# canonicalize to lower case
]]></verbatim>
<verbatim><![CDATA[
$cnt = tr/*/*/;		# count the stars in $_
]]></verbatim>
<verbatim><![CDATA[
$cnt = $sky =~ tr/*/*/;	# count the stars in $sky
]]></verbatim>
<verbatim><![CDATA[
$cnt = tr/0-9//;		# count the digits in $_
]]></verbatim>
<verbatim><![CDATA[
tr/a-zA-Z//s;		# bookkeeper -> bokeper
]]></verbatim>
<verbatim><![CDATA[
($HOST = $host) =~ tr/a-z/A-Z/;
]]></verbatim>
<verbatim><![CDATA[
tr/a-zA-Z/ /cs;		# change non-alphas to single space
]]></verbatim>
<verbatim><![CDATA[
tr [\200-\377]
   [\000-\177];		# delete 8th bit
]]></verbatim>
<para>
If multiple transliterations are given for a character, only the
first one is used:
</para>
<para>
複数の文字変換が一つの文字について指定されると、最初のものだけが使われます。
</para>
<verbatim><![CDATA[
tr/AAA/XYZ/
]]></verbatim>
<para>
will transliterate any A to X.
</para>
<para>
は A を X に変換します。
</para>
<para>
Because the transliteration table is built at compile time, neither
the SEARCHLIST nor the REPLACEMENTLIST are subjected to double quote
interpolation.  That means that if you want to use variables, you
must use an eval():
</para>
<para>
変換テーブルはコンパイル時に作られるので、SEARCHLIST も
REPLACEMENTLIST もダブルクォート展開の対象とはなりません。
変数を使いたい場合には、eval() を使わなければならないということです:
</para>
<verbatim><![CDATA[
eval "tr/$oldlist/$newlist/";
die $@ if $@;
]]></verbatim>
<verbatim><![CDATA[
eval "tr/$oldlist/$newlist/, 1" or die $@;
]]></verbatim>
</item>
</list>
</sect2>
<sect2>
<title>Gory details of parsing quoted constructs</title>
<para>
(クォートされた構造のパースに関する詳細)
</para>
<para>
When presented with something that might have several different
interpretations, Perl uses the <strong>DWIM</strong> (that's &quot;Do What I Mean&quot;)
principle to pick the most probable interpretation.  This strategy
is so successful that Perl programmers often do not suspect the
ambivalence of what they write.  But from time to time, Perl's
notions differ substantially from what the author honestly meant.
</para>
<para>
何か複数の解釈が可能な表現があった場合、Perl は最も確からしい解釈を
選択するために <strong>DWIM</strong> (&quot;Do What I Mean&quot;)原則を使います。
この戦略は非常に成功したので、Perl プログラマはしばしば
自分が書いたものの矛盾を疑いません。
しかし時間がたつにつれて、Perl の概念は作者が本当に意味していたものから
かなり変わりました。
</para>
<para>
This section hopes to clarify how Perl handles quoted constructs.
Although the most common reason to learn this is to unravel labyrinthine
regular expressions, because the initial steps of parsing are the
same for all quoting operators, they are all discussed together.
</para>
<para>
この章では Perl がどのようにクォートされた構造を扱うかを
明確にしようと思います。
これを学ぼうとする最もよくある理由は正規表現の迷宮をほぐすためですが、
パースの初期ステップは全てのクォート演算子で同じなので、全て同時に扱います。
</para>
<para>
The most important Perl parsing rule is the first one discussed
below: when processing a quoted construct, Perl first finds the end
of that construct, then interprets its contents.  If you understand
this rule, you may skip the rest of this section on the first
reading.  The other rules are likely to contradict the user's
expectations much less frequently than this first one.
</para>
<para>
Perl のパースに関するルールで最も重要なものは以下で述べているうち
最初のものです。
つまり、クォートされた構造を処理するときは、Perl はまずその構造の
最後を探して、それから中身を解釈します。
このルールがわかれば、とりあえずはこの章の残りは読み飛ばしてもかまいません。
その他のルールは最初のルールに比べてユーザーの予想に反する頻度は
はるかに少ないです。
</para>
<para>
Some passes discussed below are performed concurrently, but because
their results are the same, we consider them individually.  For different
quoting constructs, Perl performs different numbers of passes, from
one to five, but these passes are always performed in the same order.
</para>
<para>
以下で議論するパスには同時に実行されるものもありますが、
結果は同じことなので、別々に考えることにします。
クォート構造の種類によって、Perl が実行するパスの数は
1 から 5 まで異なりますが、これらのパスは常に同じ順番で実行されます。
</para>
<list>
<item><itemtext>Finding the end</itemtext>
<para>
(最後を探す)
</para>
<para>
The first pass is finding the end of the quoted construct, whether
it be a multicharacter delimiter <code>&quot;\nEOF\n&quot;</code> in the <code>&lt;&lt;EOF</code>
construct, a <code>/</code> that terminates a <code>qq//</code> construct, a <code>]</code> which
terminates <code>qq[]</code> construct, or a <code>&gt;</code> which terminates a
fileglob started with <code>&lt;</code>.
</para>
<para>
最初のパスはクォートされた構造の最後を探すことです。
<code>&lt;&lt;EOF</code> 構造の複数文字デリミタである <code>&quot;\nEOF\n&quot;</code>、
<code>qq//</code> 構造の終わりである <code>/</code>、
<code>qq[]</code> 構造の終わりである <code>]</code>、
<code>&lt;</code> で始まるファイルグロブの終わりである <code>&gt;</code> などです。
</para>
<para>
When searching for single-character non-pairing delimiters, such
as <code>/</code>, combinations of <code>\\</code> and <code>\/</code> are skipped.  However,
when searching for single-character pairing delimiter like <code>[</code>,
combinations of <code>\\</code>, <code>\]</code>, and <code>\[</code> are all skipped, and nested
<code>[</code>, <code>]</code> are skipped as well.  When searching for multicharacter
delimiters, nothing is skipped.
</para>
<para>
<code>/</code>のように、1 文字でペアでないデリミタを探す場合、
<code>\\</code> と <code>\/</code> を読み飛ばします。
しかし、<code>[</code>のように 1 文字でペアになるデリミタの場合、
<code>\\</code>, <code>\]</code>, <code>\[</code> を読み飛ばし、
さらにネストした <code>[</code>, <code>]</code> も読み飛ばします。
複数文字のデリミタの場合、何も読み飛ばしません。
</para>
<para>
For constructs with three-part delimiters (<code>s///</code>, <code>y///</code>, and
<code>tr///</code>), the search is repeated once more.
</para>
<para>
3 つのデリミタからなる構造 (<code>s///</code>, <code>y///</code>, <code>tr///</code>) の場合、
検索はもう一度繰り返されます。
</para>
<para>
During this search no attention is paid to the semantics of the construct.
Thus:
</para>
<para>
検索する間、構造の文脈は考慮しません。従って、
</para>
<verbatim><![CDATA[
"$hash{"$foo/$bar"}"
]]></verbatim>
<para>
or:
</para>
<para>
や、
</para>
<verbatim><![CDATA[
m/ 
  bar	# NOT a comment, this slash / terminated m//!
 /x
]]></verbatim>
<para>
do not form legal quoted expressions.   The quoted part ends on the
first <code>&quot;</code> and <code>/</code>, and the rest happens to be a syntax error.
Because the slash that terminated <code>m//</code> was followed by a <code>SPACE</code>,
the example above is not <code>m//x</code>, but rather <code>m//</code> with no <code>/x</code>
modifier.  So the embedded <code>#</code> is interpreted as a literal <code>#</code>.
</para>
<para>
は正しいクォート表現ではありません。
クォートは最初の <code>&quot;</code> や <code>/</code> で終わりとなり、
残りの部分は文法エラーとなります。
<code>m//</code> を終わらせているスラッシュの次に来ているのが <code>空白</code> なので、
上の例では <code>m//x</code> ではなく、<code>/x</code> なしの <code>m//</code> となります。
従って、中にある <code>#</code> はリテラルな <code>#</code> として扱われます。
</para>
</item>
<item><itemtext>Removal of backslashes before delimiters</itemtext>
<para>
(デリミタの前のバックスラッシュの削除)
</para>
<para>
During the second pass, text between the starting and ending
delimiters is copied to a safe location, and the <code>\</code> is removed
from combinations consisting of <code>\</code> and delimiter--or delimiters,
meaning both starting and ending delimiters will should these differ.
This removal does not happen for multi-character delimiters.
Note that the combination <code>\\</code> is left intact, just as it was.
</para>
<para>
第二のパスとして、開始デリミタと終了デリミタの間のテキストは
安全な場所にコピーされ、<code>\</code> とデリミタの組み合わせから
<code>\</code> を削除します。
開始デリミタと終了デリミタが異なる場合はその両方に対してです。
この削除は複数文字デリミタに対しては行われません。
今までと同様、<code>\\</code> はそのまま残されることに注意してください。
</para>
<para>
Starting from this step no information about the delimiters is
used in parsing.
</para>
<para>
このステップの開始から、デリミタに関する情報は一切パースには
使われません。
</para>
</item>
<item><itemtext>Interpolation</itemtext>
<para>
(文字変換)
</para>
<para>
The next step is interpolation in the text obtained, which is now
delimiter-independent.  There are four different cases.
</para>
<para>
次のステップは、得られた(デリミタに依存しない)テキストに対する文字変換です。
4 つのケースがあります。
</para>
</item>
<list>
<item><itemtext><code>&lt;&lt;'EOF'</code>, <code>m''</code>, <code>s'''</code>, <code>tr///</code>, <code>y///</code></itemtext>
<para>
No interpolation is performed.
</para>
<para>
文字変換は行われません。
</para>
</item>
<item><itemtext><code>''</code>, <code>q//</code></itemtext>
<para>
The only interpolation is removal of <code>\</code> from pairs <code>\\</code>.
</para>
<para>
<code>\\</code> の組における <code>\</code> の削除のみが行われます。
</para>
</item>
<item><itemtext><code>&quot;&quot;</code>, <code>``</code>, <code>qq//</code>, <code>qx//</code>, <code>&lt;file*glob&gt;</code></itemtext>
<para>
<code>\Q</code>, <code>\U</code>, <code>\u</code>, <code>\L</code>, <code>\l</code> (possibly paired with <code>\E</code>) are
converted to corresponding Perl constructs.  Thus, <code>&quot;$foo\Qbaz$bar&quot;</code>
is converted to <code>$foo . (quotemeta(&quot;baz&quot; . $bar))</code> internally.
The other combinations are replaced with appropriate expansions.
</para>
<para>
<code>\Q</code>, <code>\U</code>, <code>\u</code>, <code>\L</code>, <code>\l</code> (おそらくは <code>\E</code> との組)は
対応する Perl 構造に変換されます。
従って、<code>&quot;$foo\Qbaz$bar&quot;</code> は内部的に
<code>$foo . (quotemeta(&quot;baz&quot; . $bar))</code> に変換されます。
その他の組み合わせは適切な拡張に置換されます。
</para>
<para>
Let it be stressed that <emphasis>whatever falls between <code>\Q</code> and <code>\E</code></emphasis>
is interpolated in the usual way.  Something like <code>&quot;\Q\\E&quot;</code> has
no <code>\E</code> inside.  instead, it has <code>\Q</code>, <code>\\</code>, and <code>E</code>, so the
result is the same as for <code>&quot;\\\\E&quot;</code>.  As a general rule, backslashes
between <code>\Q</code> and <code>\E</code> may lead to counterintuitive results.  So,
<code>&quot;\Q\t\E&quot;</code> is converted to <code>quotemeta(&quot;\t&quot;)</code>, which is the same
as <code>&quot;\\\t&quot;</code> (since TAB is not alphanumeric).  Note also that:
</para>
<para>
<emphasis><code>\Q</code> と <code>\E</code> の間にある全てのもの</emphasis> が通常の方法で展開されます。
<code>&quot;\Q\\E&quot;</code> のようなものは内部にあるのは <code>\E</code> ではなく、
<code>\Q</code>, <code>\\</code>, <code>E</code> であるので、結果は <code>&quot;\\\\E&quot;</code> と同じになります。
一般的なルールとして、<code>\Q</code> と <code>\E</code> の間にあるバックスラッシュは
直感に反した結果になります。
それで、<code>&quot;\Q\t\E&quot;</code> は <code>quotemeta(&quot;\t&quot;)</code> に変換され、これは(TAB は
英数字ではないので <code>&quot;\\\t&quot;</code> と同じです。
以下のようなことにも注意してください:
</para>
<verbatim><![CDATA[
$str = '\t';
return "\Q$str";
]]></verbatim>
<para>
may be closer to the conjectural <emphasis>intention</emphasis> of the writer of <code>&quot;\Q\t\E&quot;</code>.
</para>
<para>
これは <code>&quot;\Q\t\E&quot;</code> を書いた人の憶測上の <emphasis>意図</emphasis> により近いです。
</para>
<para>
Interpolated scalars and arrays are converted internally to the <code>join</code> and
<code>.</code> catenation operations.  Thus, <code>&quot;$foo XXX '@arr'&quot;</code> becomes:
</para>
<para>
展開されたスカラと配列は内部で <code>join</code> と <code>.</code> の結合操作に変換されます。
従って、<code>&quot;$foo XXX '@arr'&quot;</code> は以下のようになります:
</para>
<verbatim><![CDATA[
$foo . " XXX '" . (join $", @arr) . "'";
]]></verbatim>
<para>
All operations above are performed simultaneously, left to right.
</para>
<para>
上記の全ての操作は、左から右に同時に行われます。
</para>
<para>
Because the result of <code>&quot;\Q STRING \E&quot;</code> has all metacharacters
quoted, there is no way to insert a literal <code>$</code> or <code>@</code> inside a
<code>\Q\E</code> pair.  If protected by <code>\</code>, <code>$</code> will be quoted to became
<code>&quot;\\\$&quot;</code>; if not, it is interpreted as the start of an interpolated
scalar.
</para>
<para>
<code>&quot;\Q STRING \E&quot;</code> の結果は全てのメタ文字がクォートされているので、
<code>\Q\E</code> の組の内側にリテラルの <code>$</code> や <code>@</code> を挿入する方法はありません。
<code>\</code> によって守られている場合、<code>$</code> はクォートされて <code>&quot;\\\$&quot;</code> と
なります。
そうでない場合、これは展開されるスカラ変数の開始として解釈されます。
</para>
<para>
Note also that the interpolation code needs to make a decision on
where the interpolated scalar ends.  For instance, whether 
<code>&quot;a $b -&gt; {c}&quot;</code> really means:
</para>
<para>
展開コードは、展開するスカラ変数がどこで終わるかを決定する必要が
あることにも注意してください。
例えば、<code>&quot;a $b -&gt; {c}&quot;</code> が実際には以下のようになるか:
</para>
<verbatim><![CDATA[
"a " . $b . " -> {c}";
]]></verbatim>
<para>
以下のようになるかです:
</para>
<verbatim><![CDATA[
"a " . $b -> {c};
]]></verbatim>
<para>
Most of the time, the longest possible text that does not include
spaces between components and which contains matching braces or
brackets.  because the outcome may be determined by voting based
on heuristic estimators, the result is not strictly predictable.
Fortunately, it's usually correct for ambiguous cases.
</para>
<para>
ほとんどの場合、要素と、マッチする中かっこや大かっこの間に空白を含まない、
最も長いテキストになります。
出力は発見的な推定器をよる投票によって決定されるので、結果は厳密には
予測できません。
幸い、紛らわしい場合でも普通は正しいです。
</para>
</item>
<item><itemtext><code>?RE?</code>, <code>/RE/</code>, <code>m/RE/</code>, <code>s/RE/foo/</code>,</itemtext>
<para>
Processing of <code>\Q</code>, <code>\U</code>, <code>\u</code>, <code>\L</code>, <code>\l</code>, and interpolation
happens (almost) as with <code>qq//</code> constructs, but the substitution
of <code>\</code> followed by RE-special chars (including <code>\</code>) is not
performed.  Moreover, inside <code>(?{BLOCK})</code>, <code>(?# comment )</code>, and
a <code>#</code>-comment in a <code>//x</code>-regular expression, no processing is
performed whatsoever.  This is the first step at which the presence
of the <code>//x</code> modifier is relevant.
</para>
<para>
<code>\Q</code>, <code>\U</code>, <code>\u</code>, <code>\L</code>, <code>\l</code> の処理と展開が <code>qq//</code> 構造と(ほとんど)
同じように起こりますが, <code>\</code> の後に正規表現の特殊文字(<code>\</code> を含みます)が
続く場合の置換は行われません。
さらに、<code>(?{BLOCK})</code>, <code>(?# comment )</code>, <code>//x</code> 正規表現での <code>#</code> の
コメントの中では、どのような処理も行われません。
これは <code>//x</code> 修飾子が影響を与える最初のステップです。
</para>
<para>
Interpolation has several quirks: <code>$|</code>, <code>$(</code>, and <code>$)</code> are not
interpolated, and constructs <code>$var[SOMETHING]</code> are voted (by several
different estimators) to be either an array element or <code>$var</code>
followed by an RE alternative.  This is where the notation
<code>${arr[$bar]}</code> comes handy: <code>/${arr[0-9]}/</code> is interpreted as
array element <code>-9</code>, not as a regular expression from the variable
<code>$arr</code> followed by a digit, which would be the interpretation of
<code>/$arr[0-9]/</code>.  Since voting among different estimators may occur,
the result is not predictable.
</para>
<para>
展開ではいくつか特殊な動作をします: <code>$|</code>, <code>$(</code>, <code>$)</code> は展開されず、
<code>$var[SOMETHING]</code> は(いくつかの異なる推定器によって)配列の要素か
<code>$var</code> の後に正規表現が続いているのかが投票されます。
これは <code>${arr[$bar]}</code> が便利になるところです: <code>/${arr[0-9]}/</code> は
配列要素 <code>-9</code> として解釈され、<code>/$arr[0-9]/</code> の場合のように <code>$arr</code> の後に
数値が続いているような正規表現としては解釈されません。
異なった推定器によって投票されることがあるので、結果は予測できません。
</para>
<para>
It is at this step that <code>\1</code> is begrudgingly converted to <code>$1</code> in
the replacement text of <code>s///</code> to correct the incorrigible
<emphasis>sed</emphasis> hackers who haven't picked up the saner idiom yet.  A warning
is emitted if the <code>use warnings</code> pragma or the <strong>-w</strong> command-line flag
(that is, the <code>$^W</code> variable) was set.
</para>
<para>
このステップでは、より健全な文法をまだ導入していない、手に負えない <emphasis>sed</emphasis>
ハッカーのために、<code>s///</code> の置換テキストの中にある <code>\1</code> を、しぶしぶながら
<code>$1</code> に変換します。
<code>use warnings</code> プラグマやコマンドラインオプション <strong>-w</strong> (これは <code>$^W</code>
変数です) がセットされていると警告が生成されます。
</para>
<para>
The lack of processing of <code>\\</code> creates specific restrictions on
the post-processed text.  If the delimiter is <code>/</code>, one cannot get
the combination <code>\/</code> into the result of this step.  <code>/</code> will
finish the regular expression, <code>\/</code> will be stripped to <code>/</code> on
the previous step, and <code>\\/</code> will be left as is.  Because <code>/</code> is
equivalent to <code>\/</code> inside a regular expression, this does not
matter unless the delimiter happens to be character special to the
RE engine, such as in <code>s*foo*bar*</code>, <code>m[foo]</code>, or <code>?foo?</code>; or an
alphanumeric char, as in:
</para>
<para>
<code>\\</code> を処理しないことにより、後処理したテキストに特定の制限があります。
デリミタが <code>/</code> の場合、このステップの結果として <code>\/</code> を得ることは
できません。
<code>/</code> は正規表現を終わらせ、<code>\/</code> は前のステップで <code>/</code> に展開され、
<code>\\/</code> はそのまま残されます。
<code>/</code> は正規表現の中では <code>\/</code> と等価なので、これはたまたまデリミタが
正規検索エンジンにとって特別な文字の場合、つまり <code>s*foo*bar*</code>,
<code>m[foo]</code>, <code>?foo?</code> のような場合、あるいは以下のように英数字でなければ、
問題にはなりません:
</para>
<verbatim><![CDATA[
m m ^ a \s* b mmx;
]]></verbatim>
<para>
In the RE above, which is intentionally obfuscated for illustration, the
delimiter is <code>m</code>, the modifier is <code>mx</code>, and after backslash-removal the
RE is the same as for <code>m/ ^ a s* b /mx</code>).  There's more than one 
reason you're encouraged to restrict your delimiters to non-alphanumeric,
non-whitespace choices.
</para>
<para>
上記の正規表現では、説明のために意図的にわかりにくくしていますが、
デリミタは <code>m</code> で、修飾子は <code>mx</code> で、バックスラッシュを取り除いた後の
正規表現は <code>m/ ^ a s* b /mx</code>) と同じです。
デリミタを英数字や空白でないものに制限するべきである理由は複数あります。
</para>
</item>
</list>
<para>
This step is the last one for all constructs except regular expressions,
which are processed further.
</para>
<para>
これは正規表現以外の全ての構造にとって最後のステップです。
正規表現はさらに処理が続きます。
</para>
<item><itemtext>Interpolation of regular expressions</itemtext>
<para>
(正規表現の文字変換)
</para>
<para>
Previous steps were performed during the compilation of Perl code,
but this one happens at run time--although it may be optimized to
be calculated at compile time if appropriate.  After preprocessing
described above, and possibly after evaluation if catenation,
joining, casing translation, or metaquoting are involved, the
resulting <emphasis>string</emphasis> is passed to the RE engine for compilation.
</para>
<para>
以前のステップは Perl コードのコンパイル中に実行されますが、
これは実行時に起こります -- しかし、もし適切ならコンパイル時に
計算できるように最適化されることもあります。
上記の前処理の後、そして必要なら連結、結合、大文字小文字変換、
メタクォート化が行われた後、結果の <emphasis>文字列</emphasis> がコンパイルのために
正規表現エンジンに渡されます。
</para>
<para>
Whatever happens in the RE engine might be better discussed in <link xref='perlre'>perlre</link>,
but for the sake of continuity, we shall do so here.
</para>
<para>
正規表現エンジンで起こることについては <link xref='perlre'>perlre</link> で議論した方が
よいでしょうが、継続性のために、ここでそれを行います。
</para>
<para>
This is another step where the presence of the <code>//x</code> modifier is
relevant.  The RE engine scans the string from left to right and
converts it to a finite automaton.
</para>
<para>
これも <code>//x</code> 修飾子の存在が関連するステップの一つです。
正規表現エンジンは文字列を左から右にスキャンして、有限状態オートマトンに
変換します。
</para>
<para>
Backslashed characters are either replaced with corresponding
literal strings (as with <code>\{</code>), or else they generate special nodes
in the finite automaton (as with <code>\b</code>).  Characters special to the
RE engine (such as <code>|</code>) generate corresponding nodes or groups of
nodes.  <code>(?#...)</code> comments are ignored.  All the rest is either
converted to literal strings to match, or else is ignored (as is
whitespace and <code>#</code>-style comments if <code>//x</code> is present).
</para>
<para>
バックスラッシュ付きの文字は(<code>\{</code> のように)対応するリテラル文字列に
置換されるか、あるいは(<code>\b</code> のように)有限状態オートマトンの特別な
ノードを生成します。
(<code>|</code> のような)正規表現エンジンにとって特別な文字は対応するノードか
ノードのグループを生成します。
残りの全てはマッチするリテラル文字列に変換されるか、そうでなければ
(<code>//x</code> が指定された時の空白と <code>#</code> スタイルのコメントと同様に)
無視されます。
</para>
<para>
Parsing of the bracketed character class construct, <code>[...]</code>, is
rather different than the rule used for the rest of the pattern.
The terminator of this construct is found using the same rules as
for finding the terminator of a <code>{}</code>-delimited construct, the only
exception being that <code>]</code> immediately following <code>[</code> is treated as
though preceded by a backslash.  Similarly, the terminator of
<code>(?{...})</code> is found using the same rules as for finding the
terminator of a <code>{}</code>-delimited construct.
</para>
<para>
文字クラス構造 <code>[...]</code> のパースは他のパターンとはルールが異なります。
この構造の終端は <code>{}</code> でデリミタされた構造の終端を検索するのと同じルールで
検索されます; 唯一の例外は、<code>[</code> の直後の <code>]</code> はバックスラッシュが
先行しているものとして扱われます。
同様に、<code>(?{...})</code> の終端は <code>{}</code> でデリミタされた構造の終端を
検索されるのと同じルールで検索されます。
</para>
<para>
It is possible to inspect both the string given to RE engine and the
resulting finite automaton.  See the arguments <code>debug</code>/<code>debugcolor</code>
in the <code>use <link xref='re'>re</link></code> pragma, as well as Perl's <strong>-Dr</strong> command-line
switch documented in <link xref='perlrun#Command_Switches'>perlrun/&quot;Command Switches&quot;</link>.
</para>
<para>
正規表現に与えられる文字列と、結果としての有限状態オートマトンの両方を
検査できます。
<code>use <link xref='re'>re</link></code> プラグマの <code>debug</code>/<code>debugcolor</code> 引数と、
<link xref='perlrun#Command_Switches'>perlrun/&quot;Command Switches&quot;</link> に記述されている <strong>-Dr</strong> コマンドライン
オプションを参照してください。
</para>
</item>
<item><itemtext>Optimization of regular expressions</itemtext>
<para>
(正規表現の最適化)
</para>
<para>
This step is listed for completeness only.  Since it does not change
semantics, details of this step are not documented and are subject
to change without notice.  This step is performed over the finite
automaton that was generated during the previous pass.
</para>
<para>
このステップは完全性のためだけにリストされています。
これは意味論的には変化がないので、このステップの詳細は文書化されておらず、
将来予告なしに変更されることがあります。
このステップはここまでの処理で生成された有限オートマトンに対して
適用されます。
</para>
<para>
It is at this stage that <code>split()</code> silently optimizes <code>/^/</code> to
mean <code>/^/m</code>.
</para>
<para>
<code>split()</code> で <code>/^/</code> を暗黙に <code>/^/m</code> に最適化するのもこのステップです。
</para>
</item>
</list>
</sect2>
<sect2>
<title>I/O Operators</title>
<para>
(I/O 演算子)
</para>
<para>
There are several I/O operators you should know about.
</para>
<para>
知っておいた方がよい I/O 演算子もいくつかあります。
</para>
<para>
A string enclosed by backticks (grave accents) first undergoes
double-quote interpolation.  It is then interpreted as an external
command, and the output of that command is the value of the
backtick string, like in a shell.  In scalar context, a single string
consisting of all output is returned.  In list context, a list of
values is returned, one per line of output.  (You can set <code>$/</code> to use
a different line terminator.)  The command is executed each time the
pseudo-literal is evaluated.  The status value of the command is
returned in <code>$?</code> (see <link xref='perlvar'>perlvar</link> for the interpretation of <code>$?</code>).
Unlike in <strong>csh</strong>, no translation is done on the return data--newlines
remain newlines.  Unlike in any of the shells, single quotes do not
hide variable names in the command from interpretation.  To pass a
literal dollar-sign through to the shell you need to hide it with a
backslash.  The generalized form of backticks is <code>qx//</code>.  (Because
backticks always undergo shell expansion as well, see <link xref='perlsec'>perlsec</link> for
security concerns.)
</para>
<para>
バッククォートで括られた文字列は、まず、ダブルクォート補完のように
変数の展開が行なわれます。
その後、シェルでの場合と同じように、外部コマンドとして解釈され、
そのコマンドの出力がこのバッククォート文字列の値となります。
スカラーコンテキストでは、出力すべてを含む一個の文字列が返されます。
リストコンテキストでは、出力の 1 行 1 行が個々の要素となるリストが返されます。
(<code>$/</code> を設定すれば、行の終わりを示す文字を変えることができます。)
コマンドは、この擬似リテラルが評価されるごとに実行されます。
コマンドのステータス値は <code>$?</code> に返されます (<code>$?</code> の解釈については、
<link xref='perlvar'>perlvar</link> を参照してください)。
<strong>csh</strong> での場合とは違って、結果のデータに対する変換は行なわれず、
改行は改行のままです。
どのシェルとも違って、シングルクォートがコマンド中の変数名を
解釈させないようにすることはありません。
シェルにリテラルなドル記号を渡すには、バックスラッシュで
エスケープしなければなりません。
バッククォートの一般形は、<code>qx//</code> です。
(バッククォートは常にシェル展開されます。
セキュリティに関しては <link xref='perlsec'>perlsec</link> を参照して下さい)
</para>
<para>
In scalar context, evaluating a filehandle in angle brackets yields
the next line from that file (the newline, if any, included), or
<code>undef</code> at end-of-file or on error.  When <code>$/</code> is set to <code>undef</code>
(sometimes known as file-slurp mode) and the file is empty, it
returns <code>''</code> the first time, followed by <code>undef</code> subsequently.
</para>
<para>
スカラーコンテキストで山括弧の中のファイルハンドルを評価すると、
そのファイルから、次の行を読み込むことになります
(改行があればそれも含まれます)。
ファイルの最後またはエラーの場合は <code>undef</code> を返します。
<code>$/</code> が <code>undef</code> に設定されている場合(ファイル吸い込みモードと呼ばれます)
でファイルが空の場合、
最初は <code>''</code> を返し、次は <code>undef</code> を返します。
</para>
<para>
Ordinarily you must assign the returned value to a variable, but
there is one situation where an automatic assignment happens.  If
and only if the input symbol is the only thing inside the conditional
of a <code>while</code> statement (even if disguised as a <code>for(;;)</code> loop),
the value is automatically assigned to the global variable $_,
destroying whatever was there previously.  (This may seem like an
odd thing to you, but you'll use the construct in almost every Perl
script you write.)  The $_ variable is not implicitly localized.
You'll have to put a <code>local $_;</code> before the loop if you want that
to happen.
</para>
<para>
The following lines are equivalent:
</para>
<para>
通常は、返された値を変数に代入しなければなりませんが、自動的に
代入される場合が 1 つだけあります。
この入力シンボルが、while 文(<code>for(;;)</code> の形になっていたとしても)の条件式中に
単独で現れた場合だけは、その値が自動的にグローバル変数 $_ に代入されます。
以前の値は破壊されます。
(これは、奇妙に思えるかもしれませんが、ほとんどすべての Perl スクリプトで
これが必要になることでしょう。)
$_ 変数は暗黙にはローカル化されません。
そうしたい場合はループの前に <code>local $_;</code> と書く必要があります。
</para>
<para>
以下のものは、お互いに同値なものです:
</para>
<verbatim><![CDATA[
while (defined($_ = <STDIN>)) { print; }
while ($_ = <STDIN>) { print; }
while (<STDIN>) { print; }
for (;<STDIN>;) { print; }
print while defined($_ = <STDIN>);
print while ($_ = <STDIN>);
print while <STDIN>;
]]></verbatim>
<para>
This also behaves similarly, but avoids $_ :
</para>
<para>
以下は同様の振る舞いをしますが、$_ を使いません:
</para>
<verbatim><![CDATA[
while (my $line = <STDIN>) { print $line }
]]></verbatim>
<para>
In these loop constructs, the assigned value (whether assignment
is automatic or explicit) is then tested to see whether it is
defined.  The defined test avoids problems where line has a string
value that would be treated as false by Perl, for example a &quot;&quot; or
a &quot;0&quot; with no trailing newline.  If you really mean for such values
to terminate the loop, they should be tested for explicitly:
</para>
<para>
これらのループ構造の中で、代入された値は (代入が自動か明示的かに関わりなく)
定義されているかどうかを見るためにテストされます。
定義テストは、行が Perl にとって偽となる文字列値を持っているかどうかの
問題を避けます。例えば newline のついていない  &quot;&quot; や &quot;0&quot; です。
もし本当にこのような値でループを終了させたいときは、
以下のように明示的にテストするべきです:
</para>
<verbatim><![CDATA[
while (($_ = <STDIN>) ne '0') { ... }
while (<STDIN>) { last unless $_; ... }
]]></verbatim>
<para>
In other boolean contexts, <code>&lt;<emphasis>filehandle</emphasis>&gt;</code> without an
explicit <code>defined</code> test or comparison elicit a warning if the 
<code>use warnings</code> pragma or the <strong>-w</strong>
command-line switch (the <code>$^W</code> variable) is in effect.
</para>
<para>
その他のブール値コンテキストでは、明示的な <code>defined</code> や比較なしに
<code>&lt;<emphasis>filehandle</emphasis>&gt;</code> を使うと、<code>use warnings</code> プラグマや
<strong>-w</strong> コマンドラインスイッチ (<code>$^W</code> 変数) が有効なときには、
警告を発生させます。
</para>
<para>
The filehandles STDIN, STDOUT, and STDERR are predefined.  (The
filehandles <code>stdin</code>, <code>stdout</code>, and <code>stderr</code> will also work except
in packages, where they would be interpreted as local identifiers
rather than global.)  Additional filehandles may be created with
the open() function, amongst others.  See <link xref='perlopentut'>perlopentut</link> and
<link xref='perlfunc#open'>perlfunc/open</link> for details on this.
</para>
<para>
STDIN、STDOUT、STDERR というファイルハンドルは、あらかじめ定義されています。
(<code>stdin</code>、<code>stdout</code>、<code>stderr</code> というファイルハンドルも、
ローカルな名前でこれらのグローバルな名前が見えなくなっている
パッケージを除けば、使用することができます。)
その他のファイルハンドルは、open() 関数などで作ることができます。
これに関する詳細については <link xref='perlopentut'>perlopentut</link> と <link xref='perlfunc#open'>perlfunc/open</link> を
参照して下さい。
</para>
<para>
If a &lt;FILEHANDLE&gt; is used in a context that is looking for
a list, a list comprising all input lines is returned, one line per
list element.  It's easy to grow to a rather large data space this
way, so use with care.
</para>
<para>
&lt;FILEHANDLE&gt; がリストを必要とするコンテキストで用いられると、
1 要素に 1 行の入力行すべてからなるリストが返されます。
これを使うと簡単にかなり大きなデータになってしまいますので、
注意を要します。
</para>
<para>
&lt;FILEHANDLE&gt; may also be spelled <code>readline(*FILEHANDLE)</code>.
See <link xref='perlfunc#readline'>perlfunc/readline</link>.
</para>
<para>
&lt;FILEHANDLE&gt; は <code>readline(*FILEHANDLE)</code> とも書けます。
<link xref='perlfunc#readline'>perlfunc/readline</link> を参照して下さい。
</para>
<para>
The null filehandle &lt;&gt; is special: it can be used to emulate the
behavior of <strong>sed</strong> and <strong>awk</strong>.  Input from &lt;&gt; comes either from
standard input, or from each file listed on the command line.  Here's
how it works: the first time &lt;&gt; is evaluated, the @ARGV array is
checked, and if it is empty, <code>$ARGV[0]</code> is set to &quot;-&quot;, which when opened
gives you standard input.  The @ARGV array is then processed as a list
of filenames.  The loop
</para>
<para>
ヌルファイルハンドル &lt;&gt; は特別で、<strong>sed</strong> や <strong>awk</strong> の動作を
エミュレートするために使われます。
&lt;&gt; からの入力は、標準入力からか、コマンドライン上に並べられた個々の
ファイルから行なわれます。
動作の概要は、以下のようになります。
最初に &lt;&gt; が評価されると、配列 @ARGV が調べられ、空であれば、
<code>$ARGV[0]</code> に &quot;-&quot;を設定します。
これは、open されるとき標準入力となります。
その後、配列 @ARGV がファイル名のリストとして処理されます。
</para>
<verbatim><![CDATA[
while (<>) {
	...			# code for each line
}
]]></verbatim>
<para>
is equivalent to the following Perl-like pseudo code:
</para>
<para>
は以下ののような Perl の擬似コードと等価です:
</para>
<verbatim><![CDATA[
unshift(@ARGV, '-') unless @ARGV;
while ($ARGV = shift) {
	open(ARGV, $ARGV);
	while (<ARGV>) {
	    ...		# code for each line
	}
}
]]></verbatim>
<para>
except that it isn't so cumbersome to say, and will actually work.
It really does shift the @ARGV array and put the current filename
into the $ARGV variable.  It also uses filehandle <emphasis>ARGV</emphasis>
internally--&lt;&gt; is just a synonym for &lt;ARGV&gt;, which
is magical.  (The pseudo code above doesn't work because it treats
&lt;ARGV&gt; as non-magical.)
</para>
<para>
但し、わずらわしく書かなくても、動作します。
実際に @ARGV を shift しますし、その時点のファイル名を変数 $ARGV に
入れています。
また、内部的にファイルハンドル ARGV を使っていて、&lt;&gt; はマジカルな
&lt;ARGV&gt; の同義語となっています。
(上記の擬似コードは、&lt;ARGV&gt; を通常のものとして扱っているので、
うまく動作しません。)
</para>
<para>
You can modify @ARGV before the first &lt;&gt; as long as the array ends up
containing the list of filenames you really want.  Line numbers (<code>$.</code>)
continue as though the input were one big happy file.  See the example
in <link xref='perlfunc#eof'>perlfunc/eof</link> for how to reset line numbers on each file.
</para>
<para>
最終的に、@ARGV に扱いたいと思っているファイル名が含まれるのであれば、
最初に &lt;&gt; を評価する前に @ARGV を変更することも可能です。
行番号 (<code>$.</code>) は、入力ファイルがあたかも 1 つの大きなファイルで
あるかのように、続けてカウントされます。
個々のファイルごとにリセットする方法は、<link xref='perlfunc#eof'>perlfunc/eof</link> の例を
参照してください。
</para>
<para>
If you want to set @ARGV to your own list of files, go right ahead.  
This sets @ARGV to all plain text files if no @ARGV was given:
</para>
<para>
最初から @ARGV に自分でファイルのリストを設定してもかまいません。
以下は @ARGV が与えられなかったときに全てのテキストファイルを
@ARGV に設定します。
</para>
<verbatim><![CDATA[
@ARGV = grep { -f && -T } glob('*') unless @ARGV;
]]></verbatim>
<para>
You can even set them to pipe commands.  For example, this automatically
filters compressed arguments through <strong>gzip</strong>:
</para>
<para>
ここにパイプコマンドを置くことも出来ます。
例えば、以下は圧縮された引数を自動的に <strong>gzip</strong> のフィルタに通します:
</para>
<verbatim><![CDATA[
@ARGV = map { /\.(gz|Z)$/ ? "gzip -dc < $_ |" : $_ } @ARGV;
]]></verbatim>
<para>
If you want to pass switches into your script, you can use one of the
Getopts modules or put a loop on the front like this:
</para>
<para>
スクリプトにスイッチを渡したいのであれば、Getopts モジュールを
使うこともできますし、実際の処理の前にのようなループを置くこともできます。
</para>
<verbatim><![CDATA[
while ($_ = $ARGV[0], /^-/) {
	shift;
    last if /^--$/;
	if (/^-D(.*)/) { $debug = $1 }
	if (/^-v/)     { $verbose++  }
	# ...		# other switches
}
]]></verbatim>
<verbatim><![CDATA[
while (<>) {
	# ...		# code for each line
}
]]></verbatim>
<para>
The &lt;&gt; symbol will return <code>undef</code> for end-of-file only once.  
If you call it again after this, it will assume you are processing another 
@ARGV list, and if you haven't set @ARGV, will read input from STDIN.
</para>
<para>
シンボル &lt;&gt; がファイルの最後で <code>undef</code> を返すのは一度きりです。
そのあとでもう一度呼び出すと、新たに別の @ARGV を処理するものとみなされ、
その時に @ARGV を設定しなおしていないと、STDIN からの入力を
読み込むことになります。
</para>
<para>
If angle brackets contain is a simple scalar variable (e.g.,
&lt;$foo&gt;), then that variable contains the name of the
filehandle to input from, or its typeglob, or a reference to the
same.  For example:
</para>
<para>
山括弧の中の文字列が (&lt;$foo&gt; のような) 単純スカラ変数を囲っていれば、
その変数が入力を行なうファイルハンドルの名前そのもの、名前への型グロブ、
名前へのリファレンスのいずれかを示しているとみなされます。
</para>
<verbatim><![CDATA[
$fh = \*STDIN;
$line = <$fh>;
]]></verbatim>
<para>
If what's within the angle brackets is neither a filehandle nor a simple
scalar variable containing a filehandle name, typeglob, or typeglob
reference, it is interpreted as a filename pattern to be globbed, and
either a list of filenames or the next filename in the list is returned,
depending on context.  This distinction is determined on syntactic
grounds alone.  That means <code>&lt;$x&gt;</code> is always a readline() from
an indirect handle, but <code>&lt;$hash{key}&gt;</code> is always a glob().
That's because $x is a simple scalar variable, but <code>$hash{key}</code> is
not--it's a hash element.
</para>
<para>
山括弧の中の文字列がファイルハンドルでもファイルハンドル名、型グロブ、
型グロブリファレンスのいずれかが入った単純スカラ変数でもなければ、
グロブを行なうファイル名のパターンと解釈され、コンテキストによって
ファイル名のリストか、そのリストの次のファイル名が返されます。
この区別は単に構文的に行われます。
<code>&lt;$x&gt;</code> は常に間接ハンドルから readline() しますが、
<code>&lt;$hash{key}&gt;</code> は常に glob() します。
$x は単純スカラー変数ですが、<code>$hash{key}</code> は違う(ハッシュ要素)からです。
</para>
<para>
One level of double-quote interpretation is done first, but you can't
say <code>&lt;$foo&gt;</code> because that's an indirect filehandle as explained
in the previous paragraph.  (In older versions of Perl, programmers
would insert curly brackets to force interpretation as a filename glob:
<code>&lt;${foo}&gt;</code>.  These days, it's considered cleaner to call the
internal function directly as <code>glob($foo)</code>, which is probably the right
way to have done it in the first place.)  For example:
</para>
<para>
まず、1 段階だけダブルクォート展開が行なわれますが、前の段落に書いた
間接ファイルハンドルと同じになる、<code>&lt;$foo&gt;</code> のようには書けません。
(Perl の古いバージョンでは、ファイル名グロブと解釈させるために
<code>&lt;${foo}&gt;</code> のように中括弧を入れていました。
最近ではより明確にするために、<code>glob($foo)</code> と内部関数を
呼ぶこともできます。
おそらく、まず、こちらの方で試すのが正解でしょう。)　例:
</para>
<verbatim><![CDATA[
while (<*.c>) {
	chmod 0644, $_;
}
]]></verbatim>
<para>
is roughly equivalent to:
</para>
<para>
はだいたい以下と等価です:
</para>
<verbatim><![CDATA[
open(FOO, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|");
while (<FOO>) {
	chomp;
	chmod 0644, $_;
}
]]></verbatim>
<para>
except that the globbing is actually done internally using the standard
<code><xlink uri='File::Glob'>File::Glob</xlink></code> extension.  Of course, the shortest way to do the above is:
</para>
<para>
但し実際のグロブは内部的に標準の <code><xlink uri='File::Glob'>File::Glob</xlink></code> モジュールを使います。
もちろん、もっと簡単に以下のように書けます:
</para>
<verbatim><![CDATA[
chmod 0644, <*.c>;
]]></verbatim>
<para>
A (file)glob evaluates its (embedded) argument only when it is
starting a new list.  All values must be read before it will start
over.  In list context, this isn't important because you automatically
get them all anyway.  However, in scalar context the operator returns
the next value each time it's called, or <code>undef</code> when the list has
run out.  As with filehandle reads, an automatic <code>defined</code> is
generated when the glob occurs in the test part of a <code>while</code>,
because legal glob returns (e.g. a file called <filename>0</filename>) would otherwise
terminate the loop.  Again, <code>undef</code> is returned only once.  So if
you're expecting a single value from a glob, it is much better to
say
</para>
<para>
(ファイル)グロブは新しいリストを開始するときにだけ(組み込みの)引数を
評価します。
全ての値は開始する前に読み込んでいなければなりません。
これはリストコンテキストでは、とにかく自動的に全てを取り込むので
重要ではありません。
しかし、スカラーコンテキストではこの演算子は呼び出された時の
次の値か、リストがなくなったときには <code>undef</code> を返します。
ファイルハンドルを読み込む場合は、グロブが <code>while</code> の条件部にある場合は
自動的な <code>defined</code> が生成されます。
なぜならそうしないと、本来の glob の返り値 (<filename>0</filename> というファイル) が
ループを終了させるからです。
ここでも、<code>undef</code> は一度だけ返されます。
従って、もしグロブから一つの値だけを想定している場合、
以下のように書くことが:
</para>
<verbatim><![CDATA[
($file) = <blurch*>;
]]></verbatim>
<para>
than
</para>
<para>
以下のように書くよりはるかに良いです:
</para>
<verbatim><![CDATA[
$file = <blurch*>;
]]></verbatim>
<para>
because the latter will alternate between returning a filename and
returning false.
</para>
<para>
なぜなら後者はファイル名を返す場合と偽を返す場合があるからです。
</para>
<para>
It you're trying to do variable interpolation, it's definitely better
to use the glob() function, because the older notation can cause people
to become confused with the indirect filehandle notation.
</para>
<para>
変数変換に挑戦する場合、明らかに glob() 関数を使う方が良いです。
なぜなら古い表記は間接ファイルハンドル表記と混乱するかも知れないからです。
</para>
<verbatim><![CDATA[
@files = glob("$dir/*.[ch]");
@files = glob($files[$i]);
]]></verbatim>
</sect2>
<sect2>
<title>Constant Folding</title>
<para>
(定数の畳み込み)
</para>
<para>
Like C, Perl does a certain amount of expression evaluation at
compile time whenever it determines that all arguments to an
operator are static and have no side effects.  In particular, string
concatenation happens at compile time between literals that don't do
variable substitution.  Backslash interpolation also happens at
compile time.  You can say
</para>
<para>
C と同じように Perl でも、演算子に対するすべての引数がスタティックで、
副作用がないと判断できれば、コンパイル時に式の評価を行なってしまいます。
特に、変数置換の無いリテラルどうしの文字列連結はコンパイル時に行なわれます。
バックスラッシュの解釈もコンパイル時に行なわれます。
</para>
<verbatim><![CDATA[
'Now is the time for all' . "\n" .
	'good men to come to.'
]]></verbatim>
<para>
and this all reduces to one string internally.  Likewise, if
you say
</para>
<para>
と書いても、内部的に 1 つの文字列になります。同様に
</para>
<verbatim><![CDATA[
foreach $file (@filenames) {
	if (-s $file > 5 + 100 * 2**16) {  }
}
]]></verbatim>
<para>
the compiler will precompute the number which that expression
represents so that the interpreter won't have to.
</para>
<para>
と書くとコンパイラは、式が表わす数値をあらかじめ計算しますので、
インタプリタで計算する必要がなくなっています。
</para>
</sect2>
<sect2>
<title>Bitwise String Operators</title>
<para>
(ビット列演算子)
</para>
<para>
Bitstrings of any size may be manipulated by the bitwise operators
(<code>~ | &amp; ^</code>).
</para>
<para>
任意のサイズのビット列はビット単位演算子(<code>~ | &amp; ^</code>)で操作できます。
</para>
<para>
If the operands to a binary bitwise op are strings of different
sizes, <strong>|</strong> and <strong>^</strong> ops act as though the shorter operand had
additional zero bits on the right, while the <strong>&amp;</strong> op acts as though
the longer operand were truncated to the length of the shorter.
The granularity for such extension or truncation is one or more
bytes.
</para>
<para>
二項ビット単位演算子のオペランドが異なった長さの文字列だった場合、
<strong>|</strong> と <strong>^</strong> の演算子は短い側のオペランドの右側に追加のゼロが
ついているとみなします。
一方 <strong>&amp;</strong> 演算子は長い方のオペランドが短い方に切り詰められます。
この拡張や短縮の粒度はバイト単位です。
</para>
<verbatim><![CDATA[
# ASCII-based examples 
print "j p \n" ^ " a h";        	# prints "JAPH\n"
print "JA" | "  ph\n";          	# prints "japh\n"
print "japh\nJunk" & '_____';   	# prints "JAPH\n";
print 'p N$' ^ " E<H\n";		# prints "Perl\n";
]]></verbatim>
<para>
If you are intending to manipulate bitstrings, be certain that
you're supplying bitstrings: If an operand is a number, that will imply
a <strong>numeric</strong> bitwise operation.  You may explicitly show which type of
operation you intend by using <code>&quot;&quot;</code> or <code>0+</code>, as in the examples below.
</para>
<para>
ビット列を操作したい場合は、確実にビット列が渡されるようにしてください:
オペランドが数字の場合、<strong>数値</strong> ビット単位演算を仮定します。
明示的に演算の型を指定するときには、以下の例のように
<code>&quot;&quot;</code> か <code>0+</code> を使ってください。
</para>
<verbatim><![CDATA[
$foo =  150  |  105 ;	# yields 255  (0x96 | 0x69 is 0xFF)
$foo = '150' |  105 ;	# yields 255
$foo =  150  | '105';	# yields 255
$foo = '150' | '105';	# yields string '155' (under ASCII)
]]></verbatim>
<verbatim><![CDATA[
$baz = 0+$foo & 0+$bar;	# both ops explicitly numeric
$biz = "$foo" ^ "$bar";	# both ops explicitly stringy
]]></verbatim>
<para>
See <link xref='perlfunc#vec'>perlfunc/vec</link> for information on how to manipulate individual bits
in a bit vector.
</para>
<para>
ビットベクタの個々のビットをどのように操作するかの情報については
<link xref='perlfunc#vec'>perlfunc/vec</link> を参照して下さい。
</para>
</sect2>
<sect2>
<title>Integer Arithmetic</title>
<para>
(整数演算)
</para>
<para>
By default, Perl assumes that it must do most of its arithmetic in
floating point.  But by saying
</para>
<para>
デフォルトでは、Perl は演算を浮動小数で行なわなければならないものと
しています。
しかし、(もしそうしたいなら)
</para>
<verbatim><![CDATA[
use integer;
]]></verbatim>
<para>
you may tell the compiler that it's okay to use integer operations
(if it feels like it) from here to the end of the enclosing BLOCK.
An inner BLOCK may countermand this by saying
</para>
<para>
と書けば、その場所から現在の BLOCK の終わりまでは、整数演算を
行なってよいと、コンパイラに指示することができます。
内部の BLOCK で、
</para>
<verbatim><![CDATA[
no integer;
]]></verbatim>
<para>
which lasts until the end of that BLOCK.  Note that this doesn't
mean everything is only an integer, merely that Perl may use integer
operations if it is so inclined.  For example, even under <code>use
integer</code>, if you take the <code>sqrt(2)</code>, you'll still get <code>1.4142135623731</code>
or so.
</para>
<para>
と書けば、その BLOCK の終わりまでは、指示を取り消すことになります。
これは全てを整数だけを使って処理することを意味するわけではないことに
注意してください。
これは単に Perl が整数を使いたいと思ったときに使うかもしれない、
というだけです。
例えば、<code>use integer</code> の指定があっても、<code>sqrt(2)</code> とすると、
<code>1.4142135623731</code> といった結果が返ってきます。
</para>
<para>
Used on numbers, the bitwise operators (&quot;&amp;&quot;, &quot;|&quot;, &quot;^&quot;, &quot;~&quot;, &quot;&lt;&lt;&quot;,
and &quot;&gt;&gt;&quot;) always produce integral results.  (But see also 
<link xref='Bitwise String Operators'>Bitwise String Operators</link>.)  However, <code>use integer</code> still has meaning for
them.  By default, their results are interpreted as unsigned integers, but
if <code>use integer</code> is in effect, their results are interpreted
as signed integers.  For example, <code>~0</code> usually evaluates to a large
integral value.  However, <code>use integer; ~0</code> is <code>-1</code> on twos-complement
machines.
</para>
<para>
数値を使う場合、ビット単位演算子 (&quot;&amp;&quot;, &quot;|&quot;, &quot;^&quot;, &quot;~&quot;, &quot;&lt;&lt;&quot;, &quot;&gt;&gt;&quot;) は
常に整数の結果を生成します(但し <link xref='Bitwise String Operators'>Bitwise String Operators</link> も
参照して下さい)。
しかし、それでも <code>use integer</code> は意味があります。
デフォルトでは、これらの結果は符号なし整数として解釈されますが、
<code>use integer</code> が有効の場合は、符号付き整数として解釈されます。
例えば、<code>~0</code> は通常大きな整数の値として評価されます。
しかし、<code>use integer; ~0</code> は 2 の補数のマシンでは <code>-1</code> になります。
</para>
</sect2>
<sect2>
<title>Floating-point Arithmetic</title>
<para>
(浮動小数点演算)
</para>
<para>
While <code>use integer</code> provides integer-only arithmetic, there is no
analogous mechanism to provide automatic rounding or truncation to a
certain number of decimal places.  For rounding to a certain number
of digits, sprintf() or printf() is usually the easiest route.
See <link xref='perlfaq4'>perlfaq4</link>.
</para>
<para>
<code>use integer</code> が整数演算を提供する一方、数を特定の桁で自動的に丸めたり
切り捨てたりする機構はありません。
数を丸めるには、sprintf() や printf() を使うのが一番簡単な方法です。
<link xref='perlfaq4'>perlfaq4</link> を参照して下さい。
</para>
<para>
Floating-point numbers are only approximations to what a mathematician
would call real numbers.  There are infinitely more reals than floats,
so some corners must be cut.  For example:
</para>
<para>
浮動小数点数は数学者が実数と呼ぶものの近似でしかありません。
実数は浮動小数点より無限に続くので、多少角が丸められます。例:
</para>
<verbatim><![CDATA[
printf "%.20g\n", 123456789123456789;
#        produces 123456789123456784
]]></verbatim>
<para>
Testing for exact equality of floating-point equality or inequality is
not a good idea.  Here's a (relatively expensive) work-around to compare
whether two floating-point numbers are equal to a particular number of
decimal places.  See Knuth, volume II, for a more robust treatment of
this topic.
</para>
<para>
浮動小数点数が等しいかどうかをちょうど同じかどうかで比較するのは
いいアイデアではありません。
以下に、二つの浮動小数点数が指定された桁まで等しいかどうかを
比較する(比較的重い)次善の策を示します。
この問題に関するより厳密な扱いについては Knuth, volume II を参照して下さい。
</para>
<verbatim><![CDATA[
sub fp_equal {
	my ($X, $Y, $POINTS) = @_;
	my ($tX, $tY);
	$tX = sprintf("%.${POINTS}g", $X);
	$tY = sprintf("%.${POINTS}g", $Y);
	return $tX eq $tY;
}
]]></verbatim>
<para>
The POSIX module (part of the standard perl distribution) implements
ceil(), floor(), and other mathematical and trigonometric functions.
The Math::Complex module (part of the standard perl distribution)
defines mathematical functions that work on both the reals and the
imaginary numbers.  Math::Complex not as efficient as POSIX, but
POSIX can't work with complex numbers.
</para>
<para>
POSIX モジュール(Perl 標準配布パッケージの一部) は ceil(), floor() 及び
その他の数学関数や三角関数を実装しています。
Math::Complex モジュール(Perl 標準配布パッケージの一部)は
実数と虚数の両方で動作する数学関数を定義しています。
Math::Complex は POSIX ほど効率的ではありませんが、
POSIX は複素数は扱えません。
</para>
<para>
Rounding in financial applications can have serious implications, and
the rounding method used should be specified precisely.  In these
cases, it probably pays not to trust whichever system rounding is
being used by Perl, but to instead implement the rounding function you
need yourself.
</para>
<para>
金融アプリケーションにおける丸めは深刻な影響を与える可能性があり、
使用する丸めメソッドは指定された精度で行われるべきです。
このような場合、Perl が使用するシステム丸めを信用せず、
代わりに自分自身で丸め関数を実装するべきです。
</para>
</sect2>
<sect2>
<title>Bigger Numbers</title>
<para>
(より大きな数)
</para>
<para>
The standard Math::BigInt and Math::BigFloat modules provide
variable-precision arithmetic and overloaded operators, although
they're currently pretty slow. At the cost of some space and
considerable speed, they avoid the normal pitfalls associated with
limited-precision representations.
</para>
<para>
標準の Math::BigInt と Math::BigFloat モジュールは多倍長演算を提供し、
演算子をオーバーロードしますが、これらは現在のところかなり遅いです。
多少の領域とかなりの速度を犠牲にして、桁数が制限されていることによる
ありがちな落とし穴を避けることができます。
</para>
<verbatim><![CDATA[
use Math::BigInt;
$x = Math::BigInt->new('123456789123456789');
print $x * $x;
]]></verbatim>
<verbatim><![CDATA[
# prints +15241578780673678515622620750190521
]]></verbatim>
<para>
There are several modules that let you calculate with (bound only by
memory and cpu-time) unlimited or fixed precision. There are also
some non-standard modules that provide faster implementations via
external C libraries.
</para>
<para>
(メモリと CPU 時間のみに依存する)無制限か固定の精度での計算ができる
モジュールがいくつかあります。
さらに外部 C ライブラリを使ってより速い実装を提供する
非標準のモジュールもあります。
</para>
<para>
Here is a short, but incomplete summary:
</para>
<verbatim><![CDATA[
Math::Fraction		big, unlimited fractions like 9973 / 12967
Math::String		treat string sequences like numbers
Math::FixedPrecision	calculate with a fixed precision
Math::Currency		for currency calculations
Bit::Vector		manipulate bit vectors fast (uses C)
Math::BigIntFast	Bit::Vector wrapper for big numbers
Math::Pari		provides access to the Pari C library
Math::BigInteger	uses an external C library
Math::Cephes		uses external Cephes C library (no big numbers)
Math::Cephes::Fraction	fractions via the Cephes library
Math::GMP		another one using an external C library
]]></verbatim>
<para>
Choose wisely.
</para>
<para>
以下は短いですが不完全なリストです。
</para>
<verbatim><![CDATA[
Math::Fraction		9973 / 12967 のような、大きくて無制限の分数
Math::String		文字列を数値のように扱う
Math::FixedPrecision	固定精度で計算する
Math::Currency		通貨の計算用
Bit::Vector		(C を使って)ビットベクタを速く操作する
Math::BigIntFast	大きな数のための Bit::Vector のラッパー
Math::Pari		Pari C ライブラリへのアクセスを提供する
Math::BigInteger	外部 C ライブラリを使う
Math::Cephes		外部の Cephes C を使う(大きな数はなし)
Math::Cephes::Fraction	Cephes ライブラリを使った分数
Math::GMP		これも外部 C ライブラリを使う
]]></verbatim>
<para>
うまく選んでください。
</para>
<para>
Translate: 吉村 寿人 &lt;JAE00534@niftyserve.or.jp&gt; (5.000)
Update: Kentaro Shirakata &lt;argrath@ub32.org&gt; (5.6.1-)
License: GPL or Artistic
</para>
</sect2>
</sect1>
</pod>
