-4

What Perl variables are used for the positions of the start and end of last successful regex match?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
unixman83
  • 9,421
  • 10
  • 68
  • 102
  • 7
    Let me look that up in the manual for you... – alexis Mar 29 '12 at 21:35
  • 3
    http://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 Answers1

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 the pos function returns when called on the variable that was matched against.

$-[0] is the offset of the start of the last successful match.

Community
  • 1
  • 1
ruakh
  • 175,680
  • 26
  • 273
  • 307