Some Perl Special Variables Some Regular Expression Special Variables 25 of 28 : [PREV] [NEXT]

@- (@LAST_MATCH_START)

  • Holds the offsets to the starts of the last successful submatches.

@+ (@LAST_MATCH_END)

  • Holds the offsets of the ends of the last successful submatches.
  $_ = "AlphaBetaGamma";
  /Beta/;

  print "Offset to start of Match     = $-[0]\n";    # 5 (B of Beta)
  print "Offset to start of Postmatch = $+[0]\n";    # 9 (G of Gamma)
  • $-[0] & $+[0] refer to the last match.
  • $-[1] & $+[1] refer to the $1 offsets.
  • $-[2] & $+[2] refer to the $2 offsets ... etc.

© 2004 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/