What Perl variables are used for the positions of the start and end of last successful regex match?
Asked
Active
Viewed 87 times
-4
-
7Let me look that up in the manual for you... – alexis Mar 29 '12 at 21:35
-
3http://perldoc.perl.org/perlvar.html – TLP Mar 29 '12 at 21:39
-
This is the first couple of pages of _Mastering Perl_ :) – brian d foy Mar 29 '12 at 22:36
-
It's not like I don't know what's in the manual. Why do you think I tagged it perlvar? And even knew about its existence. I had just forgotten. I am a C programmer, not Perl. Geez guys this site really is lame. Unless I am talking about some arcane thing people downvote... – unixman83 Mar 30 '12 at 04:25
-
If you can't run 'man' on Unix when you forget things, then you should probably choose a nick other than 'unixman'. – runrig Mar 30 '12 at 18:15
1 Answers
1
As the perlvar
man-page explains:
$+[0]
is the offset into the string of the end of the entire [last successful] match. This is the same value as what thepos
function returns when called on the variable that was matched against.
$-[0]
is the offset of the start of the last successful match.