Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

pos

Gets or sets the position of the last m//g match on a string.

As an rvalue, returns the character offset where the most recent global (/g) match left off, or undef if no match has been performed on that string. As an lvalue, sets the starting position for the next m//g match.

Without an argument, operates on $_. Positions are stored in a side table (pos_table) keyed by string content.

Synopsis

$str =~ /pattern/g;
my $p = pos($str);       # position after last /g match
pos($str) = 0;           # reset match position
my $p = pos;             # defaults to $_

See Also

m//g, reset