- pos SCALAR
 - pos
 - 
Returns the offset of where the last
m//gsearch left off for the variable in question ($_is used when the variable is not specified). This offset is in characters unless the (no-longer-recommended)use bytespragma is in effect, in which case the offset is in bytes. Note that 0 is a valid match offset. undef indicates that the search position is reset (usually due to match failure, but can also be because no match has yet been run on the scalar).対象の変数に対して、前回の
m//gが終了した場所の オフセットを返します(変数が指定されなかった場合は$_が 使われます)。 オフセットは、(もはや勧められない)use bytesプラグマが有効の 場合(この場合はバイト単位です)を除いて、文字単位です。 0 は有効なマッチオフセットであることに注意してください。 undef は検索位置がリセットされることを意味します (通常は マッチ失敗が原因ですが、このスカラ値にまだマッチングが 行われていないためかもしれません)。posdirectly accesses the location used by the regexp engine to store the offset, so assigning toposwill change that offset, and so will also influence the\Gzero-width assertion in regular expressions. Both of these effects take place for the next match, so you can't affect the position withposduring the current match, such as in(?{pos() = 5})ors//pos() = 5/e.posは正規表現エンジンがオフセットを保存するために使う場所を 直接アクセスするので、posへの代入はオフセットを変更し、 そのような変更は正規表現における\Gゼロ幅アサートにも影響を与えます。 これらの効果の両方は次のマッチングのために行われるので、(?{pos() = 5})やs//pos() = 5/eのように現在のマッチング中のposの位置には影響を与えません。Setting
posalso resets the matched with zero-length flag, described under "Repeated Patterns Matching a Zero-length Substring" in perlre.posを設定すると、 "Repeated Patterns Matching a Zero-length Substring" in perlre に 記述されている、長さ 0 でマッチング フラグもリセットされます。Because a failed
m//gcmatch doesn't reset the offset, the return fromposwon't change either in this case. See perlre and perlop.m//gcマッチに失敗してもオフセットはリセットしないので、posからの返り値はどちらの場合も変更されません。 perlre と perlop を参照してください。