pos
pos $scalar
- Returns the location in scalar where the last
m//g
search over scalar left off. It returns the offset of the character after the last one matched. This is the offset where the nextm//g
search on that string will start. Remember that the offset of the beginning of the string is0
. For example:
$grafitto = "fee fie foe foo"; while ($grafitto =~ m/e/g) { print pos $grafitto, "\n"; }
prints2
,3
,7
, and11
, the offsets of each of the characters following an e". Thepos
function may be assigned a value to tell the nextm//g
where to start.